diff options
| -rw-r--r-- | include/bluetooth.h | 14 | ||||
| -rw-r--r-- | include/hci.h | 2 | ||||
| -rw-r--r-- | include/hci_lib.h | 14 | ||||
| -rw-r--r-- | src/bluetooth.c | 18 | ||||
| -rw-r--r-- | src/hci.c | 39 | 
5 files changed, 58 insertions, 29 deletions
| diff --git a/include/bluetooth.h b/include/bluetooth.h index b93c4e35..93a6f628 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -91,20 +91,20 @@ typedef struct {  #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})  /* Copy, swap, convert BD Address */ -static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) +static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)  {  	return memcmp(ba1, ba2, sizeof(bdaddr_t));  } -static inline void bacpy(bdaddr_t *dst, bdaddr_t *src) +static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)  {  	memcpy(dst, src, sizeof(bdaddr_t));  } -void baswap(bdaddr_t *dst, bdaddr_t *src); -bdaddr_t *strtoba(char *str); -char     *batostr(bdaddr_t *ba); -int  ba2str(bdaddr_t *ba, char *str); -int  str2ba(char *str, bdaddr_t *ba); +void baswap(bdaddr_t *dst, const bdaddr_t *src); +bdaddr_t *strtoba(const char *str); +char     *batostr(const bdaddr_t *ba); +int  ba2str(const bdaddr_t *ba, char *str); +int  str2ba(const char *str, bdaddr_t *ba);  int  bt_error(uint16_t code);  char *bt_compidtostr(int id); diff --git a/include/hci.h b/include/hci.h index 8168a492..212db12b 100644 --- a/include/hci.h +++ b/include/hci.h @@ -823,7 +823,7 @@ typedef struct {  	uint16_t	event;  	uint16_t	proto;  	uint16_t	subproto; -	uint8_t 	incomming; +	uint8_t 	incoming;  } __attribute__ ((packed)) evt_si_security;  #define EVT_TESTING	0xfe diff --git a/include/hci_lib.h b/include/hci_lib.h index 81d29ecf..d6d76214 100644 --- a/include/hci_lib.h +++ b/include/hci_lib.h @@ -56,20 +56,20 @@ 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 *req, int timeout); -int hci_create_connection(int dd, bdaddr_t *ba, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to); +int hci_create_connection(int dd, const bdaddr_t *ba, 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_inquiry(int dev_id, int len, int num_rsp, uint8_t *lap, inquiry_info **ii, long flags); +int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags);  int hci_devinfo(int dev_id, struct hci_dev_info *di);  int hci_devba(int dev_id, bdaddr_t *ba); -int hci_devid(char *str); +int hci_devid(const char *str);  // deprecated: preserve compatibility  int hci_local_name(int dd, int len, char *name, int to);  int hci_read_local_name(int dd, int len, char *name, int to); -int hci_write_local_name(int dd, char *name, int to); -int hci_remote_name(int dd, bdaddr_t *ba, int len, char *name, int to); -int hci_read_remote_name(int dd, bdaddr_t *ba, int len, char *name, int to); +int hci_write_local_name(int dd, const char *name, int to); +int hci_remote_name(int dd, const bdaddr_t *ba, int len, char *name, int to); +int hci_read_remote_name(int dd, const bdaddr_t *ba, int len, char *name, int to);  int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to);  int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver, int to);  int hci_read_local_version(int dd, struct hci_version *ver, int to); @@ -79,6 +79,8 @@ 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_authenticate_link(int dd, uint16_t handle, int to); +int hci_encrypt_link(int dd, uint16_t handle, int on, int to);  int hci_for_each_dev(int flag, int(*func)(int s, int dev_id, long arg), long arg);  int hci_get_route(bdaddr_t *bdaddr); diff --git a/src/bluetooth.c b/src/bluetooth.c index 4548b121..bc0eb238 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -35,16 +35,16 @@  #include <bluetooth.h>  #include <hci.h> -void baswap(bdaddr_t *dst, bdaddr_t *src) +void baswap(bdaddr_t *dst, const bdaddr_t *src)  { -	register unsigned char * d = (unsigned char *)dst; -	register unsigned char * s = (unsigned char *)src; +	register unsigned char *d = (unsigned char *)dst; +	register const unsigned char *s = (const unsigned char *)src;  	register int i;  	for(i=0; i<6; i++)  		d[i] = s[5-i];  } -char *batostr(bdaddr_t *ba) +char *batostr(const bdaddr_t *ba)  {  	char *str = malloc(18);  	if (!str) @@ -56,9 +56,9 @@ char *batostr(bdaddr_t *ba)  	return str;  } -bdaddr_t *strtoba(char *str) +bdaddr_t *strtoba(const char *str)  { -	char *ptr = str; +	const char *ptr = str;  	int i;  	uint8_t *ba = malloc(sizeof(bdaddr_t)); @@ -74,7 +74,7 @@ bdaddr_t *strtoba(char *str)  	return (bdaddr_t *) ba;  } -int ba2str(bdaddr_t *ba, char *str) +int ba2str(const bdaddr_t *ba, char *str)  {  	uint8_t b[6]; @@ -83,10 +83,10 @@ int ba2str(bdaddr_t *ba, char *str)  	        b[0], b[1], b[2], b[3], b[4], b[5]);  } -int str2ba(char *str, bdaddr_t *ba) +int str2ba(const char *str, bdaddr_t *ba)  {  	uint8_t b[6]; -	char *ptr = str; +	const char *ptr = str;  	int i;  	for (i=0; i < 6; i++) { @@ -419,7 +419,7 @@ int hci_get_route(bdaddr_t *bdaddr)  		return hci_for_each_dev(HCI_UP, NULL, 0);  } -int hci_devid(char *str) +int hci_devid(const char *str)  {  	bdaddr_t ba;  	int id = -1; @@ -467,7 +467,7 @@ int hci_devba(int dev_id, bdaddr_t *ba)  	return 0;  } -int hci_inquiry(int dev_id, int len, int nrsp, uint8_t *lap, inquiry_info **ii, long flags) +int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap, inquiry_info **ii, long flags)  {  	struct hci_inquiry_req *ir;  	void *buf; @@ -697,7 +697,7 @@ done:  	return 0;  } -int hci_create_connection(int dd, bdaddr_t *ba, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to) +int hci_create_connection(int dd, const bdaddr_t *ba, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to)  {          evt_conn_complete rp;          create_conn_cp cp; @@ -788,7 +788,7 @@ int hci_read_local_name(int dd, int len, char *name, int to)  	return 0;  } -int hci_write_local_name(int dd, char *name, int to) +int hci_write_local_name(int dd, const char *name, int to)  {  	change_local_name_cp cp;  	struct hci_request rq; @@ -805,12 +805,12 @@ int hci_write_local_name(int dd, char *name, int to)  	return 0;  } -int hci_remote_name(int dd, bdaddr_t *ba, int len, char *name, int to) +int hci_remote_name(int dd, const bdaddr_t *ba, int len, char *name, int to)  {  	return hci_read_remote_name(dd, ba, len, name, to);  } -int hci_read_remote_name(int dd, bdaddr_t *ba, int len, char *name, int to) +int hci_read_remote_name(int dd, const bdaddr_t *ba, int len, char *name, int to)  {  	evt_remote_name_req_complete rn;  	remote_name_req_cp cp; @@ -1047,3 +1047,30 @@ int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to)  	rq.clen = WRITE_CURRENT_IAC_LAP_CP_SIZE;  	return hci_send_req(dd, &rq, to);  } + +int hci_authenticate_link(int dd, uint16_t handle, int to) +{ +	auth_requested_cp cp; +	struct hci_request rq; + +	cp.handle = handle; +	rq.ogf = OGF_LINK_CTL; +	rq.ocf = OCF_AUTH_REQUESTED; +	rq.cparam = &cp; +	rq.clen = AUTH_REQUESTED_CP_SIZE; +	return hci_send_req(dd, &rq, to); +} + +int hci_encrypt_link(int dd, uint16_t handle, int on, int to) +{ +	set_conn_encrypt_cp cp; +	struct hci_request rq; + +	cp.handle = handle; +	cp.encrypt = on; +	rq.ogf = OGF_LINK_CTL; +	rq.ocf = OCF_SET_CONN_ENCRYPT; +	rq.cparam = &cp; +	rq.clen = SET_CONN_ENCRYPT_CP_SIZE; +	return hci_send_req(dd, &rq, to); +} | 
