Lines 1-100
Link Here
|
1 |
--- ./src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp.orig 2013-05-13 15:09:14.000000000 +0200 |
|
|
2 |
+++ ./src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp 2013-06-12 16:31:03.000000000 +0200 |
3 |
@@ -61,6 +61,8 @@ |
4 |
#include <libudev.h> |
5 |
} |
6 |
#elif defined(__FreeBSD__) |
7 |
+#include <sys/param.h> |
8 |
+#include <sys/sysctl.h> |
9 |
#include <stdio.h> |
10 |
#include <unistd.h> |
11 |
#endif |
12 |
@@ -434,22 +436,77 @@ |
13 |
} |
14 |
#elif defined(__FreeBSD__) |
15 |
char devicePath[PATH_MAX + 1]; |
16 |
+ char infos[512]; |
17 |
+ char sysctlname[32]; |
18 |
+ char ttyname[8]; |
19 |
+ char *pos; |
20 |
+ size_t infos_size = sizeof(infos); |
21 |
int i; |
22 |
|
23 |
- for (i = 0; i < 8; ++i) |
24 |
+ for (i = 0; ; ++i) |
25 |
{ |
26 |
- (void)snprintf(devicePath, sizeof(devicePath), "/dev/ttyU%d", i); |
27 |
- if (strDevicePath && strcmp(devicePath, strDevicePath) != 0) |
28 |
+ unsigned int iVendor, iProduct; |
29 |
+ memset(infos, 0, sizeof(infos)); |
30 |
+ (void)snprintf(sysctlname, sizeof(sysctlname), |
31 |
+ "dev.umodem.%d.%%pnpinfo", i); |
32 |
+ if (sysctlbyname(sysctlname, infos, &infos_size, |
33 |
+ NULL, 0) != 0) |
34 |
+ break; |
35 |
+ pos = strstr(infos, "vendor="); |
36 |
+ if (pos == NULL) |
37 |
continue; |
38 |
- if (!access(devicePath, 0)) |
39 |
- { |
40 |
- snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicePath); |
41 |
- snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", devicePath); |
42 |
- deviceList[iFound].iVendorId = CEC_VID; |
43 |
- deviceList[iFound].iProductId = CEC_VID; |
44 |
- deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type |
45 |
- iFound++; |
46 |
+ sscanf(pos, "vendor=%x ", &iVendor); |
47 |
+ |
48 |
+ pos = strstr(infos, "product="); |
49 |
+ if (pos == NULL) |
50 |
+ continue; |
51 |
+ sscanf(pos, "product=%x ", &iProduct); |
52 |
+ |
53 |
+ if (iVendor != CEC_VID || (iProduct != CEC_PID && iProduct != CEC_PID2)) |
54 |
+ continue; |
55 |
+ |
56 |
+ pos = strstr(infos, "ttyname="); |
57 |
+ if (pos == NULL) |
58 |
+ continue; |
59 |
+ sscanf(pos, "ttyname=%s ", ttyname); |
60 |
+ |
61 |
+ (void)snprintf(devicePath, sizeof(devicePath), |
62 |
+ "/dev/tty%s", ttyname); |
63 |
+ |
64 |
+ if (strDevicePath) { |
65 |
+ char currStrDevicePath[512]; |
66 |
+ int port = 0; |
67 |
+ int devaddr = 0; |
68 |
+ memset(currStrDevicePath, 0, sizeof(currStrDevicePath)); |
69 |
+ memset(infos, 0, sizeof(infos)); |
70 |
+ (void)snprintf(sysctlname, sizeof(sysctlname), |
71 |
+ "dev.umodem.%d.%%location", i); |
72 |
+ if (sysctlbyname(sysctlname, infos, &infos_size, |
73 |
+ NULL, 0) != 0) |
74 |
+ break; |
75 |
+ |
76 |
+ pos = strstr(infos, "port="); |
77 |
+ if (pos == NULL) |
78 |
+ continue; |
79 |
+ sscanf(pos, "port=%d ", &port); |
80 |
+ |
81 |
+ pos = strstr(infos, "devaddr="); |
82 |
+ if (pos == NULL) |
83 |
+ continue; |
84 |
+ sscanf(pos, "devaddr=%d ", &devaddr); |
85 |
+ |
86 |
+ (void)snprintf(currStrDevicePath, sizeof(currStrDevicePath), |
87 |
+ "/dev/ugen%d.%d", port, devaddr); |
88 |
+ |
89 |
+ if (strcmp(currStrDevicePath, strDevicePath) != 0) |
90 |
+ continue; |
91 |
} |
92 |
+ snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicePath); |
93 |
+ snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", devicePath); |
94 |
+ deviceList[iFound].iVendorId = iVendor; |
95 |
+ deviceList[iFound].iProductId = iProduct; |
96 |
+ deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type |
97 |
+ iFound++; |
98 |
} |
99 |
#else |
100 |
//silence "unused" warnings |