host_controller_baseband.c (121054) | host_controller_baseband.c (128079) |
---|---|
1/* 2 * host_controller_baseband.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: host_controller_baseband.c,v 1.4 2003/08/18 19:19:53 max Exp $ | 1/* 2 * host_controller_baseband.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: host_controller_baseband.c,v 1.4 2003/08/18 19:19:53 max Exp $ |
29 * $FreeBSD: head/usr.sbin/bluetooth/hccontrol/host_controller_baseband.c 121054 2003-10-12 22:04:24Z emax $ | 29 * $FreeBSD: head/usr.sbin/bluetooth/hccontrol/host_controller_baseband.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 --- 21 unchanged lines hidden (view full) --- 59 int lo = hci_hexa2int4(a + 1); 60 61 if (hi < 0 || lo < 0) 62 return (-1); 63 64 return ((hi << 4) | lo); 65} 66 | 30 */ 31 32#include <bluetooth.h> 33#include <errno.h> 34#include <stdio.h> 35#include <string.h> 36#include "hccontrol.h" 37 --- 21 unchanged lines hidden (view full) --- 59 int lo = hci_hexa2int4(a + 1); 60 61 if (hi < 0 || lo < 0) 62 return (-1); 63 64 return ((hi << 4) | lo); 65} 66 |
67/* Convert ascii hex string to the u_int8_t[] */ | 67/* Convert ascii hex string to the uint8_t[] */ |
68static int | 68static int |
69hci_hexstring2array(char const *s, u_int8_t *a, int asize) | 69hci_hexstring2array(char const *s, uint8_t *a, int asize) |
70{ 71 int i, l, b; 72 73 l = strlen(s) / 2; 74 if (l > asize) 75 l = asize; 76 77 for (i = 0; i < l; i++) { --- 62 unchanged lines hidden (view full) --- 140 int n; 141 142 /* parse command parameters */ 143 switch (argc) { 144 case 1: 145 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 146 return (USAGE); 147 | 70{ 71 int i, l, b; 72 73 l = strlen(s) / 2; 74 if (l > asize) 75 l = asize; 76 77 for (i = 0; i < l; i++) { --- 62 unchanged lines hidden (view full) --- 140 int n; 141 142 /* parse command parameters */ 143 switch (argc) { 144 case 1: 145 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 146 return (USAGE); 147 |
148 cp.pin_type = (u_int8_t) n; | 148 cp.pin_type = (uint8_t) n; |
149 break; 150 151 default: 152 return (USAGE); 153 } 154 155 /* send command */ 156 n = sizeof(rp); --- 21 unchanged lines hidden (view full) --- 178 ng_hci_read_stored_link_key_cp cp; 179 } __attribute__ ((packed)) cmd; 180 181 struct { 182 ng_hci_event_pkt_t hdr; 183 union { 184 ng_hci_command_compl_ep cc; 185 ng_hci_return_link_keys_ep key; | 149 break; 150 151 default: 152 return (USAGE); 153 } 154 155 /* send command */ 156 n = sizeof(rp); --- 21 unchanged lines hidden (view full) --- 178 ng_hci_read_stored_link_key_cp cp; 179 } __attribute__ ((packed)) cmd; 180 181 struct { 182 ng_hci_event_pkt_t hdr; 183 union { 184 ng_hci_command_compl_ep cc; 185 ng_hci_return_link_keys_ep key; |
186 u_int8_t b[NG_HCI_EVENT_PKT_SIZE]; | 186 uint8_t b[NG_HCI_EVENT_PKT_SIZE]; |
187 } ep; 188 } __attribute__ ((packed)) event; 189 190 int n, n1; 191 192 /* Send command */ 193 memset(&cmd, 0, sizeof(cmd)); 194 cmd.hdr.type = NG_HCI_CMD_PKT; --- 57 unchanged lines hidden (view full) --- 252 le16toh(rp->max_num_keys)); 253 fprintf(stdout, "Number of keys read: %d\n", 254 le16toh(rp->num_keys_read)); 255 } break; 256 257 case NG_HCI_EVENT_RETURN_LINK_KEYS: { 258 struct _key { 259 bdaddr_t bdaddr; | 187 } ep; 188 } __attribute__ ((packed)) event; 189 190 int n, n1; 191 192 /* Send command */ 193 memset(&cmd, 0, sizeof(cmd)); 194 cmd.hdr.type = NG_HCI_CMD_PKT; --- 57 unchanged lines hidden (view full) --- 252 le16toh(rp->max_num_keys)); 253 fprintf(stdout, "Number of keys read: %d\n", 254 le16toh(rp->num_keys_read)); 255 } break; 256 257 case NG_HCI_EVENT_RETURN_LINK_KEYS: { 258 struct _key { 259 bdaddr_t bdaddr; |
260 u_int8_t key[NG_HCI_KEY_SIZE]; | 260 uint8_t key[NG_HCI_KEY_SIZE]; |
261 } __attribute__ ((packed)) *k = NULL; 262 263 fprintf(stdout, "Event: Number of keys: %d\n", 264 event.ep.key.num_keys); 265 266 k = (struct _key *)(event.ep.b + sizeof(event.ep.key)); 267 for (n = 0; n < event.ep.key.num_keys; n++) { 268 fprintf(stdout, "\t%d: %s ", --- 19 unchanged lines hidden (view full) --- 288 289/* Send Write_Stored_Link_Key command to the unit */ 290static int 291hci_write_stored_link_key(int s, int argc, char **argv) 292{ 293 struct { 294 ng_hci_write_stored_link_key_cp p; 295 bdaddr_t bdaddr; | 261 } __attribute__ ((packed)) *k = NULL; 262 263 fprintf(stdout, "Event: Number of keys: %d\n", 264 event.ep.key.num_keys); 265 266 k = (struct _key *)(event.ep.b + sizeof(event.ep.key)); 267 for (n = 0; n < event.ep.key.num_keys; n++) { 268 fprintf(stdout, "\t%d: %s ", --- 19 unchanged lines hidden (view full) --- 288 289/* Send Write_Stored_Link_Key command to the unit */ 290static int 291hci_write_stored_link_key(int s, int argc, char **argv) 292{ 293 struct { 294 ng_hci_write_stored_link_key_cp p; 295 bdaddr_t bdaddr; |
296 u_int8_t key[NG_HCI_KEY_SIZE]; | 296 uint8_t key[NG_HCI_KEY_SIZE]; |
297 } cp; 298 ng_hci_write_stored_link_key_rp rp; 299 int32_t n; 300 301 memset(&cp, 0, sizeof(cp)); 302 303 switch (argc) { 304 case 2: --- 179 unchanged lines hidden (view full) --- 484 int n; 485 486 /* parse command parameters */ 487 switch (argc) { 488 case 1: 489 if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xb540) 490 return (USAGE); 491 | 297 } cp; 298 ng_hci_write_stored_link_key_rp rp; 299 int32_t n; 300 301 memset(&cp, 0, sizeof(cp)); 302 303 switch (argc) { 304 case 2: --- 179 unchanged lines hidden (view full) --- 484 int n; 485 486 /* parse command parameters */ 487 switch (argc) { 488 case 1: 489 if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xb540) 490 return (USAGE); 491 |
492 cp.timeout = (u_int16_t) n; | 492 cp.timeout = (uint16_t) n; |
493 cp.timeout = htole16(cp.timeout); 494 break; 495 496 default: 497 return (USAGE); 498 } 499 500 /* send command */ --- 48 unchanged lines hidden (view full) --- 549 int n; 550 551 /* parse command parameters */ 552 switch (argc) { 553 case 1: 554 if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xffff) 555 return (USAGE); 556 | 493 cp.timeout = htole16(cp.timeout); 494 break; 495 496 default: 497 return (USAGE); 498 } 499 500 /* send command */ --- 48 unchanged lines hidden (view full) --- 549 int n; 550 551 /* parse command parameters */ 552 switch (argc) { 553 case 1: 554 if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xffff) 555 return (USAGE); 556 |
557 cp.timeout = (u_int16_t) n; | 557 cp.timeout = (uint16_t) n; |
558 cp.timeout = htole16(cp.timeout); 559 break; 560 561 default: 562 return (USAGE); 563 } 564 565 /* send command */ --- 47 unchanged lines hidden (view full) --- 613 int n; 614 615 /* parse command parameters */ 616 switch (argc) { 617 case 1: 618 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 3) 619 return (USAGE); 620 | 558 cp.timeout = htole16(cp.timeout); 559 break; 560 561 default: 562 return (USAGE); 563 } 564 565 /* send command */ --- 47 unchanged lines hidden (view full) --- 613 int n; 614 615 /* parse command parameters */ 616 switch (argc) { 617 case 1: 618 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 3) 619 return (USAGE); 620 |
621 cp.scan_enable = (u_int8_t) n; | 621 cp.scan_enable = (uint8_t) n; |
622 break; 623 624 default: 625 return (USAGE); 626 } 627 628 n = sizeof(rp); 629 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, --- 51 unchanged lines hidden (view full) --- 681 682 /* parse command parameters */ 683 switch (argc) { 684 case 2: 685 /* page scan interval */ 686 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 687 return (USAGE); 688 | 622 break; 623 624 default: 625 return (USAGE); 626 } 627 628 n = sizeof(rp); 629 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, --- 51 unchanged lines hidden (view full) --- 681 682 /* parse command parameters */ 683 switch (argc) { 684 case 2: 685 /* page scan interval */ 686 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 687 return (USAGE); 688 |
689 cp.page_scan_interval = (u_int16_t) n; | 689 cp.page_scan_interval = (uint16_t) n; |
690 691 /* page scan window */ 692 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 693 return (USAGE); 694 | 690 691 /* page scan window */ 692 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 693 return (USAGE); 694 |
695 cp.page_scan_window = (u_int16_t) n; | 695 cp.page_scan_window = (uint16_t) n; |
696 697 if (cp.page_scan_window > cp.page_scan_interval) 698 return (USAGE); 699 700 cp.page_scan_interval = htole16(cp.page_scan_interval); 701 cp.page_scan_window = htole16(cp.page_scan_window); 702 break; 703 --- 58 unchanged lines hidden (view full) --- 762 763 /* parse command parameters */ 764 switch (argc) { 765 case 2: 766 /* inquiry scan interval */ 767 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 768 return (USAGE); 769 | 696 697 if (cp.page_scan_window > cp.page_scan_interval) 698 return (USAGE); 699 700 cp.page_scan_interval = htole16(cp.page_scan_interval); 701 cp.page_scan_window = htole16(cp.page_scan_window); 702 break; 703 --- 58 unchanged lines hidden (view full) --- 762 763 /* parse command parameters */ 764 switch (argc) { 765 case 2: 766 /* inquiry scan interval */ 767 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 768 return (USAGE); 769 |
770 cp.inquiry_scan_interval = (u_int16_t) n; | 770 cp.inquiry_scan_interval = (uint16_t) n; |
771 772 /* inquiry scan window */ 773 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 774 return (USAGE); 775 | 771 772 /* inquiry scan window */ 773 if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) 774 return (USAGE); 775 |
776 cp.inquiry_scan_window = (u_int16_t) n; | 776 cp.inquiry_scan_window = (uint16_t) n; |
777 778 if (cp.inquiry_scan_window > cp.inquiry_scan_interval) 779 return (USAGE); 780 781 cp.inquiry_scan_interval = 782 htole16(cp.inquiry_scan_interval); 783 cp.inquiry_scan_window = htole16(cp.inquiry_scan_window); 784 break; --- 53 unchanged lines hidden (view full) --- 838 int n; 839 840 /* parse command parameters */ 841 switch (argc) { 842 case 1: 843 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 844 return (USAGE); 845 | 777 778 if (cp.inquiry_scan_window > cp.inquiry_scan_interval) 779 return (USAGE); 780 781 cp.inquiry_scan_interval = 782 htole16(cp.inquiry_scan_interval); 783 cp.inquiry_scan_window = htole16(cp.inquiry_scan_window); 784 break; --- 53 unchanged lines hidden (view full) --- 838 int n; 839 840 /* parse command parameters */ 841 switch (argc) { 842 case 1: 843 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 844 return (USAGE); 845 |
846 cp.auth_enable = (u_int8_t) n; | 846 cp.auth_enable = (uint8_t) n; |
847 break; 848 849 default: 850 return (USAGE); 851 } 852 853 /* send command */ 854 n = sizeof(rp); --- 46 unchanged lines hidden (view full) --- 901 int n; 902 903 /* parse command parameters */ 904 switch (argc) { 905 case 1: 906 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 2) 907 return (USAGE); 908 | 847 break; 848 849 default: 850 return (USAGE); 851 } 852 853 /* send command */ 854 n = sizeof(rp); --- 46 unchanged lines hidden (view full) --- 901 int n; 902 903 /* parse command parameters */ 904 switch (argc) { 905 case 1: 906 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 2) 907 return (USAGE); 908 |
909 cp.encryption_mode = (u_int8_t) n; | 909 cp.encryption_mode = (uint8_t) n; |
910 break; 911 912 default: 913 return (USAGE); 914 } 915 916 /* send command */ 917 n = sizeof(rp); --- 127 unchanged lines hidden (view full) --- 1045 int n; 1046 1047 /* parse command parameters */ 1048 switch (argc) { 1049 case 1: 1050 if (sscanf(argv[0], "%x", &n) != 1) 1051 return (USAGE); 1052 | 910 break; 911 912 default: 913 return (USAGE); 914 } 915 916 /* send command */ 917 n = sizeof(rp); --- 127 unchanged lines hidden (view full) --- 1045 int n; 1046 1047 /* parse command parameters */ 1048 switch (argc) { 1049 case 1: 1050 if (sscanf(argv[0], "%x", &n) != 1) 1051 return (USAGE); 1052 |
1053 cp.settings = (u_int16_t) n; | 1053 cp.settings = (uint16_t) n; |
1054 cp.settings = htole16(cp.settings); 1055 break; 1056 1057 default: 1058 return (USAGE); 1059 } 1060 1061 /* send command */ --- 47 unchanged lines hidden (view full) --- 1109 int n; 1110 1111 /* parse command parameters */ 1112 switch (argc) { 1113 case 1: 1114 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0xff) 1115 return (USAGE); 1116 | 1054 cp.settings = htole16(cp.settings); 1055 break; 1056 1057 default: 1058 return (USAGE); 1059 } 1060 1061 /* send command */ --- 47 unchanged lines hidden (view full) --- 1109 int n; 1110 1111 /* parse command parameters */ 1112 switch (argc) { 1113 case 1: 1114 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0xff) 1115 return (USAGE); 1116 |
1117 cp.counter = (u_int8_t) n; | 1117 cp.counter = (uint8_t) n; |
1118 break; 1119 1120 default: 1121 return (USAGE); 1122 } 1123 1124 /* send command */ 1125 n = sizeof(rp); --- 53 unchanged lines hidden (view full) --- 1179 int n; 1180 1181 /* parse command parameters */ 1182 switch (argc) { 1183 case 1: 1184 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 4) 1185 return (USAGE); 1186 | 1118 break; 1119 1120 default: 1121 return (USAGE); 1122 } 1123 1124 /* send command */ 1125 n = sizeof(rp); --- 53 unchanged lines hidden (view full) --- 1179 int n; 1180 1181 /* parse command parameters */ 1182 switch (argc) { 1183 case 1: 1184 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 4) 1185 return (USAGE); 1186 |
1187 cp.hold_mode_activity = (u_int8_t) n; | 1187 cp.hold_mode_activity = (uint8_t) n; |
1188 break; 1189 1190 default: 1191 return (USAGE); 1192 } 1193 1194 /* send command */ 1195 n = sizeof(rp); --- 46 unchanged lines hidden (view full) --- 1242 int n; 1243 1244 /* parse command parameters */ 1245 switch (argc) { 1246 case 1: 1247 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 1248 return (USAGE); 1249 | 1188 break; 1189 1190 default: 1191 return (USAGE); 1192 } 1193 1194 /* send command */ 1195 n = sizeof(rp); --- 46 unchanged lines hidden (view full) --- 1242 int n; 1243 1244 /* parse command parameters */ 1245 switch (argc) { 1246 case 1: 1247 if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) 1248 return (USAGE); 1249 |
1250 cp.flow_control = (u_int8_t) n; | 1250 cp.flow_control = (uint8_t) n; |
1251 break; 1252 1253 default: 1254 return (USAGE); 1255 } 1256 1257 /* send command */ 1258 n = sizeof(rp); --- 21 unchanged lines hidden (view full) --- 1280 int n; 1281 1282 switch (argc) { 1283 case 1: 1284 /* connection handle */ 1285 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 1286 return (USAGE); 1287 | 1251 break; 1252 1253 default: 1254 return (USAGE); 1255 } 1256 1257 /* send command */ 1258 n = sizeof(rp); --- 21 unchanged lines hidden (view full) --- 1280 int n; 1281 1282 switch (argc) { 1283 case 1: 1284 /* connection handle */ 1285 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 1286 return (USAGE); 1287 |
1288 cp.con_handle = (u_int16_t) (n & 0x0fff); | 1288 cp.con_handle = (uint16_t) (n & 0x0fff); |
1289 cp.con_handle = htole16(cp.con_handle); 1290 break; 1291 1292 default: 1293 return (USAGE); 1294 } 1295 1296 /* send command */ --- 28 unchanged lines hidden (view full) --- 1325 int n; 1326 1327 switch (argc) { 1328 case 2: 1329 /* connection handle */ 1330 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 1331 return (USAGE); 1332 | 1289 cp.con_handle = htole16(cp.con_handle); 1290 break; 1291 1292 default: 1293 return (USAGE); 1294 } 1295 1296 /* send command */ --- 28 unchanged lines hidden (view full) --- 1325 int n; 1326 1327 switch (argc) { 1328 case 2: 1329 /* connection handle */ 1330 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) 1331 return (USAGE); 1332 |
1333 cp.con_handle = (u_int16_t) (n & 0x0fff); | 1333 cp.con_handle = (uint16_t) (n & 0x0fff); |
1334 cp.con_handle = htole16(cp.con_handle); 1335 1336 /* link supervision timeout */ 1337 if (sscanf(argv[1], "%d", &n) != 1 || n < 0 || n > 0xeff) 1338 return (USAGE); 1339 | 1334 cp.con_handle = htole16(cp.con_handle); 1335 1336 /* link supervision timeout */ 1337 if (sscanf(argv[1], "%d", &n) != 1 || n < 0 || n > 0xeff) 1338 return (USAGE); 1339 |
1340 cp.timeout = (u_int16_t) (n & 0x0fff); | 1340 cp.timeout = (uint16_t) (n & 0x0fff); |
1341 cp.timeout = htole16(cp.timeout); 1342 break; 1343 1344 default: 1345 return (USAGE); 1346 } 1347 1348 /* send command */ --- 529 unchanged lines hidden --- | 1341 cp.timeout = htole16(cp.timeout); 1342 break; 1343 1344 default: 1345 return (USAGE); 1346 } 1347 1348 /* send command */ --- 529 unchanged lines hidden --- |