ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
hci.c File Reference

hci functions More...

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include "bluetooth.h"
#include "hci.h"
#include "hci_lib.h"

Go to the source code of this file.

Data Structures

struct  hci_map
 

Macros

#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 

Functions

static char * hci_bit2str (hci_map *m, unsigned int val)
 
static int hci_str2bit (hci_map *map, char *str, unsigned int *val)
 
static char * hci_uint2str (hci_map *m, unsigned int val)
 
static int hci_str2uint (hci_map *map, char *str, unsigned int *val)
 
char * hci_bustostr (int bus)
 
char * hci_dtypetostr (int type)
 
char * hci_typetostr (int type)
 
char * hci_dflagstostr (uint32_t flags)
 
char * hci_ptypetostr (unsigned int ptype)
 
int hci_strtoptype (char *str, unsigned int *val)
 
char * hci_scoptypetostr (unsigned int ptype)
 
int hci_strtoscoptype (char *str, unsigned int *val)
 
char * hci_lptostr (unsigned int lp)
 
int hci_strtolp (char *str, unsigned int *val)
 
char * hci_lmtostr (unsigned int lm)
 
int hci_strtolm (char *str, unsigned int *val)
 
char * hci_cmdtostr (unsigned int cmd)
 
char * hci_commandstostr (uint8_t *commands, char *pref, int width)
 
char * hci_vertostr (unsigned int ver)
 
int hci_strtover (char *str, unsigned int *ver)
 
char * lmp_vertostr (unsigned int ver)
 
int lmp_strtover (char *str, unsigned int *ver)
 
char * pal_vertostr (unsigned int ver)
 
int pal_strtover (char *str, unsigned int *ver)
 
char * lmp_featurestostr (uint8_t *features, char *pref, int width)
 
int hci_for_each_dev (int flag, int(*func)(int dd, int dev_id, long arg), long arg)
 
static int __other_bdaddr (int dd, int dev_id, long arg)
 
static int __same_bdaddr (int dd, int dev_id, long arg)
 
int hci_get_route (bdaddr_t *bdaddr)
 
int hci_devid (const char *str)
 
int hci_devinfo (int dev_id, struct hci_dev_info *di)
 
int hci_devba (int dev_id, bdaddr_t *bdaddr)
 
int hci_inquiry (int dev_id, int len, int nrsp, const uint8_t *lap, inquiry_info **ii, long flags)
 
int hci_open_dev (int dev_id)
 
int hci_close_dev (int dd)
 
int hci_send_cmd (int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param)
 
int hci_send_req (int dd, struct hci_request *r, int to)
 
int hci_create_connection (int dd, const bdaddr_t *bdaddr, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to)
 
int hci_disconnect (int dd, uint16_t handle, uint8_t reason, int to)
 
