1/* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2000-2001 Qualcomm Incorporated 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 7 * Copyright (C) 2002-2009 Marcel Holtmann <marcel@holtmann.org> 8 * 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 */ 25 26#ifndef __HCI_LIB_H 27#define __HCI_LIB_H 28 29#ifdef __cplusplus 30extern "C" { 31#endif 32 33struct hci_request { 34 uint16_t ogf; 35 uint16_t ocf; 36 int event; 37 void *cparam; 38 int clen; 39 void *rparam; 40 int rlen; 41}; 42 43struct hci_version { 44 uint16_t manufacturer; 45 uint8_t hci_ver; 46 uint16_t hci_rev; 47 uint8_t lmp_ver; 48 uint16_t lmp_subver; 49}; 50 51int hci_open_dev(int dev_id); 52int hci_close_dev(int dd); 53int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param); 54int hci_send_req(int dd, struct hci_request *req, int timeout); 55 56int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to); 57int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to); 58 59int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags); 60int hci_devinfo(int dev_id, struct hci_dev_info *di); 61int hci_devba(int dev_id, bdaddr_t *bdaddr); 62int hci_devid(const char *str); 63 64int hci_read_local_name(int dd, int len, char *name, int to); 65int hci_write_local_name(int dd, const char *name, int to); 66int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name, int to); 67int hci_read_remote_name_with_clock_offset(int dd, const bdaddr_t *bdaddr, uint8_t pscan_rep_mode, uint16_t clkoffset, int len, char *name, int to); 68int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to); 69int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver, int to); 70int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to); 71int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 72int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to); 73int hci_read_local_version(int dd, struct hci_version *ver, int to); 74int hci_read_local_commands(int dd, uint8_t *commands, int to); 75int hci_read_local_features(int dd, uint8_t *features, int to); 76int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 77int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to); 78int hci_read_class_of_dev(int dd, uint8_t *cls, int to); 79int hci_write_class_of_dev(int dd, uint32_t cls, int to); 80int hci_read_voice_setting(int dd, uint16_t *vs, int to); 81int hci_write_voice_setting(int dd, uint16_t vs, int to); 82int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to); 83int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to); 84int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 85int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to); 86int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 87int hci_authenticate_link(int dd, uint16_t handle, int to); 88int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to); 89int hci_change_link_key(int dd, uint16_t handle, int to); 90int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to); 91int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to); 92int hci_exit_park_mode(int dd, uint16_t handle, int to); 93int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to); 94int hci_write_inquiry_scan_type(int dd, uint8_t type, int to); 95int hci_read_inquiry_mode(int dd, uint8_t *mode, int to); 96int hci_write_inquiry_mode(int dd, uint8_t mode, int to); 97int hci_read_afh_mode(int dd, uint8_t *mode, int to); 98int hci_write_afh_mode(int dd, uint8_t mode, int to); 99int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to); 100int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to); 101int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to); 102int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to); 103int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to); 104int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to); 105int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to); 106int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type, int8_t *level, int to); 107int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to); 108int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to); 109int hci_read_link_supervision_timeout(int dd, uint16_t handle, uint16_t *timeout, int to); 110int hci_write_link_supervision_timeout(int dd, uint16_t handle, uint16_t timeout, int to); 111int hci_set_afh_classification(int dd, uint8_t *map, int to); 112int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality, int to); 113int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to); 114int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map, int to); 115int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock, uint16_t *accuracy, int to); 116 117int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg); 118int hci_get_route(bdaddr_t *bdaddr); 119 120char *hci_dtypetostr(int type); 121char *hci_dflagstostr(uint32_t flags); 122char *hci_ptypetostr(unsigned int ptype); 123int hci_strtoptype(char *str, unsigned int *val); 124char *hci_scoptypetostr(unsigned int ptype); 125int hci_strtoscoptype(char *str, unsigned int *val); 126char *hci_lptostr(unsigned int ptype); 127int hci_strtolp(char *str, unsigned int *val); 128char *hci_lmtostr(unsigned int ptype); 129int hci_strtolm(char *str, unsigned int *val); 130 131char *hci_cmdtostr(unsigned int cmd); 132char *hci_commandstostr(uint8_t *commands, char *pref, int width); 133 134char *hci_vertostr(unsigned int ver); 135int hci_strtover(char *str, unsigned int *ver); 136char *lmp_vertostr(unsigned int ver); 137int lmp_strtover(char *str, unsigned int *ver); 138 139char *lmp_featurestostr(uint8_t *features, char *pref, int width); 140 141static inline void hci_set_bit(int nr, void *addr) 142{ 143 *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31)); 144} 145 146static inline void hci_clear_bit(int nr, void *addr) 147{ 148 *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31)); 149} 150 151static inline int hci_test_bit(int nr, void *addr) 152{ 153 return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31)); 154} 155 156/* HCI filter tools */ 157static inline void hci_filter_clear(struct hci_filter *f) 158{ 159 memset(f, 0, sizeof(*f)); 160} 161static inline void hci_filter_set_ptype(int t, struct hci_filter *f) 162{ 163 hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 164} 165static inline void hci_filter_clear_ptype(int t, struct hci_filter *f) 166{ 167 hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 168} 169static inline int hci_filter_test_ptype(int t, struct hci_filter *f) 170{ 171 return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 172} 173static inline void hci_filter_all_ptypes(struct hci_filter *f) 174{ 175 memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask)); 176} 177static inline void hci_filter_set_event(int e, struct hci_filter *f) 178{ 179 hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 180} 181static inline void hci_filter_clear_event(int e, struct hci_filter *f) 182{ 183 hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 184} 185static inline int hci_filter_test_event(int e, struct hci_filter *f) 186{ 187 return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 188} 189static inline void hci_filter_all_events(struct hci_filter *f) 190{ 191 memset((void *) f->event_mask, 0xff, sizeof(f->event_mask)); 192} 193static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f) 194{ 195 f->opcode = opcode; 196} 197static inline void hci_filter_clear_opcode(struct hci_filter *f) 198{ 199 f->opcode = 0; 200} 201static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f) 202{ 203 return (f->opcode == opcode); 204} 205 206#ifdef __cplusplus 207} 208#endif 209 210#endif /* __HCI_LIB_H */ 211