link_control.c (122451) | link_control.c (128079) |
---|---|
1/* 2 * link_control.c 3 * 4 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: link_control.c,v 1.4 2003/08/18 19:19:54 max Exp $ | 1/* 2 * link_control.c 3 * 4 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: link_control.c,v 1.4 2003/08/18 19:19:54 max Exp $ |
29 * $FreeBSD: head/usr.sbin/bluetooth/hccontrol/link_control.c 122451 2003-11-11 02:43:10Z emax $ | 29 * $FreeBSD: head/usr.sbin/bluetooth/hccontrol/link_control.c 128079 2004-04-09 23:58:53Z emax $ |
30 */ 31 32#include <bluetooth.h> 33#include <errno.h> 34#include <stdio.h> 35#include <string.h> 36#include "hccontrol.h" 37 | 30 */ 31 32#include <bluetooth.h> 33#include <errno.h> 34#include <stdio.h> 35#include <string.h> 36#include "hccontrol.h" 37 |
38static void hci_inquiry_response (int n, u_int8_t **b); | 38static void hci_inquiry_response (int n, uint8_t **b); |
39 40/* Send Inquiry command to the unit */ 41static int 42hci_inquiry(int s, int argc, char **argv) 43{ 44 int n0, n1, n2, timo; | 39 40/* Send Inquiry command to the unit */ 41static int 42hci_inquiry(int s, int argc, char **argv) 43{ 44 int n0, n1, n2, timo; |
45 u_int8_t b[512]; | 45 uint8_t b[512]; |
46 ng_hci_inquiry_cp cp; 47 ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; 48 49 /* set defaults */ 50 cp.lap[2] = 0x9e; 51 cp.lap[1] = 0x8b; 52 cp.lap[0] = 0x33; 53 cp.inquiry_length = 5; --- 58 unchanged lines hidden (view full) --- 112 errno = EIO; 113 return (ERROR); 114 } 115 116 switch (e->event) { 117 case NG_HCI_EVENT_INQUIRY_RESULT: { 118 ng_hci_inquiry_result_ep *ir = 119 (ng_hci_inquiry_result_ep *)(e + 1); | 46 ng_hci_inquiry_cp cp; 47 ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; 48 49 /* set defaults */ 50 cp.lap[2] = 0x9e; 51 cp.lap[1] = 0x8b; 52 cp.lap[0] = 0x33; 53 cp.inquiry_length = 5; --- 58 unchanged lines hidden (view full) --- 112 errno = EIO; 113 return (ERROR); 114 } 115 116 switch (e->event) { 117 case NG_HCI_EVENT_INQUIRY_RESULT: { 118 ng_hci_inquiry_result_ep *ir = 119 (ng_hci_inquiry_result_ep *)(e + 1); |
120 u_int8_t *r = (u_int8_t *)(ir + 1); | 120 uint8_t *r = (uint8_t *)(ir + 1); |
121 122 fprintf(stdout, "Inquiry result, num_responses=%d\n", 123 ir->num_responses); 124 125 for (n0 = 0; n0 < ir->num_responses; n0++) 126 hci_inquiry_response(n0, &r); 127 128 goto wait_for_more; --- 10 unchanged lines hidden (view full) --- 139 140 timeout = timo; 141 142 return (OK); 143} /* hci_inquiry */ 144 145/* Print Inquiry_Result event */ 146static void | 121 122 fprintf(stdout, "Inquiry result, num_responses=%d\n", 123 ir->num_responses); 124 125 for (n0 = 0; n0 < ir->num_responses; n0++) 126 hci_inquiry_response(n0, &r); 127 128 goto wait_for_more; --- 10 unchanged lines hidden (view full) --- 139 140 timeout = timo; 141 142 return (OK); 143} /* hci_inquiry */ 144 145/* Print Inquiry_Result event */ 146static void |
147hci_inquiry_response(int n, u_int8_t **b) | 147hci_inquiry_response(int n, uint8_t **b) |
148{ 149 struct inquiry_response { 150 bdaddr_t bdaddr; | 148{ 149 struct inquiry_response { 150 bdaddr_t bdaddr; |
151 u_int8_t page_scan_rep_mode; 152 u_int8_t page_scan_period_mode; 153 u_int8_t page_scan_mode; 154 u_int8_t class[NG_HCI_CLASS_SIZE]; 155 u_int16_t clock_offset; | 151 uint8_t page_scan_rep_mode; 152 uint8_t page_scan_period_mode; 153 uint8_t page_scan_mode; 154 uint8_t class[NG_HCI_CLASS_SIZE]; 155 uint16_t clock_offset; |
156 } *ir = (struct inquiry_response *)(*b); 157 158 fprintf(stdout, "Inquiry result #%d\n", n); 159 fprintf(stdout, "\tBD_ADDR: %s\n", hci_bdaddr2str(&ir->bdaddr)); 160 fprintf(stdout, "\tPage Scan Rep. Mode: %#02x\n", 161 ir->page_scan_rep_mode); 162 fprintf(stdout, "\tPage Scan Period Mode: %#02x\n", 163 ir->page_scan_period_mode); --- 143 unchanged lines hidden (view full) --- 307 308 /* parse command parameters */ 309 switch (argc) { 310 case 2: 311 /* reason */ 312 if (sscanf(argv[1], "%d", &n) != 1 || n <= 0x00 || n > 0xff) 313 return (USAGE); 314 | 156 } *ir = (struct inquiry_response *)(*b); 157 158 fprintf(stdout, "Inquiry result #%d\n", n); 159 fprintf(stdout, "\tBD_ADDR: %s\n", hci_bdaddr2str(&ir->bdaddr)); 160 fprintf(stdout, "\tPage Scan Rep. Mode: %#02x\n", 161 ir->page_scan_rep_mode); 162 fprintf(stdout, "\tPage Scan Period Mode: %#02x\n", 163 ir->page_scan_period_mode); --- 143 unchanged lines hidden (view full) --- 307 308 /* parse command parameters */ 309 switch (argc) { 310 case 2: 311 /* reason */ 312 if (sscanf(argv[1], "%d", &n) != 1 || n <= 0x00 || n > 0xff) 313 return (USAGE); 314 |
315 cp.reason = (u_int8_t) (n & 0xff); | 315 cp.reason = (uint8_t) (n & 0xff); |
316 317 case 1: 318 /* connection handle */ 319 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 320 return (USAGE); 321 | 316 317 case 1: 318 /* connection handle */ 319 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 320 return (USAGE); 321 |
322 cp.con_handle = (u_int16_t) (n & 0x0fff); | 322 cp.con_handle = (uint16_t) (n & 0x0fff); |
323 cp.con_handle = htole16(cp.con_handle); 324 break; 325 326 default: 327 return (USAGE); 328 } 329 330 /* send request and expect status response */ --- 54 unchanged lines hidden (view full) --- 385 /* packet type */ 386 if (sscanf(argv[0], "%x", &n) != 1) 387 return (USAGE); 388 389 n &= (NG_HCI_PKT_HV1 | NG_HCI_PKT_HV2 | NG_HCI_PKT_HV3); 390 if (n == 0) 391 return (USAGE); 392 | 323 cp.con_handle = htole16(cp.con_handle); 324 break; 325 326 default: 327 return (USAGE); 328 } 329 330 /* send request and expect status response */ --- 54 unchanged lines hidden (view full) --- 385 /* packet type */ 386 if (sscanf(argv[0], "%x", &n) != 1) 387 return (USAGE); 388 389 n &= (NG_HCI_PKT_HV1 | NG_HCI_PKT_HV2 | NG_HCI_PKT_HV3); 390 if (n == 0) 391 return (USAGE); 392 |
393 cp.pkt_type = (u_int16_t) (n & 0x0fff); | 393 cp.pkt_type = (uint16_t) (n & 0x0fff); |
394 cp.pkt_type = htole16(cp.pkt_type); 395 396 case 1: 397 /* acl connection handle */ 398 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 399 return (USAGE); 400 | 394 cp.pkt_type = htole16(cp.pkt_type); 395 396 case 1: 397 /* acl connection handle */ 398 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 399 return (USAGE); 400 |
401 cp.con_handle = (u_int16_t) (n & 0x0fff); | 401 cp.con_handle = (uint16_t) (n & 0x0fff); |
402 cp.con_handle = htole16(cp.con_handle); 403 break; 404 405 default: 406 return (USAGE); 407 } 408 409 /* send request and expect status response */ --- 47 unchanged lines hidden (view full) --- 457 ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; 458 459 switch (argc) { 460 case 2: 461 /* connection handle */ 462 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 463 return (USAGE); 464 | 402 cp.con_handle = htole16(cp.con_handle); 403 break; 404 405 default: 406 return (USAGE); 407 } 408 409 /* send request and expect status response */ --- 47 unchanged lines hidden (view full) --- 457 ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; 458 459 switch (argc) { 460 case 2: 461 /* connection handle */ 462 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 463 return (USAGE); 464 |
465 cp.con_handle = (u_int16_t) (n & 0x0fff); | 465 cp.con_handle = (uint16_t) (n & 0x0fff); |
466 cp.con_handle = htole16(cp.con_handle); 467 468 /* packet type */ 469 if (sscanf(argv[1], "%x", &n) != 1) 470 return (USAGE); 471 | 466 cp.con_handle = htole16(cp.con_handle); 467 468 /* packet type */ 469 if (sscanf(argv[1], "%x", &n) != 1) 470 return (USAGE); 471 |
472 cp.pkt_type = (u_int16_t) (n & 0xffff); | 472 cp.pkt_type = (uint16_t) (n & 0xffff); |
473 cp.pkt_type = htole16(cp.pkt_type); 474 break; 475 476 default: 477 return (USAGE); 478 } 479 480 /* send request and expect status response */ --- 486 unchanged lines hidden --- | 473 cp.pkt_type = htole16(cp.pkt_type); 474 break; 475 476 default: 477 return (USAGE); 478 } 479 480 /* send request and expect status response */ --- 486 unchanged lines hidden --- |