Lines 69-81
Link Here
|
69 |
int window; |
69 |
int window; |
70 |
int adrtype; |
70 |
int adrtype; |
71 |
int policy; |
71 |
int policy; |
72 |
int e, n; |
72 |
int n; |
73 |
|
73 |
|
74 |
ng_hci_le_set_scan_parameters_cp cp; |
74 |
ng_hci_le_set_scan_parameters_cp cp; |
75 |
ng_hci_le_set_scan_parameters_rp rp; |
75 |
ng_hci_le_set_scan_parameters_rp rp; |
76 |
|
76 |
|
77 |
if (argc != 5) |
77 |
if (argc != 5) |
78 |
return USAGE; |
78 |
return (USAGE); |
79 |
|
79 |
|
80 |
if (strcmp(argv[0], "active") == 0) |
80 |
if (strcmp(argv[0], "active") == 0) |
81 |
type = 1; |
81 |
type = 1; |
Lines 82-88
Link Here
|
82 |
else if (strcmp(argv[0], "passive") == 0) |
82 |
else if (strcmp(argv[0], "passive") == 0) |
83 |
type = 0; |
83 |
type = 0; |
84 |
else |
84 |
else |
85 |
return USAGE; |
85 |
return (USAGE); |
86 |
|
86 |
|
87 |
interval = (int)(atof(argv[1])/0.625); |
87 |
interval = (int)(atof(argv[1])/0.625); |
88 |
interval = (interval < 4)? 4: interval; |
88 |
interval = (interval < 4)? 4: interval; |
Lines 94-100
Link Here
|
94 |
else if (strcmp(argv[3], "random") == 0) |
94 |
else if (strcmp(argv[3], "random") == 0) |
95 |
adrtype = 1; |
95 |
adrtype = 1; |
96 |
else |
96 |
else |
97 |
return USAGE; |
97 |
return (USAGE); |
98 |
|
98 |
|
99 |
if (strcmp(argv[4], "all") == 0) |
99 |
if (strcmp(argv[4], "all") == 0) |
100 |
policy = 0; |
100 |
policy = 0; |
Lines 101-107
Link Here
|
101 |
else if (strcmp(argv[4], "whitelist") == 0) |
101 |
else if (strcmp(argv[4], "whitelist") == 0) |
102 |
policy = 1; |
102 |
policy = 1; |
103 |
else |
103 |
else |
104 |
return USAGE; |
104 |
return (USAGE); |
105 |
|
105 |
|
106 |
cp.le_scan_type = type; |
106 |
cp.le_scan_type = type; |
107 |
cp.le_scan_interval = interval; |
107 |
cp.le_scan_interval = interval; |
Lines 109-119
Link Here
|
109 |
cp.le_scan_window = window; |
109 |
cp.le_scan_window = window; |
110 |
cp.scanning_filter_policy = policy; |
110 |
cp.scanning_filter_policy = policy; |
111 |
n = sizeof(rp); |
111 |
n = sizeof(rp); |
112 |
e = hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
112 |
|
|
|
113 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
113 |
NG_HCI_OCF_LE_SET_SCAN_PARAMETERS), |
114 |
NG_HCI_OCF_LE_SET_SCAN_PARAMETERS), |
114 |
(void *)&cp, sizeof(cp), (void *)&rp, &n); |
115 |
(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR) |
|
|
116 |
return (ERROR); |
115 |
|
117 |
|
116 |
return 0; |
118 |
if (rp.status != 0x00) { |
|
|
119 |
fprintf(stdout, "Status: %s [%#02x]\n", |
120 |
hci_status2str(rp.status), rp.status); |
121 |
return (FAILED); |
122 |
} |
123 |
|
124 |
return (OK); |
117 |
} |
125 |
} |
118 |
|
126 |
|
119 |
static int |
127 |
static int |
Lines 121-147
Link Here
|
121 |
{ |
129 |
{ |
122 |
ng_hci_le_set_scan_enable_cp cp; |
130 |
ng_hci_le_set_scan_enable_cp cp; |
123 |
ng_hci_le_set_scan_enable_rp rp; |
131 |
ng_hci_le_set_scan_enable_rp rp; |
124 |
int e, n, enable = 0; |
132 |
int n, enable = 0; |
125 |
|
133 |
|
126 |
if (argc != 1) |
134 |
if (argc != 1) |
127 |
return USAGE; |
135 |
return (USAGE); |
128 |
|
136 |
|
129 |
if (strcmp(argv[0], "enable") == 0) |
137 |
if (strcmp(argv[0], "enable") == 0) |
130 |
enable = 1; |
138 |
enable = 1; |
131 |
else if (strcmp(argv[0], "disable") != 0) |
139 |
else if (strcmp(argv[0], "disable") != 0) |
132 |
return USAGE; |
140 |
return (USAGE); |
133 |
|
141 |
|
134 |
n = sizeof(rp); |
142 |
n = sizeof(rp); |
135 |
cp.le_scan_enable = enable; |
143 |
cp.le_scan_enable = enable; |
136 |
cp.filter_duplicates = 0; |
144 |
cp.filter_duplicates = 0; |
137 |
e = hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
145 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
138 |
NG_HCI_OCF_LE_SET_SCAN_ENABLE), |
146 |
NG_HCI_OCF_LE_SET_SCAN_ENABLE), |
139 |
(void *)&cp, sizeof(cp), (void *)&rp, &n); |
147 |
(void *)&cp, sizeof(cp), |
|
|
148 |
(void *)&rp, &n) == ERROR) |
149 |
return (ERROR); |
140 |
|
150 |
|
141 |
if (e != 0 || rp.status != 0) |
151 |
if (rp.status != 0x00) { |
142 |
return ERROR; |
152 |
fprintf(stdout, "Status: %s [%#02x]\n", |
|
|
153 |
hci_status2str(rp.status), rp.status); |
154 |
return (FAILED); |
155 |
} |
143 |
|
156 |
|
144 |
return OK; |
157 |
fprintf(stdout, "LE Scan: %s\n", |
|
|
158 |
enable? "Enabled" : "Disabled"); |
159 |
|
160 |
return (OK); |
145 |
} |
161 |
} |
146 |
|
162 |
|
147 |
static int |
163 |
static int |
Lines 197-203
Link Here
|
197 |
done: |
213 |
done: |
198 |
*len = curbuf - buf; |
214 |
*len = curbuf - buf; |
199 |
|
215 |
|
200 |
return OK; |
216 |
return (OK); |
201 |
} |
217 |
} |
202 |
|
218 |
|
203 |
static int |
219 |
static int |
Lines 206-212
Link Here
|
206 |
ng_hci_le_set_scan_response_data_cp cp; |
222 |
ng_hci_le_set_scan_response_data_cp cp; |
207 |
ng_hci_le_set_scan_response_data_rp rp; |
223 |
ng_hci_le_set_scan_response_data_rp rp; |
208 |
int n; |
224 |
int n; |
209 |
int e; |
|
|
210 |
int len; |
225 |
int len; |
211 |
char buf[NG_HCI_ADVERTISING_DATA_SIZE]; |
226 |
char buf[NG_HCI_ADVERTISING_DATA_SIZE]; |
212 |
|
227 |
|
Lines 216-228
Link Here
|
216 |
cp.scan_response_data_length = len; |
231 |
cp.scan_response_data_length = len; |
217 |
memcpy(cp.scan_response_data, buf, len); |
232 |
memcpy(cp.scan_response_data, buf, len); |
218 |
n = sizeof(rp); |
233 |
n = sizeof(rp); |
219 |
e = hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
234 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
220 |
NG_HCI_OCF_LE_SET_SCAN_RESPONSE_DATA), |
235 |
NG_HCI_OCF_LE_SET_SCAN_RESPONSE_DATA), |
221 |
(void *)&cp, sizeof(cp), (void *)&rp, &n); |
236 |
(void *)&cp, sizeof(cp), |
|
|
237 |
(void *)&rp, &n) == ERROR) |
238 |
return (ERROR); |
222 |
|
239 |
|
223 |
printf("SET SCAN RESPONSE %d %d %d\n", e, rp.status, n); |
240 |
if (rp.status != 0x00) { |
|
|
241 |
fprintf(stdout, "Status: %s [%#02x]\n", |
242 |
hci_status2str(rp.status), rp.status); |
243 |
return (FAILED); |
244 |
} |
224 |
|
245 |
|
225 |
return OK; |
246 |
return (OK); |
226 |
} |
247 |
} |
227 |
|
248 |
|
228 |
static int |
249 |
static int |
Lines 259-265
Link Here
|
259 |
buffer, sizeof(buffer))); |
280 |
buffer, sizeof(buffer))); |
260 |
fprintf(stdout, "\n"); |
281 |
fprintf(stdout, "\n"); |
261 |
|
282 |
|
262 |
return OK; |
283 |
return (OK); |
263 |
} |
284 |
} |
264 |
|
285 |
|
265 |
static int |
286 |
static int |
Lines 290-296
Link Here
|
290 |
{ |
311 |
{ |
291 |
ng_hci_le_set_event_mask_cp semc; |
312 |
ng_hci_le_set_event_mask_cp semc; |
292 |
ng_hci_le_set_event_mask_rp rp; |
313 |
ng_hci_le_set_event_mask_rp rp; |
293 |
int i, n ,e; |
314 |
int i, n; |
294 |
|
315 |
|
295 |
n = sizeof(rp); |
316 |
n = sizeof(rp); |
296 |
|
317 |
|
Lines 298-308
Link Here
|
298 |
semc.event_mask[i] = mask&0xff; |
319 |
semc.event_mask[i] = mask&0xff; |
299 |
mask >>= 8; |
320 |
mask >>= 8; |
300 |
} |
321 |
} |
301 |
e = hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
322 |
if(hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
302 |
NG_HCI_OCF_LE_SET_EVENT_MASK), |
323 |
NG_HCI_OCF_LE_SET_EVENT_MASK), |
303 |
(void *)&semc, sizeof(semc), (void *)&rp, &n); |
324 |
(void *)&semc, sizeof(semc), (void *)&rp, &n) == ERROR) |
|
|
325 |
return (ERROR); |
326 |
|
327 |
if (rp.status != 0x00) { |
328 |
fprintf(stdout, "Status: %s [%#02x]\n", |
329 |
hci_status2str(rp.status), rp.status); |
330 |
return (FAILED); |
331 |
} |
304 |
|
332 |
|
305 |
return 0; |
333 |
return (OK); |
306 |
} |
334 |
} |
307 |
|
335 |
|
308 |
static int |
336 |
static int |
Lines 310-316
Link Here
|
310 |
{ |
338 |
{ |
311 |
ng_hci_set_event_mask_cp semc; |
339 |
ng_hci_set_event_mask_cp semc; |
312 |
ng_hci_set_event_mask_rp rp; |
340 |
ng_hci_set_event_mask_rp rp; |
313 |
int i, n, e; |
341 |
int i, n; |
314 |
|
342 |
|
315 |
n = sizeof(rp); |
343 |
n = sizeof(rp); |
316 |
|
344 |
|
Lines 318-346
Link Here
|
318 |
semc.event_mask[i] = mask&0xff; |
346 |
semc.event_mask[i] = mask&0xff; |
319 |
mask >>= 8; |
347 |
mask >>= 8; |
320 |
} |
348 |
} |
321 |
e = hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, |
349 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, |
322 |
NG_HCI_OCF_SET_EVENT_MASK), |
350 |
NG_HCI_OCF_SET_EVENT_MASK), |
323 |
(void *)&semc, sizeof(semc), (void *)&rp, &n); |
351 |
(void *)&semc, sizeof(semc), (void *)&rp, &n) == ERROR) |
|
|
352 |
return (ERROR); |
353 |
|
354 |
if (rp.status != 0x00) { |
355 |
fprintf(stdout, "Status: %s [%#02x]\n", |
356 |
hci_status2str(rp.status), rp.status); |
357 |
return (FAILED); |
358 |
} |
324 |
|
359 |
|
325 |
return 0; |
360 |
return (OK); |
326 |
} |
361 |
} |
327 |
|
362 |
|
328 |
static |
363 |
static |
329 |
int le_enable(int s, int argc, char *argv[]) |
364 |
int le_enable(int s, int argc, char *argv[]) |
330 |
{ |
365 |
{ |
|
|
366 |
int result; |
367 |
|
331 |
if (argc != 1) |
368 |
if (argc != 1) |
332 |
return USAGE; |
369 |
return (USAGE); |
333 |
|
370 |
|
334 |
if (strcasecmp(argv[0], "enable") == 0) { |
371 |
if (strcasecmp(argv[0], "enable") == 0) { |
335 |
set_event_mask(s, NG_HCI_EVENT_MASK_DEFAULT | |
372 |
result = set_event_mask(s, NG_HCI_EVENT_MASK_DEFAULT | |
336 |
NG_HCI_EVENT_MASK_LE); |
373 |
NG_HCI_EVENT_MASK_LE); |
337 |
set_le_event_mask(s, NG_HCI_LE_EVENT_MASK_ALL); |
374 |
if (result != OK) |
338 |
} else if (strcasecmp(argv[0], "disable") == 0) |
375 |
return result; |
339 |
set_event_mask(s, NG_HCI_EVENT_MASK_DEFAULT); |
376 |
result = set_le_event_mask(s, NG_HCI_LE_EVENT_MASK_ALL); |
340 |
else |
377 |
if (result == OK) { |
341 |
return USAGE; |
378 |
fprintf(stdout, "LE enabled\n"); |
342 |
|
379 |
return (OK); |
343 |
return OK; |
380 |
} else |
|
|
381 |
return result; |
382 |
} else if (strcasecmp(argv[0], "disable") == 0) { |
383 |
result = set_event_mask(s, NG_HCI_EVENT_MASK_DEFAULT); |
384 |
if (result == OK) { |
385 |
fprintf(stdout, "LE disabled\n"); |
386 |
return (OK); |
387 |
} else |
388 |
return result; |
389 |
} else |
390 |
return (USAGE); |
344 |
} |
391 |
} |
345 |
|
392 |
|
346 |
static int |
393 |
static int |