int hci_le_add_white_list (int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
 
int hci_le_rm_white_list (int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
 
int hci_le_read_white_list_size (int dd, uint8_t *size, int to)
 
int hci_le_clear_white_list (int dd, int to)
 
int hci_le_add_resolving_list (int dd, const bdaddr_t *bdaddr, uint8_t type, uint8_t *peer_irk, uint8_t *local_irk, int to)
 
int hci_le_rm_resolving_list (int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
 
int hci_le_clear_resolving_list (int dd, int to)
 
int hci_le_read_resolving_list_size (int dd, uint8_t *size, int to)
 
int hci_le_set_address_resolution_enable (int dd, uint8_t enable, int to)
 
int hci_read_local_name (int dd, int len, char *name, int to)
 
int hci_write_local_name (int dd, const char *name, int to)
 
int 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)
 
int hci_read_remote_name (int dd, const bdaddr_t *bdaddr, int len, char *name, int to)
 
int hci_read_remote_name_cancel (int dd, const bdaddr_t *bdaddr, int to)
 
int hci_read_remote_version (int dd, uint16_t handle, struct hci_version *ver, int to)
 
int hci_read_remote_features (int dd, uint16_t handle, uint8_t *features, int to)
 
int hci_read_remote_ext_features (int dd, uint16_t handle, uint8_t page, uint8_t *max_page, uint8_t *features, int to)
 
int hci_read_clock_offset (int dd, uint16_t handle, uint16_t *clkoffset, int to)
 
int hci_read_local_version (int dd, struct hci_version *ver, int to)
 
int hci_read_local_commands (int dd, uint8_t *commands, int to)
 
int hci_read_local_features (int dd, uint8_t *features, int to)
 
int hci_read_local_ext_features (int dd, uint8_t page, uint8_t *max_page, uint8_t *features, int to)
 
int hci_read_bd_addr (int dd, bdaddr_t *bdaddr, int to)
 
int hci_read_class_of_dev (int dd, uint8_t *cls, int to)
 
int hci_write_class_of_dev (int dd, uint32_t cls, int to)
 
int hci_read_voice_setting (int dd, uint16_t *vs, int to)
 
int hci_write_voice_setting (int dd, uint16_t vs, int to)
 
int hci_read_current_iac_lap (int dd, uint8_t *num_iac, uint8_t *lap, int to)
 
int hci_write_current_iac_lap (int dd, uint8_t num_iac, uint8_t *lap, int to)
 
int hci_read_stored_link_key (int dd, bdaddr_t *bdaddr, uint8_t all, int to)
 
int hci_write_stored_link_key (int dd, bdaddr_t *bdaddr, uint8_t *key, int to)
 
int hci_delete_stored_link_key (int dd, bdaddr_t *bdaddr, uint8_t all, int to)
 
int hci_authenticate_link (int dd, uint16_t handle, int to)
 
int hci_encrypt_link (int dd, uint16_t handle, uint8_t encrypt, int to)
 
int hci_change_link_key (int dd, uint16_t handle, int to)
 
int hci_switch_role (int dd, bdaddr_t *bdaddr, uint8_t role, int to)
 
int hci_park_mode (int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to)
 
int hci_exit_park_mode (int dd, uint16_t handle, int to)
 
int hci_read_inquiry_scan_type (int dd, uint8_t *type, int to)
 
int hci_write_inquiry_scan_type (int dd, uint8_t type, int to)
 
int hci_read_inquiry_mode (int dd, uint8_t *mode, int to)
 
int hci_write_inquiry_mode (int dd, uint8_t mode, int to)
 
int hci_read_afh_mode (int dd, uint8_t *mode, int to)
 
int hci_write_afh_mode (int dd, uint8_t mode, int to)
 
int hci_read_ext_inquiry_response (int dd, uint8_t *fec, uint8_t *data, int to)
 
int hci_write_ext_inquiry_response (int dd, uint8_t fec, uint8_t *data, int to)
 
int hci_read_simple_pairing_mode (int dd, uint8_t *mode, int to)
 
int hci_write_simple_pairing_mode (int dd, uint8_t mode, int to)
 
int hci_read_local_oob_data (int dd, uint8_t *hash, uint8_t *randomizer, int to)
 
int hci_read_inq_response_tx_power_level (int dd, int8_t *level, int to)
 
int hci_read_inquiry_transmit_power_level (int dd, int8_t *level, int to)
 
int hci_write_inquiry_transmit_power_level (int dd, int8_t level, int to)
 
int hci_read_transmit_power_level (int dd, uint16_t handle, uint8_t type, int8_t *level, int to)
 
int hci_read_link_policy (int dd, uint16_t handle, uint16_t *policy, int to)
 
int hci_write_link_policy (int dd, uint16_t handle, uint16_t policy, int to)
 
int hci_read_link_supervision_timeout (int dd, uint16_t handle, uint16_t *timeout, int to)
 
int hci_write_link_supervision_timeout (int dd, uint16_t handle, uint16_t timeout, int to)
 
int hci_set_afh_classification (int dd, uint8_t *map, int to)
 
int hci_read_link_quality (int dd, uint16_t handle, uint8_t *link_quality, int to)
 
int hci_read_rssi (int dd, uint16_t handle, int8_t *rssi, int to)
 
int hci_read_afh_map (int dd, uint16_t handle, uint8_t *mode, uint8_t *map, int to)
 
int hci_read_clock (int dd, uint16_t handle, uint8_t which, uint32_t *clock, uint16_t *accuracy, int to)
 
int hci_le_set_scan_enable (int dd, uint8_t enable, uint8_t filter_dup, int to)
 
int hci_le_set_scan_parameters (int dd, uint8_t type, uint16_t interval, uint16_t window, uint8_t own_type, uint8_t filter, int to)
 
int hci_le_set_advertise_enable (int dd, uint8_t enable, int to)
 
int hci_le_create_conn (int dd, uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length, uint16_t *handle, int to)
 
int hci_le_conn_update (int dd, uint16_t handle, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t supervision_timeout, int to)
 
int hci_le_read_remote_features (int dd, uint16_t handle, uint8_t *features, int to)
 

Variables

static hci_map dev_flags_map []
 
static hci_map pkt_type_map []
 
static hci_map sco_ptype_map []
 
static hci_map link_policy_map []
 
static hci_map link_mode_map []
 
static hci_map commands_map []
 
static hci_map ver_map []
 
static hci_map pal_map []
 
static hci_map lmp_features_map [8][9]
 

Detailed Description

hci functions

Author
Gilbert Brault

Definition in file hci.c.

Macro Definition Documentation

#define MIN (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 59 of file hci.c.

Referenced by hci_send_req().

Function Documentation

static int __other_bdaddr ( int  dd,
int  dev_id,
long  arg 
)
static
Parameters
dd
dev_id
arg
Returns

Definition at line 1075 of file hci.c.

References bacmp(), hci_dev_info::bdaddr, hci_dev_info::dev_id, hci_dev_info::flags, HCI_RAW, hci_test_bit(), and HCIGETDEVINFO.

Referenced by hci_get_route().

static int __same_bdaddr ( int  dd,
int  dev_id,
long  arg 
)
static
Parameters
dd
dev_id
arg
Returns

Definition at line 1095 of file hci.c.

References bacmp(), hci_dev_info::bdaddr, hci_dev_info::dev_id, and HCIGETDEVINFO.

Referenced by hci_devid(), and hci_get_route().

int hci_authenticate_link ( int  dd,
uint16_t  handle,
int  to 
)
static char* hci_bit2str ( hci_map m,
unsigned int  val 
)
static

lookup the numeric code val into the hci_map m and return the matching string

Parameters
mpointer to the hci_map
valcode to match
Returns
string matching the code (val) from the hci_map

Definition at line 74 of file hci.c.

References hci_map::str, and hci_map::val.

Referenced by hci_lmtostr(), hci_lptostr(), hci_ptypetostr(), and hci_scoptypetostr().

char* hci_bustostr ( int  bus)

return a string corresponding to the bus code (see HCI bus types in hci.h)

Parameters
busbus code
Returns
string corresponding to the bus code (NULL if error)

Definition at line 189 of file hci.c.

References HCI_PCCARD, HCI_PCI, HCI_RS232, HCI_SDIO, HCI_UART, HCI_USB, and HCI_VIRTUAL.

Referenced by hci_dtypetostr().

int hci_close_dev ( int  dd)

Close the device

Parameters
ddDevice descriptor returned by hci_open_dev.
Returns
0 if OK or -1 if failure

Definition at line 1326 of file hci.c.

char* hci_cmdtostr ( unsigned int  cmd)

translate a command code into an english sentence

use the commands_map table which is an array of structures { "english sentence", command code }

Parameters
cmdcommand code value
Returns
english sentence corresponding to the command code (NULL if error)

Definition at line 722 of file hci.c.

References hci_uint2str().

char* hci_commandstostr ( uint8_t *  commands,
char *  pref,
int  width 
)

translate a byte array of bit "commands" into a series of corresponding english strings which is returned

Parameters
commandsan array of bytes corresponding to a list of encoded commands
prefprefix to add to str (if pref !=NULL pref will be the first concatenated string)
width
Returns
NULL if error else str which is a string of concatenated commands separated by /0

Definition at line 735 of file hci.c.

References bt_malloc(), commands_map, hci_map::str, and hci_map::val.

int hci_create_connection ( int  dd,
const bdaddr_t *  bdaddr,
uint16_t  ptype,
uint16_t  clkoffset,
uint8_t  rswitch,
uint16_t *  handle,
int  to 
)
int hci_delete_stored_link_key ( int  dd,
bdaddr_t *  bdaddr,
uint8_t  all,
int  to 
)
int hci_devba ( int  dev_id,
bdaddr_t *  bdaddr 
)
Parameters
dev_id
bdaddr
Returns
0 = OK, -1 = Error

Definition at line 1182 of file hci.c.

References bacpy(), hci_dev_info::bdaddr, hci_dev_info::flags, hci_devinfo(), hci_test_bit(), and HCI_UP.

Referenced by hci_devid(), and main().

int hci_devid ( const char *  str)

return the bt device number

Parameters
strstring should be hci<n>
Returns
bt device number (-1 if error)

Definition at line 1130 of file hci.c.

References __same_bdaddr(), hci_devba(), hci_for_each_dev(), HCI_UP, and str2ba().

Referenced by main().

int hci_devinfo ( int  dev_id,
struct hci_dev_info di 
)

get device info given device id

Parameters
dev_iddevice id
didevice info structure if ok
Returns
0 info structure set else error

Definition at line 1155 of file hci.c.

References AF_BLUETOOTH, BTPROTO_HCI, hci_dev_info::dev_id, and HCIGETDEVINFO.

Referenced by hci_devba().

char* hci_dflagstostr ( uint32_t  flags)

return the HCI device flags string given its code

Parameters
flagsHCI device flags code
Returns
HCI device flags string (NULL if error)

Definition at line 260 of file hci.c.

References bt_malloc(), dev_flags_map, hci_test_bit(), HCI_UP, hci_map::str, and hci_map::val.

int hci_disconnect ( int  dd,
uint16_t  handle,
uint8_t  reason,
int  to 
)
char* hci_dtypetostr ( int  type)

return the bus string according to the bus code (type)

Parameters
typebus code
Returns
bus string (NULL if error)

Definition at line 217 of file hci.c.

References hci_bustostr().

int hci_encrypt_link ( int  dd,
uint16_t  handle,
uint8_t  encrypt,
int  to 
)
int hci_exit_park_mode ( int  dd,
uint16_t  handle,
int  to 
)
int hci_for_each_dev ( int  flag,
int(*)(int dd, int dev_id, long arg)  func,
long  arg 
)

return the bt device number

Parameters
flag
func
arg
Returns

Definition at line 1019 of file hci.c.

References AF_BLUETOOTH, BTPROTO_HCI, hci_dev_req::dev_id, hci_dev_list_req::dev_num, hci_dev_req::dev_opt, hci_dev_list_req::dev_req, func, HCI_MAX_DEV, hci_test_bit(), and HCIGETDEVLIST.

Referenced by hci_devid(), and hci_get_route().

int hci_get_route ( bdaddr_t *  bdaddr)
Parameters
bdaddr
Returns

Definition at line 1111 of file hci.c.

References __other_bdaddr(), __same_bdaddr(), BDADDR_ANY, hci_dev_info::dev_id, hci_for_each_dev(), and HCI_UP.

Referenced by hci_inquiry().

int hci_inquiry ( int  dev_id,
int  len,
int  nrsp,
const uint8_t *  lap,
inquiry_info **  ii,
long  flags 
)
int hci_le_add_resolving_list ( int  dd,
const bdaddr_t *  bdaddr,
uint8_t  type,
uint8_t *  peer_irk,
uint8_t *  local_irk,
int  to 
)
int hci_le_add_white_list ( int  dd,
const bdaddr_t *  bdaddr,
uint8_t  type,
int  to 
)
int hci_le_clear_resolving_list ( int  dd,
int  to 
)
Parameters
dd
to
Returns

Definition at line 1843 of file hci.c.

References hci_send_req(), hci_request::ocf, OCF_LE_CLEAR_RESOLV_LIST, hci_request::ogf, OGF_LE_CTL, hci_request::rlen, and hci_request::rparam.

int hci_le_clear_white_list ( int  dd,
int  to 
)
Parameters
dd
to
Returns

Definition at line 1731 of file hci.c.

References hci_send_req(), hci_request::ocf, OCF_LE_CLEAR_WHITE_LIST, hci_request::ogf, OGF_LE_CTL, hci_request::rlen, and hci_request::rparam.

int hci_le_conn_update ( int  dd,
uint16_t  handle,
uint16_t  min_interval,
uint16_t  max_interval,
uint16_t  latency,
uint16_t  supervision_timeout,
int  to 
)
Parameters
dd
handle
min_interval
max_interval
latency
supervision_timeout
to
Returns

Definition at line 3936 of file hci.c.

References hci_request::clen, hci_request::cparam, hci_request::event, EVT_LE_CONN_UPDATE_COMPLETE, hci_send_req(), htobs, LE_CONN_UPDATE_CP_SIZE, hci_request::ocf, OCF_LE_CONN_UPDATE, hci_request::ogf, OGF_LE_CTL, hci_request::rlen, and hci_request::rparam.

int hci_le_create_conn ( int  dd,
uint16_t  interval,
uint16_t  window,
uint8_t  initiator_filter,
uint8_t  peer_bdaddr_type,
bdaddr_t  peer_bdaddr,
uint8_t  own_bdaddr_type,
uint16_t  min_interval,
uint16_t  max_interval,
uint16_t  latency,
uint16_t  supervision_timeout,
uint16_t  min_ce_length,
uint16_t  max_ce_length,
uint16_t *  handle,
int  to 
)
Parameters
dd
interval
window
initiator_filter
peer_bdaddr_type
peer_bdaddr
own_bdaddr_type
min_interval
max_interval
latency
supervision_timeout
min_ce_length
max_ce_length
handle
to
Returns

Definition at line 3875 of file hci.c.

References hci_request::clen, hci_request::cparam, hci_request::event, EVT_CONN_COMPLETE_SIZE, EVT_LE_CONN_COMPLETE, hci_send_req(), LE_CREATE_CONN_CP_SIZE, hci_request::ocf, OCF_LE_CREATE_CONN, hci_request::ogf, OGF_LE_CTL, hci_request::rlen, and hci_request::rparam.

int hci_le_read_remote_features ( int  dd,
uint16_t  handle,
uint8_t *  features,
int  to 
)
int hci_le_read_resolving_list_size ( int  dd,
uint8_t *  size,
int  to 
)
int hci_le_read_white_list_size ( int  dd,
uint8_t *  size,
int  to 
)
int hci_le_rm_resolving_list ( int  dd,
const bdaddr_t *  bdaddr,
uint8_t  type,
int  to 
)
int hci_le_rm_white_list ( int  dd,
const bdaddr_t *  bdaddr,
uint8_t  type,
int  to 
)
int hci_le_set_address_resolution_enable ( int  dd,
uint8_t  enable,
int  to 
)
int hci_le_set_advertise_enable ( int  dd,
uint8_t  enable,
int  to 
)
int hci_le_set_scan_enable ( int  dd,
uint8_t  enable,
uint8_t  filter_dup,
int  to 
)
int hci_le_set_scan_parameters ( int  dd,
uint8_t  type,
uint16_t  interval,
uint16_t  window,
uint8_t  own_type,
uint8_t  filter,
int  to 
)
char* hci_lmtostr ( unsigned int  lm)

return the Link mode mapping string given the code

Parameters
lmLink mode mapping code
Returns
Link mode mapping string (NULL if error)

Definition at line 415 of file hci.c.

References bt_free(), bt_malloc(), hci_bit2str(), and HCI_LM_MASTER.

char* hci_lptostr ( unsigned int  lp)

return the Link policy mapping string given the code

Parameters
lpLink policy mapping code
Returns
Link policy mapping string (NULL if error)

Definition at line 379 of file hci.c.

References hci_bit2str().

int hci_open_dev ( int  dev_id)

Open HCI device.

Parameters
dev_idinteger device address
Returns
device descriptor (dd): a bluetooth socket

Definition at line 1287 of file hci.c.

References AF_BLUETOOTH, BTPROTO_HCI, sockaddr_hci::hci_dev, and sockaddr_hci::hci_family.

int hci_park_mode ( int  dd,
uint16_t  handle,
uint16_t  max_interval,
uint16_t  min_interval,
int  to 
)
char* hci_ptypetostr ( unsigned int  ptype)

return the HCI packet type string given the code

Parameters
ptypeHCI packet type
Returns
HCI packet type string (NULL if error)

Definition at line 323 of file hci.c.

References hci_bit2str().

int hci_read_afh_map ( int  dd,
uint16_t  handle,
uint8_t *  mode,
uint8_t *  map,
int  to 
)
int hci_read_afh_mode ( int  dd,
uint8_t *  mode,
int  to 
)
int hci_read_bd_addr ( int  dd,
bdaddr_t *  bdaddr,
int  to 
)
int hci_read_class_of_dev ( int  dd,
uint8_t *  cls,
int  to 
)
int hci_read_clock ( int  dd,
uint16_t  handle,
uint8_t  which,
uint32_t *  clock,
uint16_t *  accuracy,
int  to 
)
int hci_read_clock_offset ( int  dd,
uint16_t  handle,
uint16_t *  clkoffset,
int  to 
)
int hci_read_current_iac_lap ( int  dd,
uint8_t *  num_iac,
uint8_t *  lap,
int  to 
)
int hci_read_ext_inquiry_response ( int  dd,
uint8_t *  fec,
uint8_t *  data,
int  to 
)
int hci_read_inq_response_tx_power_level ( int  dd,
int8_t *  level,
int  to 
)
int hci_read_inquiry_mode ( int  dd,
uint8_t *  mode,
int  to 
)
int hci_read_inquiry_scan_type ( int  dd,
uint8_t *  type,
int  to 
)
int hci_read_inquiry_transmit_power_level ( int  dd,
int8_t *  level,
int  to 
)
Parameters
dd
level
to
Returns

Definition at line 3322 of file hci.c.

References hci_read_inq_response_tx_power_level().

int hci_read_link_policy ( int  dd,
uint16_t  handle,
uint16_t *  policy,
int  to 
)
int hci_read_link_quality ( int  dd,
uint16_t  handle,
uint8_t *  link_quality,
int  to 
)
int hci_read_link_supervision_timeout ( int  dd,
uint16_t  handle,
uint16_t *  timeout,
int  to 
)
int hci_read_local_commands ( int  dd,
uint8_t *  commands,
int  to 
)
int hci_read_local_ext_features ( int  dd,
uint8_t  page,
uint8_t *  max_page,
uint8_t *  features,
int  to 
)
int hci_read_local_features ( int  dd,
uint8_t *  features,
int  to 
)
int hci_read_local_name ( int  dd,
int  len,
char *  name,
int  to 
)
int hci_read_local_oob_data ( int  dd,
uint8_t *  hash,
uint8_t *  randomizer,
int  to 
)
Parameters
dd
hash
randomizer
to
Returns

Definition at line 3259 of file hci.c.

References hci_send_req(), hci_request::ocf, OCF_READ_LOCAL_OOB_DATA, hci_request::ogf, OGF_HOST_CTL, READ_LOCAL_OOB_DATA_RP_SIZE, hci_request::rlen, and hci_request::rparam.

int hci_read_remote_ext_features ( int  dd,
uint16_t  handle,
uint8_t  page,
uint8_t *  max_page,
uint8_t *  features,
int  to 
)
int hci_read_remote_features ( int  dd,
uint16_t  handle,
uint8_t *  features,
int  to 
)
int hci_read_remote_name ( int  dd,
const bdaddr_t *  bdaddr,
int  len,
char *  name,
int  to 
)
Parameters
dd
bdaddr
len
name
to
Returns

Definition at line 2053 of file hci.c.

References hci_read_remote_name_with_clock_offset().

int hci_read_remote_name_cancel ( int  dd,
const bdaddr_t *  bdaddr,
int  to 
)
int 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 
)
int hci_read_rssi ( int  dd,
uint16_t  handle,
int8_t *  rssi,
int  to 
)
int hci_read_simple_pairing_mode ( int  dd,
uint8_t *  mode,
int  to 
)
int hci_read_stored_link_key ( int  dd,
bdaddr_t *  bdaddr,
uint8_t  all,
int  to 
)
int hci_read_transmit_power_level ( int  dd,
uint16_t  handle,
uint8_t  type,
int8_t *  level,
int  to 
)
int hci_read_voice_setting ( int  dd,
uint16_t *  vs,
int  to 
)
char* hci_scoptypetostr ( unsigned int  ptype)

return the SCO (synchronous connection orientated) links string given the code

Parameters
ptypeSCO type code
Returns
SCO string (NULL if error)

Definition at line 346 of file hci.c.

References hci_bit2str().

int hci_send_cmd ( int  dd,
uint16_t  ogf,
uint16_t  ocf,
uint8_t  plen,
void *  param 
)
Parameters
ddDevice descriptor returned by hci_open_dev.
ogf
ocf
plen
param
Returns

Definition at line 1343 of file hci.c.

References cmd_opcode_pack, HCI_COMMAND_HDR_SIZE, HCI_COMMAND_PKT, htobs, and type.

Referenced by hci_send_req().

int hci_send_req ( int  dd,
struct hci_request r,
int  to 
)
Parameters
dd
r
to
Returns

Definition at line 1381 of file hci.c.

References bacmp(), hci_request::clen, cmd_opcode_pack, hci_request::cparam, hci_request::event, EVT_CMD_COMPLETE, EVT_CMD_COMPLETE_SIZE, EVT_CMD_STATUS, EVT_LE_META_EVENT, EVT_REMOTE_NAME_REQ_COMPLETE, HCI_EVENT_HDR_SIZE, HCI_EVENT_PKT, HCI_FILTER, hci_filter_clear(), hci_filter_set_event(), hci_filter_set_opcode(), hci_filter_set_ptype(), HCI_MAX_EVENT_SIZE, hci_send_cmd(), htobs, MIN, hci_request::ocf, hci_request::ogf, opcode, hci_request::rlen, hci_request::rparam, and SOL_HCI.

Referenced by hci_authenticate_link(), hci_change_link_key(), hci_create_connection(), hci_delete_stored_link_key(), hci_disconnect(), hci_encrypt_link(), hci_exit_park_mode(), hci_le_add_resolving_list(), hci_le_add_white_list(), hci_le_clear_resolving_list(), hci_le_clear_white_list(), hci_le_conn_update(), hci_le_create_conn(), hci_le_read_remote_features(), hci_le_read_resolving_list_size(), hci_le_read_white_list_size(), hci_le_rm_resolving_list(), hci_le_rm_white_list(), hci_le_set_address_resolution_enable(), hci_le_set_advertise_enable(), hci_le_set_scan_enable(), hci_le_set_scan_parameters(), hci_park_mode(), hci_read_afh_map(), hci_read_afh_mode(), hci_read_bd_addr(), hci_read_class_of_dev(), hci_read_clock(), hci_read_clock_offset(), hci_read_current_iac_lap(), hci_read_ext_inquiry_response(), hci_read_inq_response_tx_power_level(), hci_read_inquiry_mode(), hci_read_inquiry_scan_type(), hci_read_link_policy(), hci_read_link_quality(), hci_read_link_supervision_timeout(), hci_read_local_commands(), hci_read_local_ext_features(), hci_read_local_features(), hci_read_local_name(), hci_read_local_oob_data(), hci_read_local_version(), hci_read_remote_ext_features(), hci_read_remote_features(), hci_read_remote_name_cancel(), hci_read_remote_name_with_clock_offset(), hci_read_remote_version(), hci_read_rssi(), hci_read_simple_pairing_mode(), hci_read_stored_link_key(), hci_read_transmit_power_level(), hci_read_voice_setting(), hci_set_afh_classification(), hci_switch_role(), hci_write_afh_mode(), hci_write_class_of_dev(), hci_write_current_iac_lap(), hci_write_ext_inquiry_response(), hci_write_inquiry_mode(), hci_write_inquiry_scan_type(), hci_write_inquiry_transmit_power_level(), hci_write_link_policy(), hci_write_link_supervision_timeout(), hci_write_local_name(), hci_write_simple_pairing_mode(), hci_write_stored_link_key(), and hci_write_voice_setting().

int hci_set_afh_classification ( int  dd,
uint8_t *  map,
int  to 
)
static int hci_str2bit ( hci_map map,
char *  str,
unsigned int *  val 
)
static

ored bits corresponding to comma separated commands matching the hci_map array

Parameters
mappointer to the hci_map array
strcommands, separated by commas for match in the hci_map array
valored bits (from the hci_map) of maching commands
Returns
1 val is set, 0

Definition at line 99 of file hci.c.

Referenced by hci_strtolm(), hci_strtolp(), hci_strtoptype(), and hci_strtoscoptype().

static int hci_str2uint ( hci_map map,
char *  str,
unsigned int *  val 
)
static

lookup a command string in the hci_map array and return the corresponding code

Parameters
mappointer to the hci_map array
strcommand to match
valreturned corresponding code
Returns
1 val is set 0 if no matching string

Definition at line 158 of file hci.c.

References hci_map::str, and hci_map::val.

Referenced by hci_strtover(), lmp_strtover(), and pal_strtover().

int hci_strtolm ( char *  str,
unsigned int *  val 
)

retrun Link mode mapping code given the tring

Parameters
strLink mode mapping string
valLink mode mapping code
Returns
1 match found, 0 error

Definition at line 443 of file hci.c.

References hci_str2bit().

int hci_strtolp ( char *  str,
unsigned int *  val 
)

return Link policy mapping code given the string

Parameters
strLink policy mapping string
valLink policy mapping code
Returns
1 match found 0 error

Definition at line 391 of file hci.c.

References hci_str2bit().

int hci_strtoptype ( char *  str,
unsigned int *  val 
)

return the HCI packet type code given the string

Parameters
strHCI packet type string
valHCI packet type code
Returns
1 if found 0 error

Definition at line 335 of file hci.c.

References hci_str2bit().

int hci_strtoscoptype ( char *  str,
unsigned int *  val 
)

return the SCO (synchronous connection orientated) links code given the string

Parameters
strSCO (synchronous connection orientated) links string
valSCO (synchronous connection orientated) links code
Returns
1 match found 0 error

Definition at line 358 of file hci.c.

References hci_str2bit().

int hci_strtover ( char *  str,
unsigned int *  ver 
)

return the version code given the string

Parameters
strversion string
verversion code
Returns
1 of match found, 0 error

Definition at line 809 of file hci.c.

References hci_str2uint().

int hci_switch_role ( int  dd,
bdaddr_t *  bdaddr,
uint8_t  role,
int  to 
)
char* hci_typetostr ( int  type)

return the bluetooth type string give the code (see HCI controller types in hci.h)

Parameters
typeHCI controller types
Returns
corresponding string (NULL if error)

Definition at line 228 of file hci.c.

References HCI_AMP, and HCI_BREDR.

static char* hci_uint2str ( hci_map m,
unsigned int  val 
)
static

lookup the hci_map and find entry corresponding to val and return the corresponding string

Parameters
mhci_map pointer
valval to match in the hci_map
Returns
string mapped to the matching value or NULL if no matching

Definition at line 130 of file hci.c.

References hci_map::str, and hci_map::val.

Referenced by hci_cmdtostr(), hci_vertostr(), lmp_vertostr(), and pal_vertostr().

char* hci_vertostr ( unsigned int  ver)

translate a version code into a mapping string

Parameters
verversion code
Returns
mapping string (NULL if error)

Definition at line 797 of file hci.c.

References hci_uint2str().

int hci_write_afh_mode ( int  dd,
uint8_t  mode,
int  to 
)
int hci_write_class_of_dev ( int  dd,
uint32_t  cls,
int  to 
)
int hci_write_current_iac_lap ( int  dd,
uint8_t  num_iac,
uint8_t *  lap,
int  to 
)
Parameters
dd
num_iac
lap
to
Returns

Definition at line 2588 of file hci.c.

References hci_request::clen, hci_request::cparam, hci_send_req(), hci_request::ocf, OCF_WRITE_CURRENT_IAC_LAP, hci_request::ogf, and OGF_HOST_CTL.

int hci_write_ext_inquiry_response ( int  dd,
uint8_t  fec,
uint8_t *  data,
int  to 
)
int hci_write_inquiry_mode ( int  dd,
uint8_t  mode,
int  to 
)
int hci_write_inquiry_scan_type ( int  dd,
uint8_t  type,
int  to 
)
int hci_write_inquiry_transmit_power_level ( int  dd,
int8_t  level,
int  to 
)
int hci_write_link_policy ( int  dd,
uint16_t  handle,
uint16_t  policy,
int  to 
)
int hci_write_link_supervision_timeout ( int  dd,
uint16_t  handle,
uint16_t  timeout,
int  to 
)
int hci_write_local_name ( int  dd,
const char *  name,
int  to 
)
int hci_write_simple_pairing_mode ( int  dd,
uint8_t  mode,
int  to 
)
int hci_write_stored_link_key ( int  dd,
bdaddr_t *  bdaddr,
uint8_t *  key,
int  to 
)
int hci_write_voice_setting ( int  dd,
uint16_t  vs,
int  to 
)
char* lmp_featurestostr ( uint8_t *  features,
char *  pref,
int  width 
)

Link Manager Protocol feature string given code

Parameters
featuresLink Manager Protocol feature code
prefprefix
width
Returns
Link Manager Protocol string or NULL if error

Definition at line 962 of file hci.c.

References bt_malloc(), hci_map::str, and hci_map::val.

int lmp_strtover ( char *  str,
unsigned int *  ver 
)

Link Manager Protocol code given the string

Parameters
strversion string
verversion code
Returns
1 of match found, 0 error

Definition at line 832 of file hci.c.

References hci_str2uint().

char* lmp_vertostr ( unsigned int  ver)

Link Manager Protocol version (same as hci) string given the code

Parameters
verversion code
Returns
mapping string (NULL if error)

Definition at line 820 of file hci.c.

References hci_uint2str().

int pal_strtover ( char *  str,
unsigned int *  ver 
)

pal version code given string

Parameters
strpal version string
verpal version code
Returns
1 pal version code is set 0 error

Definition at line 860 of file hci.c.

References hci_str2uint().

char* pal_vertostr ( unsigned int  ver)

pal version string given code

Parameters
verpal version code
Returns
pal version string or NULL if error

Definition at line 848 of file hci.c.

References hci_uint2str().

Variable Documentation

hci_map commands_map[]
static

Definition at line 449 of file hci.c.

Referenced by hci_commandstostr().

hci_map dev_flags_map[]
static
Initial value:
= {
{ "UP", HCI_UP },
{ "INIT", HCI_INIT },
{ "RUNNING", HCI_RUNNING },
{ "RAW", HCI_RAW },
{ "PSCAN", HCI_PSCAN },
{ "ISCAN", HCI_ISCAN },
{ "INQUIRY", HCI_INQUIRY },
{ "AUTH", HCI_AUTH },
{ "ENCRYPT", HCI_ENCRYPT },
{ NULL }
}
Definition: hci.h:65
Definition: hci.h:66
Definition: hci.h:71
Definition: hci.h:70
Definition: hci.h:75
Definition: hci.h:69

Definition at line 241 of file hci.c.

Referenced by hci_dflagstostr().

hci_map link_mode_map[]
static
Initial value:
= {
{ "NONE", 0 },
{ "ACCEPT", HCI_LM_ACCEPT },
{ "MASTER", HCI_LM_MASTER },
{ "AUTH", HCI_LM_AUTH },
{ "ENCRYPT", HCI_LM_ENCRYPT },
{ "TRUSTED", HCI_LM_TRUSTED },
{ "RELIABLE", HCI_LM_RELIABLE },
{ "SECURE", HCI_LM_SECURE },
{ NULL }
}
#define HCI_LM_RELIABLE
Definition: hci.h:295
#define HCI_LM_ACCEPT
Definition: hci.h:290
#define HCI_LM_TRUSTED
Definition: hci.h:294
#define HCI_LM_AUTH
Definition: hci.h:292
#define HCI_LM_SECURE
Definition: hci.h:296
#define HCI_LM_MASTER
Definition: hci.h:291
#define HCI_LM_ENCRYPT
Definition: hci.h:293

Definition at line 397 of file hci.c.

hci_map link_policy_map[]
static
Initial value:
= {
{ "NONE", 0 },
{ "RSWITCH", HCI_LP_RSWITCH },
{ "HOLD", HCI_LP_HOLD },
{ "SNIFF", HCI_LP_SNIFF },
{ "PARK", HCI_LP_PARK },
{ NULL }
}
#define HCI_LP_SNIFF
Definition: hci.h:286
#define HCI_LP_HOLD
Definition: hci.h:285
#define HCI_LP_PARK
Definition: hci.h:287
#define HCI_LP_RSWITCH
Definition: hci.h:284

Definition at line 364 of file hci.c.

hci_map lmp_features_map[8][9]
static

Definition at line 866 of file hci.c.

hci_map pal_map[]
static
Initial value:
= {
{ "3.0", 0x01 },
{ NULL }
}

Definition at line 837 of file hci.c.

hci_map pkt_type_map[]
static
Initial value:
= {
{ "DM1", HCI_DM1 },
{ "DM3", HCI_DM3 },
{ "DM5", HCI_DM5 },
{ "DH1", HCI_DH1 },
{ "DH3", HCI_DH3 },
{ "DH5", HCI_DH5 },
{ "HV1", HCI_HV1 },
{ "HV2", HCI_HV2 },
{ "HV3", HCI_HV3 },
{ "2-DH1", HCI_2DH1 },
{ "2-DH3", HCI_2DH3 },
{ "2-DH5", HCI_2DH5 },
{ "3-DH1", HCI_3DH1 },
{ "3-DH3", HCI_3DH3 },
{ "3-DH5", HCI_3DH5 },
{ NULL }
}
#define HCI_DM5
Definition: hci.h:131
#define HCI_2DH5
Definition: hci.h:129
#define HCI_DH1
Definition: hci.h:124
#define HCI_HV3
Definition: hci.h:136
#define HCI_DM3
Definition: hci.h:127
#define HCI_3DH1
Definition: hci.h:122
#define HCI_DH3
Definition: hci.h:128
#define HCI_3DH3
Definition: hci.h:126
#define HCI_2DH3
Definition: hci.h:125
#define HCI_HV1
Definition: hci.h:134
#define HCI_2DH1
Definition: hci.h:121
#define HCI_HV2
Definition: hci.h:135
#define HCI_DH5
Definition: hci.h:132
#define HCI_DM1
Definition: hci.h:123
#define HCI_3DH5
Definition: hci.h:130

Definition at line 283 of file hci.c.

hci_map sco_ptype_map[]
static
Initial value:
= {
{ "HV1", 0x0001 },
{ "HV2", 0x0002 },
{ "HV3", 0x0004 },
{ "EV3", HCI_EV3 },
{ "EV4", HCI_EV4 },
{ "EV5", HCI_EV5 },
{ "2-EV3", HCI_2EV3 },
{ "2-EV5", HCI_2EV5 },
{ "3-EV3", HCI_3EV3 },
{ "3-EV5", HCI_3EV5 },
{ NULL }
}
#define HCI_3EV5
Definition: hci.h:144
#define HCI_EV5
Definition: hci.h:140
#define HCI_2EV3
Definition: hci.h:141
#define HCI_3EV3
Definition: hci.h:142
#define HCI_EV4
Definition: hci.h:139
#define HCI_2EV5
Definition: hci.h:143
#define HCI_EV3
Definition: hci.h:138

Definition at line 303 of file hci.c.

hci_map ver_map[]
static
Initial value:
= {
{ "1.0b", 0x00 },
{ "1.1", 0x01 },
{ "1.2", 0x02 },
{ "2.0", 0x03 },
{ "2.1", 0x04 },
{ "3.0", 0x05 },
{ "4.0", 0x06 },
{ "4.1", 0x07 },
{ "4.2", 0x08 },
{ NULL }
}

Definition at line 778 of file hci.c.