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