diff options
| author | Max Krasnyansky <maxk@qualcomm.com> | 2002-03-21 23:20:32 +0000 | 
|---|---|---|
| committer | Max Krasnyansky <maxk@qualcomm.com> | 2002-03-21 23:20:32 +0000 | 
| commit | a51747b602f9cd03c7431788f80431c1710f5827 (patch) | |
| tree | 3d83daef2523d2cc087ebb8da1240e05e56bd6a9 | |
| parent | e5049f81cd29f935a2465c430f5db8f15765d46d (diff) | |
Additional strtoXX and XXtostr functions.
| -rw-r--r-- | include/bluetooth.h | 3 | ||||
| -rw-r--r-- | include/hci_lib.h | 5 | ||||
| -rw-r--r-- | src/bluetooth.c | 216 | ||||
| -rw-r--r-- | src/hci.c | 82 | 
4 files changed, 234 insertions, 72 deletions
diff --git a/include/bluetooth.h b/include/bluetooth.h index 5dd4085f..ee345616 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -103,7 +103,8 @@ char     *batostr(bdaddr_t *ba);  int  ba2str(bdaddr_t *ba, char *str);  int  str2ba(char *str, bdaddr_t *ba); -int  bterr(uint16_t code); +int  bt_error(uint16_t code); +char *bt_compidtostr(int id);  #ifdef __cplusplus  } diff --git a/include/hci_lib.h b/include/hci_lib.h index 28a32993..c590150d 100644 --- a/include/hci_lib.h +++ b/include/hci_lib.h @@ -77,6 +77,11 @@ int   hci_strtolp(char *str, unsigned int *val);  char *hci_lmtostr(unsigned int ptype);  int   hci_strtolm(char *str, unsigned int *val); +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); +  static inline void hci_set_bit(int nr, void *addr)  {          *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31)); diff --git a/src/bluetooth.c b/src/bluetooth.c index 6dfccf44..b202f280 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -96,69 +96,159 @@ int str2ba(char *str, bdaddr_t *ba)  }  /* Bluetooth error codes to Unix errno mapping */ -int bterr(uint16_t code) +int bt_error(uint16_t code)  { -	switch(code) { -		case 0: -			return 0; -		case 0x01: -			return EBADRQC; -		case 0x02: -			return ENOTCONN; -		case 0x03: -			return EIO; -		case 0x04: -			return EHOSTDOWN; -		case 0x05: -			return EACCES; -		case 0x06: -			return EINVAL; -		case 0x07: -			return ENOMEM; -		case 0x08: -			return ETIMEDOUT; -		case 0x09: -			return EMLINK; -		case 0x0a: -			return EMLINK; -		case 0x0b: -			return EALREADY; -		case 0x0c: -			return EBUSY; -		case 0x0d: -		case 0x0e: -		case 0x0f: -			return ECONNREFUSED; -		case 0x10: -			return ETIMEDOUT; -		case 0x11: -		case 0x27: -		case 0x29: -		case 0x20: -			return EOPNOTSUPP; -		case 0x12: -			return EINVAL; -		case 0x13: -		case 0x14: -		case 0x15: -			return ECONNRESET; -		case 0x16: -			return ECONNABORTED; -		case 0x17: -			return ELOOP; -		case 0x18: -			return EACCES; -		case 0x1a: -			return EPROTONOSUPPORT; -		case 0x1b: -			return ECONNREFUSED; -		case 0x19: -		case 0x1e: -		case 0x23: -		case 0x24: -		case 0x25: -			return EPROTO; -		default: -			return ENOSYS; +	switch (code) { +	case 0: +		return 0; +	case 0x01: +		return EBADRQC; +	case 0x02: +		return ENOTCONN; +	case 0x03: +		return EIO; +	case 0x04: +		return EHOSTDOWN; +	case 0x05: +		return EACCES; +	case 0x06: +		return EINVAL; +	case 0x07: +		return ENOMEM; +	case 0x08: +		return ETIMEDOUT; +	case 0x09: +		return EMLINK; +	case 0x0a: +		return EMLINK; +	case 0x0b: +		return EALREADY; +	case 0x0c: +		return EBUSY; +	case 0x0d: +	case 0x0e: +	case 0x0f: +		return ECONNREFUSED; +	case 0x10: +		return ETIMEDOUT; +	case 0x11: +	case 0x27: +	case 0x29: +	case 0x20: +		return EOPNOTSUPP; +	case 0x12: +		return EINVAL; +	case 0x13: +	case 0x14: +	case 0x15: +		return ECONNRESET; +	case 0x16: +		return ECONNABORTED; +	case 0x17: +		return ELOOP; +	case 0x18: +		return EACCES; +	case 0x1a: +		return EPROTONOSUPPORT; +	case 0x1b: +		return ECONNREFUSED; +	case 0x19: +	case 0x1e: +	case 0x23: +	case 0x24: +	case 0x25: +		return EPROTO; +	default: +		return ENOSYS; +	} +} + +char *bt_compidtostr(int compid) +{ +	switch (compid) { +	case 0: +		return "Ericsson Mobile Comunications"; +	case 1: +		return "Nokia Mobile Phones"; +	case 2: +		return "Intel Corp."; +	case 3: +		return "IBM Corp."; +	case 4: +		return "Toshiba Corp."; +	case 5: +		return "3Com"; +	case 6: +		return "Microsoft"; +	case 7: +		return "Lucent"; +	case 8: +		return "Motorola"; +	case 9: +		return "Infineon Technologies AG"; +	case 10: +		return "Cambridge Silicon Radio"; +	case 11: +		return "Silicon Wave"; +	case 12: +		return "Digianswer A/S"; +	case 13: +		return "Texas Instruments Inc."; +	case 14: +		return "Parthus Technologies Inc."; +	case 15: +		return "Broadcom Corporation"; +	case 16: +		return "Mitel Semiconductor"; +	case 17: +		return "Widcomm, Inc."; +	case 18: +		return "Telencomm Inc."; +	case 19: +		return "Atmel Corporation"; +	case 20: +		return "Mitsubishi Electric Corporation"; +	case 21: +		return "RTX Telecom A/S"; +	case 22: +		return "KC Technology Inc."; +	case 23: +		return "Newlogic"; +	case 24: +		return "Transilica, Inc."; +	case 25: +		return "Rohde & Schwartz GmbH & Co. KG"; +	case 26: +		return "TTPCom Limited"; +	case 27: +		return "Signia Technologies, Inc."; +	case 28: +		return "Conexant Systems Inc."; +	case 29: +		return "Qualcomm"; +	case 30: +		return "Inventel"; +	case 31: +		return "AVM Berlin"; +	case 32: +		return "BandSpeed, Inc."; +	case 33: +		return "Mansella Ltd"; +	case 34: +		return "NEC Corporation"; +	case 35: +		return "WavePlus Technology Co., Ltd."; +	case 36: +		return "Alcatel"; +	case 37: +		return "Philips Semiconductors"; +	case 38: +		return "C Technologies"; +	case 39: +		return "Open Interface"; +	case 65535: +		return "internal use"; +	default: +		return "not assigned";  	}  } @@ -51,7 +51,7 @@ typedef struct {  	char  *str; unsigned int val;  } hci_map; -static char * hci_uint2str(hci_map *m, unsigned int val)  +static char *hci_bit2str(hci_map *m, unsigned int val)   {  	static char str[50];  	char *ptr = str; @@ -65,7 +65,7 @@ static char * hci_uint2str(hci_map *m, unsigned int val)  	return str;  } -int hci_str2uint(hci_map *map, char *str, unsigned int *val) +static int hci_str2bit(hci_map *map, char *str, unsigned int *val)  {  	char *t, *ptr;  	hci_map *m; @@ -90,6 +90,46 @@ int hci_str2uint(hci_map *map, char *str, unsigned int *val)  	return set;  } +static char *hci_uint2str(hci_map *m, unsigned int val)  +{ +	static char str[50]; +	char *ptr = str; + +	*ptr = 0; +	while (m->str) { +		if ((unsigned int) m->val == val) { +			ptr += sprintf(ptr, "%s", m->str); +			break; +		} +		m++; +	} 	 +	return str; +} + +static int hci_str2uint(hci_map *map, char *str, unsigned int *val) +{ +	char *t, *ptr; +	hci_map *m; +	int set = 0; + +	if (!str) +		return 0; + +	str = ptr = strdup(str); + +	while ((t=strsep(&ptr, ","))) { +		for (m=map; m->str; m++) { +			if (!strcasecmp(m->str,t)) { +				*val = (unsigned int) m->val; set = 1; +				break; +			} +		} +	} 	 +	free(str); + +	return set; +} +  char *hci_dtypetostr(int type)  {  	switch (type) { @@ -153,11 +193,11 @@ hci_map pkt_type_map[] = {  };  char *hci_ptypetostr(unsigned int ptype)  { -	return hci_uint2str(pkt_type_map, ptype); +	return hci_bit2str(pkt_type_map, ptype);  }  int hci_strtoptype(char *str, unsigned int *val)  { -	return hci_str2uint(pkt_type_map, str, val); +	return hci_str2bit(pkt_type_map, str, val);  }  /* Link policy mapping */ @@ -171,11 +211,11 @@ hci_map link_policy_map[] = {  };  char *hci_lptostr(unsigned int lp)  { -	return hci_uint2str(link_policy_map, lp); +	return hci_bit2str(link_policy_map, lp);  }  int hci_strtolp(char *str, unsigned int *val)  { -	return hci_str2uint(link_policy_map, str, val); +	return hci_str2bit(link_policy_map, str, val);  }  /* Link mode mapping */ @@ -196,12 +236,38 @@ char *hci_lmtostr(unsigned int lm)  	if (!(lm & HCI_LM_MASTER))  		strcpy(str, "SLAVE "); -	strcat(str, hci_uint2str(link_mode_map, lm)); +	strcat(str, hci_bit2str(link_mode_map, lm));  	return str;  }  int hci_strtolm(char *str, unsigned int *val)  { -	return hci_str2uint(link_mode_map, str, val); +	return hci_str2bit(link_mode_map, str, val); +} + +/* Version mapping */ +hci_map ver_map[] = { +	{ "1.0b",    0x00 }, +	{ "1.1",     0x01 }, +	{ NULL } +}; +char *hci_vertostr(unsigned int ver) +{ +	char *str = hci_uint2str(ver_map, ver); +	return *str ? str : "n/a"; +} +int hci_strtover(char *str, unsigned int *ver) +{ +	return hci_str2uint(ver_map, str, ver); +} + +char *lmp_vertostr(unsigned int ver) +{ +	char *str = hci_uint2str(ver_map, ver); +	return *str ? str : "n/a"; +} +int lmp_strtover(char *str, unsigned int *ver) +{ +	return hci_str2uint(ver_map, str, ver);  }  /* HCI functions that do not require open device */  | 
