1 /* 2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 */ 7 8 #ifndef _BTHCI_COMMAND_H_ 9 #define _BTHCI_COMMAND_H_ 10 11 #include <bluetooth/bluetooth.h> 12 #include <bluetooth/HCI/btHCI.h> 13 14 #define HCI_COMMAND_HDR_SIZE 3 15 16 struct hci_command_header { 17 uint16 opcode; /* OCF & OGF */ 18 uint8 clen; 19 } __attribute__ ((packed)); 20 21 22 /* Command opcode pack/unpack */ 23 #define PACK_OPCODE(ogf, ocf) (uint16)((ocf & 0x03ff)|(ogf << 10)) 24 #define GET_OPCODE_OGF(op) (op >> 10) 25 #define GET_OPCODE_OCF(op) (op & 0x03ff) 26 27 28 /* - Informational Parameters Command definition - */ 29 #define OGF_INFORMATIONAL_PARAM 0x04 30 31 #define OCF_READ_LOCAL_VERSION 0x0001 32 struct hci_rp_read_loc_version { 33 uint8 status; 34 uint8 hci_ver; 35 uint16 hci_rev; 36 uint8 lmp_ver; 37 uint16 manufacturer; 38 uint16 lmp_subver; 39 } __attribute__ ((packed)); 40 41 #define OCF_READ_LOCAL_FEATURES 0x0003 42 struct hci_rp_read_loc_features { 43 uint8 status; 44 uint8 features[8]; 45 } __attribute__ ((packed)); 46 47 #define OCF_READ_BUFFER_SIZE 0x0005 48 struct hci_rp_read_buffer_size { 49 uint8 status; 50 uint16 acl_mtu; 51 uint8 sco_mtu; 52 uint16 acl_max_pkt; 53 uint16 sco_max_pkt; 54 } __attribute__ ((packed)); 55 56 #define OCF_READ_BD_ADDR 0x0009 57 struct hci_rp_read_bd_addr { 58 uint8 status; 59 bdaddr_t bdaddr; 60 } __attribute__ ((packed)); 61 62 /* - Host Controller and Baseband Command definition - */ 63 #define OGF_CONTROL_BASEBAND 0x03 64 65 #define OCF_RESET 0x0003 66 /*struct hci_reset { 67 void no_fields; 68 } __attribute__ ((packed));*/ 69 70 #define OCF_SET_EVENT_FLT 0x0005 71 struct hci_cp_set_event_flt { 72 uint8 flt_type; 73 uint8 cond_type; 74 uint8 condition[0]; 75 } __attribute__ ((packed)); 76 77 #define OCF_READ_STORED_LINK_KEY 0x000D 78 struct hci_read_stored_link_key { 79 bdaddr_t bdaddr; 80 uint8 all_keys_flag; 81 } __attribute__ ((packed)); 82 struct hci_read_stored_link_key_reply { 83 uint8 status; 84 uint16 max_num_keys; 85 uint16 num_keys_read; 86 } __attribute__ ((packed)); 87 88 #define OCF_WRITE_STORED_LINK_KEY 0x0011 89 struct hci_write_stored_link_key { 90 uint8 num_keys_to_write; 91 // these are repeated "num_keys_write" times 92 bdaddr_t bdaddr; 93 uint8 key[HCI_LINK_KEY_SIZE]; 94 } __attribute__ ((packed)); 95 struct hci_write_stored_link_key_reply { 96 uint8 status; 97 uint8 num_keys_written; 98 } __attribute__ ((packed)); 99 100 101 #define OCF_WRITE_LOCAL_NAME 0x0013 102 #define OCF_READ_LOCAL_NAME 0x0014 103 struct hci_rp_read_local_name { 104 uint8 status; 105 char local_name[HCI_DEVICE_NAME_SIZE]; 106 } __attribute__ ((packed)); 107 108 #define OCF_WRITE_CA_TIMEOUT 0x0016 109 #define OCF_WRITE_PG_TIMEOUT 0x0018 110 111 #define OCF_WRITE_SCAN_ENABLE 0x001A 112 #define HCI_SCAN_DISABLED 0x00 113 #define HCI_SCAN_INQUIRY 0x01 114 #define HCI_SCAN_PAGE 0x02 115 #define HCI_SCAN_INQUIRY_PAGE 0x03 116 struct hci_write_scan_enable { 117 uint8 scan; 118 } __attribute__ ((packed)); 119 120 #define OCF_READ_AUTH_ENABLE 0x001F 121 #define OCF_WRITE_AUTH_ENABLE 0x0020 122 #define HCI_AUTH_DISABLED 0x00 123 #define HCI_AUTH_ENABLED 0x01 124 struct hci_write_authentication_enable { 125 uint8 authentication; 126 } __attribute__ ((packed)); 127 128 #define OCF_READ_ENCRYPT_MODE 0x0021 129 #define OCF_WRITE_ENCRYPT_MODE 0x0022 130 #define HCI_ENCRYPT_DISABLED 0x00 131 #define HCI_ENCRYPT_P2P 0x01 132 #define HCI_ENCRYPT_BOTH 0x02 133 struct hci_write_encryption_mode_enable { 134 uint8 encryption; 135 } __attribute__ ((packed)); 136 137 /* Filter types */ 138 #define HCI_FLT_CLEAR_ALL 0x00 139 #define HCI_FLT_INQ_RESULT 0x01 140 #define HCI_FLT_CONN_SETUP 0x02 141 142 /* CONN_SETUP Condition types */ 143 #define HCI_CONN_SETUP_ALLOW_ALL 0x00 144 #define HCI_CONN_SETUP_ALLOW_CLASS 0x01 145 #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02 146 147 /* CONN_SETUP Conditions */ 148 #define HCI_CONN_SETUP_AUTO_OFF 0x01 149 #define HCI_CONN_SETUP_AUTO_ON 0x02 150 151 #define OCF_READ_CLASS_OF_DEV 0x0023 152 153 struct hci_read_dev_class_reply { 154 uint8 status; 155 uint8 dev_class[3]; 156 } __attribute__ ((packed)); 157 158 #define OCF_WRITE_CLASS_OF_DEV 0x0024 159 struct hci_write_dev_class { 160 uint8 dev_class[3]; 161 } __attribute__ ((packed)); 162 163 #define OCF_READ_VOICE_SETTING 0x0025 164 struct hci_rp_read_voice_setting { 165 uint8 status; 166 uint16 voice_setting; 167 } __attribute__ ((packed)); 168 169 #define OCF_WRITE_VOICE_SETTING 0x0026 170 struct hci_cp_write_voice_setting { 171 uint16 voice_setting; 172 } __attribute__ ((packed)); 173 174 #define OCF_HOST_BUFFER_SIZE 0x0033 175 struct hci_cp_host_buffer_size { 176 uint16 acl_mtu; 177 uint8 sco_mtu; 178 uint16 acl_max_pkt; 179 uint16 sco_max_pkt; 180 } __attribute__ ((packed)); 181 182 /* Link Control Command definition */ 183 #define OGF_LINK_CONTROL 0x01 184 185 #define OCF_INQUIRY 0x0001 186 struct hci_cp_inquiry { 187 uint8 lap[3]; 188 uint8 length; 189 uint8 num_rsp; 190 } __attribute__ ((packed)); 191 192 #define OCF_INQUIRY_CANCEL 0x0002 193 194 #define OCF_CREATE_CONN 0x0005 195 struct hci_cp_create_conn { 196 bdaddr_t bdaddr; 197 uint16 pkt_type; 198 uint8 pscan_rep_mode; 199 uint8 pscan_mode; 200 uint16 clock_offset; 201 uint8 role_switch; 202 } __attribute__ ((packed)); 203 204 #define OCF_DISCONNECT 0x0006 205 struct hci_disconnect { 206 uint16 handle; 207 uint8 reason; 208 } __attribute__ ((packed)); 209 210 #define OCF_ADD_SCO 0x0007 211 struct hci_cp_add_sco { 212 uint16 handle; 213 uint16 pkt_type; 214 } __attribute__ ((packed)); 215 216 #define OCF_ACCEPT_CONN_REQ 0x0009 217 struct hci_cp_accept_conn_req { 218 bdaddr_t bdaddr; 219 uint8 role; 220 } __attribute__ ((packed)); 221 222 #define OCF_REJECT_CONN_REQ 0x000a 223 struct hci_cp_reject_conn_req { 224 bdaddr_t bdaddr; 225 uint8 reason; 226 } __attribute__ ((packed)); 227 228 #define OCF_LINK_KEY_REPLY 0x000B 229 struct hci_cp_link_key_reply { 230 bdaddr_t bdaddr; 231 uint8 link_key[16]; 232 } __attribute__ ((packed)); 233 234 #define OCF_LINK_KEY_NEG_REPLY 0x000C 235 struct hci_cp_link_key_neg_reply { 236 bdaddr_t bdaddr; 237 } __attribute__ ((packed)); 238 239 #define OCF_PIN_CODE_REPLY 0x000D 240 struct hci_cp_pin_code_reply { 241 bdaddr_t bdaddr; 242 uint8 pin_len; 243 uint8 pin_code[16]; 244 } __attribute__ ((packed)); 245 246 #define OCF_PIN_CODE_NEG_REPLY 0x000E 247 struct hci_cp_pin_code_neg_reply { 248 bdaddr_t bdaddr; 249 } __attribute__ ((packed)); 250 251 #define OCF_CHANGE_CONN_PTYPE 0x000F 252 struct hci_cp_change_conn_ptype { 253 uint16 handle; 254 uint16 pkt_type; 255 } __attribute__ ((packed)); 256 257 #define OCF_AUTH_REQUESTED 0x0011 258 struct hci_cp_auth_requested { 259 uint16 handle; 260 } __attribute__ ((packed)); 261 262 #define OCF_SET_CONN_ENCRYPT 0x0013 263 struct hci_cp_set_conn_encrypt { 264 uint16 handle; 265 uint8 encrypt; 266 } __attribute__ ((packed)); 267 268 #define OCF_CHANGE_CONN_LINK_KEY 0x0015 269 struct hci_cp_change_conn_link_key { 270 uint16 handle; 271 } __attribute__ ((packed)); 272 273 #define OCF_REMOTE_NAME_REQUEST 0x0019 274 struct hci_remote_name_request { 275 bdaddr_t bdaddr; 276 uint8 pscan_rep_mode; 277 uint8 reserved; 278 uint16 clock_offset; 279 } __attribute__ ((packed)); 280 281 #define OCF_READ_REMOTE_FEATURES 0x001B 282 struct hci_cp_read_rmt_features { 283 uint16 handle; 284 } __attribute__ ((packed)); 285 286 #define OCF_READ_REMOTE_VERSION 0x001D 287 struct hci_cp_read_rmt_version { 288 uint16 handle; 289 } __attribute__ ((packed)); 290 291 292 /* Link Policy Command definition */ 293 #define OGF_LINK_POLICY 0x02 294 295 #define OCF_ROLE_DISCOVERY 0x0009 296 struct hci_cp_role_discovery { 297 uint16 handle; 298 } __attribute__ ((packed)); 299 struct hci_rp_role_discovery { 300 uint8 status; 301 uint16 handle; 302 uint8 role; 303 } __attribute__ ((packed)); 304 305 #define OCF_READ_LINK_POLICY 0x000C 306 struct hci_cp_read_link_policy { 307 uint16 handle; 308 } __attribute__ ((packed)); 309 struct hci_rp_read_link_policy { 310 uint8 status; 311 uint16 handle; 312 uint16 policy; 313 } __attribute__ ((packed)); 314 315 #define OCF_SWITCH_ROLE 0x000B 316 struct hci_cp_switch_role { 317 bdaddr_t bdaddr; 318 uint8 role; 319 } __attribute__ ((packed)); 320 321 #define OCF_WRITE_LINK_POLICY 0x000D 322 struct hci_cp_write_link_policy { 323 uint16 handle; 324 uint16 policy; 325 } __attribute__ ((packed)); 326 struct hci_rp_write_link_policy { 327 uint8 status; 328 uint16 handle; 329 } __attribute__ ((packed)); 330 331 /* Status params */ 332 #define OGF_STATUS_PARAM 0x05 333 334 /* Testing commands */ 335 #define OGF_TESTING_CMD 0x3E 336 337 /* Vendor specific commands */ 338 #define OGF_VENDOR_CMD 0x3F 339 340 #endif 341