File: On-linux-check-whether-a-kernel-driver-is-attached

package info (click to toggle)
airspyone-host 1.0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,336 kB
  • sloc: ansic: 6,357; xml: 20; sh: 14; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From 7e9a0a62981caf34077cbb35fb435d8b4306538f Mon Sep 17 00:00:00 2001
From: bvernoux <bvernoux@gmail.com>
Date: Tue, 26 May 2015 22:08:19 +0200
Subject: [PATCH 01/10] On linux check whether a kernel driver is attached to
 airspy device opened and if so, we detach it.

---
 libairspy/src/airspy.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

--- a/libairspy/src/airspy.c
+++ b/libairspy/src/airspy.c
@@ -671,6 +671,15 @@
 								*libusb_dev_handle = NULL;
 								continue;
 							}
+#ifdef __linux__
+							/* Check whether a kernel driver is attached to interface #0. If so, we'll 
+							 * need to detach it.
+							 */
+							if (libusb_kernel_driver_active(dev_handle, 0))
+							{
+								libusb_detach_kernel_driver(dev_handle, 0);
+							}
+#endif
 							result = libusb_claim_interface(dev_handle, 0);
 							if (result != 0)
 							{
@@ -716,6 +725,15 @@
 						*libusb_dev_handle = NULL;
 						continue;
 					}
+#ifdef __linux__
+					/* Check whether a kernel driver is attached to interface #0. If so, we'll 
+					 * need to detach it.
+					 */
+					if (libusb_kernel_driver_active(dev_handle, 0))
+					{
+						libusb_detach_kernel_driver(dev_handle, 0);
+					}
+#endif
 					result = libusb_claim_interface(dev_handle, 0);
 					if (result != 0)
 					{