├── README.md ├── ble_socket ├── Debug │ ├── makefile │ ├── objects.mk │ ├── sources.mk │ └── src │ │ └── subdir.mk ├── include │ ├── a2mp.h │ ├── amp.h │ ├── ble.h │ ├── bluetooth.h │ ├── bluez.pc.in │ ├── bnep.h │ ├── cmtp.h │ ├── hci.h │ ├── hci_lib.h │ ├── hidp.h │ ├── l2cap.h │ ├── mgmt.h │ ├── rfcomm.h │ ├── sco.h │ ├── sdp.h │ ├── sdp_lib.h │ └── uuid.h └── src │ ├── ble.c │ ├── bluetooth.c │ ├── hci.c │ ├── main.c │ ├── sdp.c │ └── uuid.c └── start_bluetooth /README.md: -------------------------------------------------------------------------------- 1 | # bluezTest Linux下的Bluez的应用 2 | 3 | bluez是linux官方蓝牙协议栈。 4 | 5 | - 组成 6 | - bluez分为两个部分:内核代码和用户态程序及工具集 7 | - 内核代码:bluez核心协议和驱动程序等模块组成 8 | - 用户态程序及工具集:应用程序接口和bluez工具集 9 | 10 | ## 编译bluez-5.49 11 | 需要先编译安装以下包: 12 | - bluez-libs 13 | - expat 14 | - dbus 15 | - glib 16 | - bluez-utils 17 | - libusb 18 | 19 | 在这里就不写了,网上教程很多。交叉编译后,把生成的/bin /sbin /lib下的so放到板子的lib目录。 20 | 21 | ## 测试 22 | - hciconfig hci0 up 启用蓝牙 23 | - hciconfig hci0 iscan配置开发板蓝牙可被查找 24 | - hcitool scan 查找蓝牙 25 | - Scanning ... 26 | - 04:02:1F:A2:B2:AF xxx 27 | - 00:13:EF:A0:00:AF xxx 28 | 29 | ## 应用编程 30 | 其实在linux上的bluetooth应用开发,都是基于内核提供了核心驱动和模块,我们移植bluez协议栈只是为了得到一些工具和API来驱动蓝牙设备而已。 31 | 32 | 当然了,在应用编程之前要先启动蓝牙服务,这个可以写个脚本来自动化方便开启,停止等动作的。后面会整理下,共享出来。 33 | 34 | 本项目基于bluez协议与epoll模型实现设备的蓝牙连接与数据交互功能。 35 | ___________________________________- 36 | #### 更新 37 | 1.增加蓝牙启动脚本 38 | -------------------------------------------------------------------------------- /ble_socket/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include src/subdir.mk 12 | -include subdir.mk 13 | -include objects.mk 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | ifneq ($(strip $(C_DEPS)),) 17 | -include $(C_DEPS) 18 | endif 19 | endif 20 | 21 | -include ../makefile.defs 22 | 23 | # Add inputs and outputs from these tool invocations to the build variables 24 | 25 | # All Target 26 | all: ble_socket 27 | 28 | # Tool invocations 29 | ble_socket: $(OBJS) $(USER_OBJS) 30 | @echo 'Building target: $@' 31 | @echo 'Invoking: Cross GCC Linker' 32 | arm-linux-gnueabihf-gcc -o "ble_socket" $(OBJS) $(USER_OBJS) $(LIBS) 33 | @echo 'Finished building target: $@' 34 | @echo ' ' 35 | 36 | # Other Targets 37 | clean: 38 | -$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) ble_socket 39 | -@echo ' ' 40 | 41 | .PHONY: all clean dependents 42 | 43 | -include ../makefile.targets 44 | -------------------------------------------------------------------------------- /ble_socket/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := 8 | 9 | -------------------------------------------------------------------------------- /ble_socket/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | OBJ_SRCS := 6 | ASM_SRCS := 7 | C_SRCS := 8 | O_SRCS := 9 | S_UPPER_SRCS := 10 | EXECUTABLES := 11 | OBJS := 12 | C_DEPS := 13 | 14 | # Every subdirectory with source files must be described here 15 | SUBDIRS := \ 16 | src \ 17 | 18 | -------------------------------------------------------------------------------- /ble_socket/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | C_SRCS += \ 7 | ../src/ble.c \ 8 | ../src/bluetooth.c \ 9 | ../src/hci.c \ 10 | ../src/main.c \ 11 | ../src/sdp.c \ 12 | ../src/uuid.c 13 | 14 | OBJS += \ 15 | ./src/ble.o \ 16 | ./src/bluetooth.o \ 17 | ./src/hci.o \ 18 | ./src/main.o \ 19 | ./src/sdp.o \ 20 | ./src/uuid.o 21 | 22 | C_DEPS += \ 23 | ./src/ble.d \ 24 | ./src/bluetooth.d \ 25 | ./src/hci.d \ 26 | ./src/main.d \ 27 | ./src/sdp.d \ 28 | ./src/uuid.d 29 | 30 | 31 | # Each subdirectory must supply rules for building sources it contributes 32 | src/%.o: ../src/%.c 33 | @echo 'Building file: $<' 34 | @echo 'Invoking: Cross GCC Compiler' 35 | arm-linux-gnueabihf-gcc -I/home/liangjf/eclipse-workspace/ble_socket/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" 36 | @echo 'Finished building: $<' 37 | @echo ' ' 38 | 39 | 40 | -------------------------------------------------------------------------------- /ble_socket/include/a2mp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2012 Intel Corporation. All rights reserved. 6 | * Copyright (c) 2012 Code Aurora Forum. All rights reserved. 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __A2MP_H 25 | #define __A2MP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* A2MP Protocol */ 32 | 33 | /* A2MP command codes */ 34 | 35 | #define A2MP_COMMAND_REJ 0x01 36 | #define A2MP_DISCOVER_REQ 0x02 37 | #define A2MP_DISCOVER_RSP 0x03 38 | #define A2MP_CHANGE_NOTIFY 0x04 39 | #define A2MP_CHANGE_RSP 0x05 40 | #define A2MP_INFO_REQ 0x06 41 | #define A2MP_INFO_RSP 0x07 42 | #define A2MP_ASSOC_REQ 0x08 43 | #define A2MP_ASSOC_RSP 0x09 44 | #define A2MP_CREATE_REQ 0x0a 45 | #define A2MP_CREATE_RSP 0x0b 46 | #define A2MP_DISCONN_REQ 0x0c 47 | #define A2MP_DISCONN_RSP 0x0d 48 | 49 | struct a2mp_hdr { 50 | uint8_t code; 51 | uint8_t ident; 52 | uint16_t len; 53 | } __attribute__ ((packed)); 54 | #define A2MP_HDR_SIZE 4 55 | 56 | struct a2mp_command_rej { 57 | uint16_t reason; 58 | } __attribute__ ((packed)); 59 | 60 | struct a2mp_discover_req { 61 | uint16_t mtu; 62 | uint16_t mask; 63 | } __attribute__ ((packed)); 64 | 65 | struct a2mp_ctrl { 66 | uint8_t id; 67 | uint8_t type; 68 | uint8_t status; 69 | } __attribute__ ((packed)); 70 | 71 | struct a2mp_discover_rsp { 72 | uint16_t mtu; 73 | uint16_t mask; 74 | struct a2mp_ctrl ctrl_list[0]; 75 | } __attribute__ ((packed)); 76 | 77 | struct a2mp_info_req { 78 | uint8_t id; 79 | } __attribute__ ((packed)); 80 | 81 | struct a2mp_info_rsp { 82 | uint8_t id; 83 | uint8_t status; 84 | uint32_t total_bw; 85 | uint32_t max_bw; 86 | uint32_t min_latency; 87 | uint16_t pal_caps; 88 | uint16_t assoc_size; 89 | } __attribute__ ((packed)); 90 | 91 | struct a2mp_assoc_req { 92 | uint8_t id; 93 | } __attribute__ ((packed)); 94 | 95 | struct a2mp_assoc_rsp { 96 | uint8_t id; 97 | uint8_t status; 98 | uint8_t assoc_data[0]; 99 | } __attribute__ ((packed)); 100 | 101 | struct a2mp_create_req { 102 | uint8_t local_id; 103 | uint8_t remote_id; 104 | uint8_t assoc_data[0]; 105 | } __attribute__ ((packed)); 106 | 107 | struct a2mp_create_rsp { 108 | uint8_t local_id; 109 | uint8_t remote_id; 110 | uint8_t status; 111 | } __attribute__ ((packed)); 112 | 113 | struct a2mp_disconn_req { 114 | uint8_t local_id; 115 | uint8_t remote_id; 116 | } __attribute__ ((packed)); 117 | 118 | struct a2mp_disconn_rsp { 119 | uint8_t local_id; 120 | uint8_t remote_id; 121 | uint8_t status; 122 | } __attribute__ ((packed)); 123 | 124 | #define A2MP_COMMAND_NOT_RECOGNIZED 0x0000 125 | 126 | /* AMP controller status */ 127 | #define AMP_CTRL_POWERED_DOWN 0x00 128 | #define AMP_CTRL_BLUETOOTH_ONLY 0x01 129 | #define AMP_CTRL_NO_CAPACITY 0x02 130 | #define AMP_CTRL_LOW_CAPACITY 0x03 131 | #define AMP_CTRL_MEDIUM_CAPACITY 0x04 132 | #define AMP_CTRL_HIGH_CAPACITY 0x05 133 | #define AMP_CTRL_FULL_CAPACITY 0x06 134 | 135 | /* A2MP response status */ 136 | #define A2MP_STATUS_SUCCESS 0x00 137 | #define A2MP_STATUS_INVALID_CTRL_ID 0x01 138 | #define A2MP_STATUS_UNABLE_START_LINK_CREATION 0x02 139 | #define A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02 140 | #define A2MP_STATUS_COLLISION_OCCURED 0x03 141 | #define A2MP_STATUS_DISCONN_REQ_RECVD 0x04 142 | #define A2MP_STATUS_PHYS_LINK_EXISTS 0x05 143 | #define A2MP_STATUS_SECURITY_VIOLATION 0x06 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* __A2MP_H */ 150 | -------------------------------------------------------------------------------- /ble_socket/include/amp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2010-2011 Code Aurora Forum. All rights reserved. 6 | * Copyright (C) 2012 Intel Corporation. 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License version 2 and 10 | * only version 2 as published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | */ 18 | 19 | #ifndef __AMP_H 20 | #define __AMP_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #define AMP_MGR_CID 0x03 27 | 28 | /* AMP manager codes */ 29 | #define AMP_COMMAND_REJ 0x01 30 | #define AMP_DISCOVER_REQ 0x02 31 | #define AMP_DISCOVER_RSP 0x03 32 | #define AMP_CHANGE_NOTIFY 0x04 33 | #define AMP_CHANGE_RSP 0x05 34 | #define AMP_INFO_REQ 0x06 35 | #define AMP_INFO_RSP 0x07 36 | #define AMP_ASSOC_REQ 0x08 37 | #define AMP_ASSOC_RSP 0x09 38 | #define AMP_LINK_REQ 0x0a 39 | #define AMP_LINK_RSP 0x0b 40 | #define AMP_DISCONN_REQ 0x0c 41 | #define AMP_DISCONN_RSP 0x0d 42 | 43 | typedef struct { 44 | uint8_t code; 45 | uint8_t ident; 46 | uint16_t len; 47 | } __attribute__ ((packed)) amp_mgr_hdr; 48 | #define AMP_MGR_HDR_SIZE 4 49 | 50 | /* AMP ASSOC structure */ 51 | typedef struct { 52 | uint8_t type_id; 53 | uint16_t len; 54 | uint8_t data[0]; 55 | } __attribute__ ((packed)) amp_assoc_tlv; 56 | 57 | typedef struct { 58 | uint16_t reason; 59 | } __attribute__ ((packed)) amp_cmd_rej_parms; 60 | 61 | typedef struct { 62 | uint16_t mtu; 63 | uint16_t mask; 64 | } __attribute__ ((packed)) amp_discover_req_parms; 65 | 66 | typedef struct { 67 | uint16_t mtu; 68 | uint16_t mask; 69 | uint8_t controller_list[0]; 70 | } __attribute__ ((packed)) amp_discover_rsp_parms; 71 | 72 | typedef struct { 73 | uint8_t id; 74 | } __attribute__ ((packed)) amp_info_req_parms; 75 | 76 | typedef struct { 77 | uint8_t id; 78 | uint8_t status; 79 | uint32_t total_bandwidth; 80 | uint32_t max_bandwidth; 81 | uint32_t min_latency; 82 | uint16_t pal_caps; 83 | uint16_t assoc_size; 84 | } __attribute__ ((packed)) amp_info_rsp_parms; 85 | 86 | typedef struct { 87 | uint8_t id; 88 | uint8_t status; 89 | amp_assoc_tlv assoc; 90 | } __attribute__ ((packed)) amp_assoc_rsp_parms; 91 | 92 | typedef struct { 93 | uint8_t local_id; 94 | uint8_t remote_id; 95 | amp_assoc_tlv assoc; 96 | } __attribute__ ((packed)) amp_link_req_parms; 97 | 98 | typedef struct { 99 | uint8_t local_id; 100 | uint8_t remote_id; 101 | uint8_t status; 102 | } __attribute__ ((packed)) amp_link_rsp_parms; 103 | 104 | typedef struct { 105 | uint8_t local_id; 106 | uint8_t remote_id; 107 | } __attribute__ ((packed)) amp_disconn_req_parms; 108 | 109 | #define A2MP_MAC_ADDR_TYPE 1 110 | #define A2MP_PREF_CHANLIST_TYPE 2 111 | #define A2MP_CONNECTED_CHAN 3 112 | #define A2MP_PAL_CAP_TYPE 4 113 | #define A2MP_PAL_VER_INFO 5 114 | 115 | struct amp_tlv { 116 | uint8_t type; 117 | uint16_t len; 118 | uint8_t val[0]; 119 | } __attribute__ ((packed)); 120 | 121 | struct amp_pal_ver { 122 | uint8_t ver; 123 | uint16_t company_id; 124 | uint16_t sub_ver; 125 | } __attribute__ ((packed)); 126 | 127 | struct amp_country_triplet { 128 | union { 129 | struct { 130 | uint8_t first_channel; 131 | uint8_t num_channels; 132 | int8_t max_power; 133 | } __attribute__ ((packed)) chans; 134 | struct { 135 | uint8_t reg_extension_id; 136 | uint8_t reg_class; 137 | uint8_t coverage_class; 138 | } __attribute__ ((packed)) ext; 139 | }; 140 | } __attribute__ ((packed)); 141 | 142 | struct amp_chan_list { 143 | uint8_t country_code[3]; 144 | struct amp_country_triplet triplets[0]; 145 | } __attribute__ ((packed)); 146 | 147 | #define AMP_COMMAND_NOT_RECOGNIZED 0x0000 148 | 149 | /* AMP controller status */ 150 | #define AMP_CT_POWERED_DOWN 0x00 151 | #define AMP_CT_BLUETOOTH_ONLY 0x01 152 | #define AMP_CT_NO_CAPACITY 0x02 153 | #define AMP_CT_LOW_CAPACITY 0x03 154 | #define AMP_CT_MEDIUM_CAPACITY 0x04 155 | #define AMP_CT_HIGH_CAPACITY 0x05 156 | #define AMP_CT_FULL_CAPACITY 0x06 157 | 158 | /* AMP response status */ 159 | #define AMP_STATUS_SUCCESS 0x00 160 | #define AMP_STATUS_INVALID_CTRL_ID 0x01 161 | #define AMP_STATUS_UNABLE_START_LINK_CREATION 0x02 162 | #define AMP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02 163 | #define AMP_STATUS_COLLISION_OCCURED 0x03 164 | #define AMP_STATUS_DISCONN_REQ_RECVD 0x04 165 | #define AMP_STATUS_PHYS_LINK_EXISTS 0x05 166 | #define AMP_STATUS_SECURITY_VIOLATION 0x06 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* __AMP_H */ 173 | -------------------------------------------------------------------------------- /ble_socket/include/ble.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ble.h 3 | * 4 | * Created on: Mar 19, 2018 5 | * Author: liangjf 6 | */ 7 | 8 | #ifndef INCLUDE_BLE_H_ 9 | #define INCLUDE_BLE_H_ 10 | 11 | extern unsigned int epoll_fd_num; 12 | extern pthread_mutex_t fd_mutex; 13 | 14 | int BTDevInit(); 15 | int GetEpollNowfdNum(char *str); 16 | int BTInitSocket(void); 17 | int epollAddfd(struct epoll_event *event, int epollfd, int fd, int enable_et); 18 | int epollModfd(struct epoll_event *event, int epollfd, int fd, int enable_et); 19 | int RecvBT(int sockfd, char *r_buf, int r_len); 20 | int SendBT(int sockfd, char *w_buf, int w_len); 21 | void do_use_fd(struct epoll_event *event, int epollfd, int fd); 22 | int EpollBTorListends(struct epoll_event *event, struct epoll_event *events, int epollfd, int ret_fd_num, int listenfd); 23 | 24 | 25 | #endif /* INCLUDE_BLE_H_ */ 26 | -------------------------------------------------------------------------------- /ble_socket/include/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 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 __BLUETOOTH_H 27 | #define __BLUETOOTH_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #ifndef AF_BLUETOOTH 41 | #define AF_BLUETOOTH 31 42 | #define PF_BLUETOOTH AF_BLUETOOTH 43 | #endif 44 | 45 | #define BTPROTO_L2CAP 0 46 | #define BTPROTO_HCI 1 47 | #define BTPROTO_SCO 2 48 | #define BTPROTO_RFCOMM 3 49 | #define BTPROTO_BNEP 4 50 | #define BTPROTO_CMTP 5 51 | #define BTPROTO_HIDP 6 52 | #define BTPROTO_AVDTP 7 53 | 54 | #define SOL_HCI 0 55 | #define SOL_L2CAP 6 56 | #define SOL_SCO 17 57 | #define SOL_RFCOMM 18 58 | 59 | #ifndef SOL_BLUETOOTH 60 | #define SOL_BLUETOOTH 274 61 | #endif 62 | 63 | #define BT_SECURITY 4 64 | struct bt_security { 65 | uint8_t level; 66 | uint8_t key_size; 67 | }; 68 | #define BT_SECURITY_SDP 0 69 | #define BT_SECURITY_LOW 1 70 | #define BT_SECURITY_MEDIUM 2 71 | #define BT_SECURITY_HIGH 3 72 | #define BT_SECURITY_FIPS 4 73 | 74 | #define BT_DEFER_SETUP 7 75 | 76 | #define BT_FLUSHABLE 8 77 | 78 | #define BT_FLUSHABLE_OFF 0 79 | #define BT_FLUSHABLE_ON 1 80 | 81 | #define BT_POWER 9 82 | struct bt_power { 83 | uint8_t force_active; 84 | }; 85 | #define BT_POWER_FORCE_ACTIVE_OFF 0 86 | #define BT_POWER_FORCE_ACTIVE_ON 1 87 | 88 | #define BT_CHANNEL_POLICY 10 89 | 90 | /* BR/EDR only (default policy) 91 | * AMP controllers cannot be used. 92 | * Channel move requests from the remote device are denied. 93 | * If the L2CAP channel is currently using AMP, move the channel to BR/EDR. 94 | */ 95 | #define BT_CHANNEL_POLICY_BREDR_ONLY 0 96 | 97 | /* BR/EDR Preferred 98 | * Allow use of AMP controllers. 99 | * If the L2CAP channel is currently on AMP, move it to BR/EDR. 100 | * Channel move requests from the remote device are allowed. 101 | */ 102 | #define BT_CHANNEL_POLICY_BREDR_PREFERRED 1 103 | 104 | /* AMP Preferred 105 | * Allow use of AMP controllers 106 | * If the L2CAP channel is currently on BR/EDR and AMP controller 107 | * resources are available, initiate a channel move to AMP. 108 | * Channel move requests from the remote device are allowed. 109 | * If the L2CAP socket has not been connected yet, try to create 110 | * and configure the channel directly on an AMP controller rather 111 | * than BR/EDR. 112 | */ 113 | #define BT_CHANNEL_POLICY_AMP_PREFERRED 2 114 | 115 | #define BT_VOICE 11 116 | struct bt_voice { 117 | uint16_t setting; 118 | }; 119 | 120 | #define BT_SNDMTU 12 121 | #define BT_RCVMTU 13 122 | 123 | #define BT_VOICE_TRANSPARENT 0x0003 124 | #define BT_VOICE_CVSD_16BIT 0x0060 125 | 126 | /* Connection and socket states */ 127 | enum { 128 | BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 129 | BT_OPEN, 130 | BT_BOUND, 131 | BT_LISTEN, 132 | BT_CONNECT, 133 | BT_CONNECT2, 134 | BT_CONFIG, 135 | BT_DISCONN, 136 | BT_CLOSED 137 | }; 138 | 139 | /* Byte order conversions */ 140 | #if __BYTE_ORDER == __LITTLE_ENDIAN 141 | #define htobs(d) (d) 142 | #define htobl(d) (d) 143 | #define htobll(d) (d) 144 | #define btohs(d) (d) 145 | #define btohl(d) (d) 146 | #define btohll(d) (d) 147 | #elif __BYTE_ORDER == __BIG_ENDIAN 148 | #define htobs(d) bswap_16(d) 149 | #define htobl(d) bswap_32(d) 150 | #define htobll(d) bswap_64(d) 151 | #define btohs(d) bswap_16(d) 152 | #define btohl(d) bswap_32(d) 153 | #define btohll(d) bswap_64(d) 154 | #else 155 | #error "Unknown byte order" 156 | #endif 157 | 158 | /* Bluetooth unaligned access */ 159 | #define bt_get_unaligned(ptr) \ 160 | __extension__ ({ \ 161 | struct __attribute__((packed)) { \ 162 | __typeof__(*(ptr)) __v; \ 163 | } *__p = (__typeof__(__p)) (ptr); \ 164 | __p->__v; \ 165 | }) 166 | 167 | #define bt_put_unaligned(val, ptr) \ 168 | do { \ 169 | struct __attribute__((packed)) { \ 170 | __typeof__(*(ptr)) __v; \ 171 | } *__p = (__typeof__(__p)) (ptr); \ 172 | __p->__v = (val); \ 173 | } while(0) 174 | 175 | #if __BYTE_ORDER == __LITTLE_ENDIAN 176 | static inline uint64_t bt_get_le64(const void *ptr) 177 | { 178 | return bt_get_unaligned((const uint64_t *) ptr); 179 | } 180 | 181 | static inline uint64_t bt_get_be64(const void *ptr) 182 | { 183 | return bswap_64(bt_get_unaligned((const uint64_t *) ptr)); 184 | } 185 | 186 | static inline uint32_t bt_get_le32(const void *ptr) 187 | { 188 | return bt_get_unaligned((const uint32_t *) ptr); 189 | } 190 | 191 | static inline uint32_t bt_get_be32(const void *ptr) 192 | { 193 | return bswap_32(bt_get_unaligned((const uint32_t *) ptr)); 194 | } 195 | 196 | static inline uint16_t bt_get_le16(const void *ptr) 197 | { 198 | return bt_get_unaligned((const uint16_t *) ptr); 199 | } 200 | 201 | static inline uint16_t bt_get_be16(const void *ptr) 202 | { 203 | return bswap_16(bt_get_unaligned((const uint16_t *) ptr)); 204 | } 205 | 206 | static inline void bt_put_le64(uint64_t val, const void *ptr) 207 | { 208 | bt_put_unaligned(val, (uint64_t *) ptr); 209 | } 210 | 211 | static inline void bt_put_be64(uint64_t val, const void *ptr) 212 | { 213 | bt_put_unaligned(bswap_64(val), (uint64_t *) ptr); 214 | } 215 | 216 | static inline void bt_put_le32(uint32_t val, const void *ptr) 217 | { 218 | bt_put_unaligned(val, (uint32_t *) ptr); 219 | } 220 | 221 | static inline void bt_put_be32(uint32_t val, const void *ptr) 222 | { 223 | bt_put_unaligned(bswap_32(val), (uint32_t *) ptr); 224 | } 225 | 226 | static inline void bt_put_le16(uint16_t val, const void *ptr) 227 | { 228 | bt_put_unaligned(val, (uint16_t *) ptr); 229 | } 230 | 231 | static inline void bt_put_be16(uint16_t val, const void *ptr) 232 | { 233 | bt_put_unaligned(bswap_16(val), (uint16_t *) ptr); 234 | } 235 | 236 | #elif __BYTE_ORDER == __BIG_ENDIAN 237 | static inline uint64_t bt_get_le64(const void *ptr) 238 | { 239 | return bswap_64(bt_get_unaligned((const uint64_t *) ptr)); 240 | } 241 | 242 | static inline uint64_t bt_get_be64(const void *ptr) 243 | { 244 | return bt_get_unaligned((const uint64_t *) ptr); 245 | } 246 | 247 | static inline uint32_t bt_get_le32(const void *ptr) 248 | { 249 | return bswap_32(bt_get_unaligned((const uint32_t *) ptr)); 250 | } 251 | 252 | static inline uint32_t bt_get_be32(const void *ptr) 253 | { 254 | return bt_get_unaligned((const uint32_t *) ptr); 255 | } 256 | 257 | static inline uint16_t bt_get_le16(const void *ptr) 258 | { 259 | return bswap_16(bt_get_unaligned((const uint16_t *) ptr)); 260 | } 261 | 262 | static inline uint16_t bt_get_be16(const void *ptr) 263 | { 264 | return bt_get_unaligned((const uint16_t *) ptr); 265 | } 266 | 267 | static inline void bt_put_le64(uint64_t val, const void *ptr) 268 | { 269 | bt_put_unaligned(bswap_64(val), (uint64_t *) ptr); 270 | } 271 | 272 | static inline void bt_put_be64(uint64_t val, const void *ptr) 273 | { 274 | bt_put_unaligned(val, (uint64_t *) ptr); 275 | } 276 | 277 | static inline void bt_put_le32(uint32_t val, const void *ptr) 278 | { 279 | bt_put_unaligned(bswap_32(val), (uint32_t *) ptr); 280 | } 281 | 282 | static inline void bt_put_be32(uint32_t val, const void *ptr) 283 | { 284 | bt_put_unaligned(val, (uint32_t *) ptr); 285 | } 286 | 287 | static inline void bt_put_le16(uint16_t val, const void *ptr) 288 | { 289 | bt_put_unaligned(bswap_16(val), (uint16_t *) ptr); 290 | } 291 | 292 | static inline void bt_put_be16(uint16_t val, const void *ptr) 293 | { 294 | bt_put_unaligned(val, (uint16_t *) ptr); 295 | } 296 | #else 297 | #error "Unknown byte order" 298 | #endif 299 | 300 | /* BD Address */ 301 | typedef struct { 302 | uint8_t b[6]; 303 | } __attribute__((packed)) bdaddr_t; 304 | 305 | /* BD Address type */ 306 | #define BDADDR_BREDR 0x00 307 | #define BDADDR_LE_PUBLIC 0x01 308 | #define BDADDR_LE_RANDOM 0x02 309 | 310 | #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 311 | #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 312 | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 313 | 314 | /* Copy, swap, convert BD Address */ 315 | static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 316 | { 317 | return memcmp(ba1, ba2, sizeof(bdaddr_t)); 318 | } 319 | static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) 320 | { 321 | memcpy(dst, src, sizeof(bdaddr_t)); 322 | } 323 | 324 | void baswap(bdaddr_t *dst, const bdaddr_t *src); 325 | bdaddr_t *strtoba(const char *str); 326 | char *batostr(const bdaddr_t *ba); 327 | int ba2str(const bdaddr_t *ba, char *str); 328 | int str2ba(const char *str, bdaddr_t *ba); 329 | int ba2oui(const bdaddr_t *ba, char *oui); 330 | int bachk(const char *str); 331 | 332 | int baprintf(const char *format, ...); 333 | int bafprintf(FILE *stream, const char *format, ...); 334 | int basprintf(char *str, const char *format, ...); 335 | int basnprintf(char *str, size_t size, const char *format, ...); 336 | 337 | void *bt_malloc(size_t size); 338 | void bt_free(void *ptr); 339 | 340 | int bt_error(uint16_t code); 341 | const char *bt_compidtostr(int id); 342 | 343 | typedef struct { 344 | uint8_t data[16]; 345 | } uint128_t; 346 | 347 | static inline void bswap_128(const void *src, void *dst) 348 | { 349 | const uint8_t *s = (const uint8_t *) src; 350 | uint8_t *d = (uint8_t *) dst; 351 | int i; 352 | 353 | for (i = 0; i < 16; i++) 354 | d[15 - i] = s[i]; 355 | } 356 | 357 | #if __BYTE_ORDER == __BIG_ENDIAN 358 | 359 | #define ntoh64(x) (x) 360 | 361 | static inline void ntoh128(const uint128_t *src, uint128_t *dst) 362 | { 363 | memcpy(dst, src, sizeof(uint128_t)); 364 | } 365 | 366 | static inline void btoh128(const uint128_t *src, uint128_t *dst) 367 | { 368 | bswap_128(src, dst); 369 | } 370 | 371 | #else 372 | 373 | static inline uint64_t ntoh64(uint64_t n) 374 | { 375 | uint64_t h; 376 | uint64_t tmp = ntohl(n & 0x00000000ffffffff); 377 | 378 | h = ntohl(n >> 32); 379 | h |= tmp << 32; 380 | 381 | return h; 382 | } 383 | 384 | static inline void ntoh128(const uint128_t *src, uint128_t *dst) 385 | { 386 | bswap_128(src, dst); 387 | } 388 | 389 | static inline void btoh128(const uint128_t *src, uint128_t *dst) 390 | { 391 | memcpy(dst, src, sizeof(uint128_t)); 392 | } 393 | 394 | #endif 395 | 396 | #define hton64(x) ntoh64(x) 397 | #define hton128(x, y) ntoh128(x, y) 398 | #define htob128(x, y) btoh128(x, y) 399 | 400 | #ifdef __cplusplus 401 | } 402 | #endif 403 | 404 | #endif /* __BLUETOOTH_H */ 405 | -------------------------------------------------------------------------------- /ble_socket/include/bluez.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: BlueZ 7 | Description: Bluetooth protocol stack for Linux 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lbluetooth 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /ble_socket/include/bnep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __BNEP_H 26 | #define __BNEP_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | #ifndef ETH_ALEN 35 | #define ETH_ALEN 6 /* from */ 36 | #endif 37 | 38 | /* BNEP UUIDs */ 39 | #define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB 40 | #define BNEP_UUID16 0x02 41 | #define BNEP_UUID32 0x04 42 | #define BNEP_UUID128 0x16 43 | 44 | #define BNEP_SVC_PANU 0x1115 45 | #define BNEP_SVC_NAP 0x1116 46 | #define BNEP_SVC_GN 0x1117 47 | 48 | /* BNEP packet types */ 49 | #define BNEP_GENERAL 0x00 50 | #define BNEP_CONTROL 0x01 51 | #define BNEP_COMPRESSED 0x02 52 | #define BNEP_COMPRESSED_SRC_ONLY 0x03 53 | #define BNEP_COMPRESSED_DST_ONLY 0x04 54 | 55 | /* BNEP control types */ 56 | #define BNEP_CMD_NOT_UNDERSTOOD 0x00 57 | #define BNEP_SETUP_CONN_REQ 0x01 58 | #define BNEP_SETUP_CONN_RSP 0x02 59 | #define BNEP_FILTER_NET_TYPE_SET 0x03 60 | #define BNEP_FILTER_NET_TYPE_RSP 0x04 61 | #define BNEP_FILTER_MULT_ADDR_SET 0x05 62 | #define BNEP_FILTER_MULT_ADDR_RSP 0x06 63 | 64 | /* BNEP response messages */ 65 | #define BNEP_SUCCESS 0x00 66 | 67 | #define BNEP_CONN_INVALID_DST 0x01 68 | #define BNEP_CONN_INVALID_SRC 0x02 69 | #define BNEP_CONN_INVALID_SVC 0x03 70 | #define BNEP_CONN_NOT_ALLOWED 0x04 71 | 72 | #define BNEP_FILTER_UNSUPPORTED_REQ 0x01 73 | #define BNEP_FILTER_INVALID_RANGE 0x02 74 | #define BNEP_FILTER_INVALID_MCADDR 0x02 75 | #define BNEP_FILTER_LIMIT_REACHED 0x03 76 | #define BNEP_FILTER_DENIED_SECURITY 0x04 77 | 78 | /* L2CAP settings */ 79 | #define BNEP_MTU 1691 80 | #define BNEP_FLUSH_TO 0xffff 81 | #define BNEP_CONNECT_TO 15 82 | #define BNEP_FILTER_TO 15 83 | 84 | #ifndef BNEP_PSM 85 | #define BNEP_PSM 0x0f 86 | #endif 87 | 88 | /* BNEP headers */ 89 | #define BNEP_TYPE_MASK 0x7f 90 | #define BNEP_EXT_HEADER 0x80 91 | 92 | struct bnep_setup_conn_req { 93 | uint8_t type; 94 | uint8_t ctrl; 95 | uint8_t uuid_size; 96 | uint8_t service[0]; 97 | } __attribute__((packed)); 98 | 99 | struct bnep_set_filter_req { 100 | uint8_t type; 101 | uint8_t ctrl; 102 | uint16_t len; 103 | uint8_t list[0]; 104 | } __attribute__((packed)); 105 | 106 | struct bnep_ctrl_cmd_not_understood_cmd { 107 | uint8_t type; 108 | uint8_t ctrl; 109 | uint8_t unkn_ctrl; 110 | } __attribute__((packed)); 111 | 112 | struct bnep_control_rsp { 113 | uint8_t type; 114 | uint8_t ctrl; 115 | uint16_t resp; 116 | } __attribute__((packed)); 117 | 118 | struct bnep_ext_hdr { 119 | uint8_t type; 120 | uint8_t len; 121 | uint8_t data[0]; 122 | } __attribute__((packed)); 123 | 124 | /* BNEP ioctl defines */ 125 | #define BNEPCONNADD _IOW('B', 200, int) 126 | #define BNEPCONNDEL _IOW('B', 201, int) 127 | #define BNEPGETCONNLIST _IOR('B', 210, int) 128 | #define BNEPGETCONNINFO _IOR('B', 211, int) 129 | #define BNEPGETSUPPFEAT _IOR('B', 212, int) 130 | 131 | #define BNEP_SETUP_RESPONSE 0 132 | 133 | struct bnep_connadd_req { 134 | int sock; /* Connected socket */ 135 | uint32_t flags; 136 | uint16_t role; 137 | char device[16]; /* Name of the Ethernet device */ 138 | }; 139 | 140 | struct bnep_conndel_req { 141 | uint32_t flags; 142 | uint8_t dst[ETH_ALEN]; 143 | }; 144 | 145 | struct bnep_conninfo { 146 | uint32_t flags; 147 | uint16_t role; 148 | uint16_t state; 149 | uint8_t dst[ETH_ALEN]; 150 | char device[16]; 151 | }; 152 | 153 | struct bnep_connlist_req { 154 | uint32_t cnum; 155 | struct bnep_conninfo *ci; 156 | }; 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* __BNEP_H */ 163 | -------------------------------------------------------------------------------- /ble_socket/include/cmtp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2010 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __CMTP_H 25 | #define __CMTP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* CMTP defaults */ 32 | #define CMTP_MINIMUM_MTU 152 33 | #define CMTP_DEFAULT_MTU 672 34 | 35 | /* CMTP ioctl defines */ 36 | #define CMTPCONNADD _IOW('C', 200, int) 37 | #define CMTPCONNDEL _IOW('C', 201, int) 38 | #define CMTPGETCONNLIST _IOR('C', 210, int) 39 | #define CMTPGETCONNINFO _IOR('C', 211, int) 40 | 41 | #define CMTP_LOOPBACK 0 42 | 43 | struct cmtp_connadd_req { 44 | int sock; /* Connected socket */ 45 | uint32_t flags; 46 | }; 47 | 48 | struct cmtp_conndel_req { 49 | bdaddr_t bdaddr; 50 | uint32_t flags; 51 | }; 52 | 53 | struct cmtp_conninfo { 54 | bdaddr_t bdaddr; 55 | uint32_t flags; 56 | uint16_t state; 57 | int num; 58 | }; 59 | 60 | struct cmtp_connlist_req { 61 | uint32_t cnum; 62 | struct cmtp_conninfo *ci; 63 | }; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __CMTP_H */ 70 | -------------------------------------------------------------------------------- /ble_socket/include/hci_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 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 30 | extern "C" { 31 | #endif 32 | 33 | struct 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 | 43 | struct 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 | 51 | int hci_open_dev(int dev_id); 52 | int hci_close_dev(int dd); 53 | int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param); 54 | int hci_send_req(int dd, struct hci_request *req, int timeout); 55 | 56 | int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to); 57 | int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to); 58 | 59 | int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags); 60 | int hci_devinfo(int dev_id, struct hci_dev_info *di); 61 | int hci_devba(int dev_id, bdaddr_t *bdaddr); 62 | int hci_devid(const char *str); 63 | 64 | int hci_read_local_name(int dd, int len, char *name, int to); 65 | int hci_write_local_name(int dd, const char *name, int to); 66 | int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name, int to); 67 | 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); 68 | int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to); 69 | int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver, int to); 70 | int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to); 71 | int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 72 | int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to); 73 | int hci_read_local_version(int dd, struct hci_version *ver, int to); 74 | int hci_read_local_commands(int dd, uint8_t *commands, int to); 75 | int hci_read_local_features(int dd, uint8_t *features, int to); 76 | int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 77 | int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to); 78 | int hci_read_class_of_dev(int dd, uint8_t *cls, int to); 79 | int hci_write_class_of_dev(int dd, uint32_t cls, int to); 80 | int hci_read_voice_setting(int dd, uint16_t *vs, int to); 81 | int hci_write_voice_setting(int dd, uint16_t vs, int to); 82 | int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to); 83 | int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to); 84 | int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 85 | int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to); 86 | int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 87 | int hci_authenticate_link(int dd, uint16_t handle, int to); 88 | int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to); 89 | int hci_change_link_key(int dd, uint16_t handle, int to); 90 | int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to); 91 | int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to); 92 | int hci_exit_park_mode(int dd, uint16_t handle, int to); 93 | int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to); 94 | int hci_write_inquiry_scan_type(int dd, uint8_t type, int to); 95 | int hci_read_inquiry_mode(int dd, uint8_t *mode, int to); 96 | int hci_write_inquiry_mode(int dd, uint8_t mode, int to); 97 | int hci_read_afh_mode(int dd, uint8_t *mode, int to); 98 | int hci_write_afh_mode(int dd, uint8_t mode, int to); 99 | int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to); 100 | int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to); 101 | int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to); 102 | int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to); 103 | int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to); 104 | int hci_read_inq_response_tx_power_level(int dd, int8_t *level, int to); 105 | int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to); 106 | int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to); 107 | int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type, int8_t *level, int to); 108 | int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to); 109 | int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to); 110 | int hci_read_link_supervision_timeout(int dd, uint16_t handle, uint16_t *timeout, int to); 111 | int hci_write_link_supervision_timeout(int dd, uint16_t handle, uint16_t timeout, int to); 112 | int hci_set_afh_classification(int dd, uint8_t *map, int to); 113 | int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality, int to); 114 | int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to); 115 | int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map, int to); 116 | int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock, uint16_t *accuracy, int to); 117 | 118 | int hci_le_set_scan_enable(int dev_id, uint8_t enable, uint8_t filter_dup, int to); 119 | int hci_le_set_scan_parameters(int dev_id, uint8_t type, uint16_t interval, 120 | uint16_t window, uint8_t own_type, 121 | uint8_t filter, int to); 122 | int hci_le_set_advertise_enable(int dev_id, uint8_t enable, int to); 123 | int hci_le_create_conn(int dd, uint16_t interval, uint16_t window, 124 | uint8_t initiator_filter, uint8_t peer_bdaddr_type, 125 | bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type, 126 | uint16_t min_interval, uint16_t max_interval, 127 | uint16_t latency, uint16_t supervision_timeout, 128 | uint16_t min_ce_length, uint16_t max_ce_length, 129 | uint16_t *handle, int to); 130 | int hci_le_conn_update(int dd, uint16_t handle, uint16_t min_interval, 131 | uint16_t max_interval, uint16_t latency, 132 | uint16_t supervision_timeout, int to); 133 | int hci_le_add_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to); 134 | int hci_le_rm_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to); 135 | int hci_le_read_white_list_size(int dd, uint8_t *size, int to); 136 | int hci_le_clear_white_list(int dd, int to); 137 | int hci_le_add_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, 138 | uint8_t *peer_irk, uint8_t *local_irk, int to); 139 | int hci_le_rm_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to); 140 | int hci_le_clear_resolving_list(int dd, int to); 141 | int hci_le_read_resolving_list_size(int dd, uint8_t *size, int to); 142 | int hci_le_set_address_resolution_enable(int dev_id, uint8_t enable, int to); 143 | int hci_le_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to); 144 | 145 | int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg); 146 | int hci_get_route(bdaddr_t *bdaddr); 147 | 148 | char *hci_bustostr(int bus); 149 | char *hci_typetostr(int type); 150 | char *hci_dtypetostr(int type); 151 | char *hci_dflagstostr(uint32_t flags); 152 | char *hci_ptypetostr(unsigned int ptype); 153 | int hci_strtoptype(char *str, unsigned int *val); 154 | char *hci_scoptypetostr(unsigned int ptype); 155 | int hci_strtoscoptype(char *str, unsigned int *val); 156 | char *hci_lptostr(unsigned int ptype); 157 | int hci_strtolp(char *str, unsigned int *val); 158 | char *hci_lmtostr(unsigned int ptype); 159 | int hci_strtolm(char *str, unsigned int *val); 160 | 161 | char *hci_cmdtostr(unsigned int cmd); 162 | char *hci_commandstostr(uint8_t *commands, char *pref, int width); 163 | 164 | char *hci_vertostr(unsigned int ver); 165 | int hci_strtover(char *str, unsigned int *ver); 166 | char *lmp_vertostr(unsigned int ver); 167 | int lmp_strtover(char *str, unsigned int *ver); 168 | char *pal_vertostr(unsigned int ver); 169 | int pal_strtover(char *str, unsigned int *ver); 170 | 171 | char *lmp_featurestostr(uint8_t *features, char *pref, int width); 172 | 173 | static inline void hci_set_bit(int nr, void *addr) 174 | { 175 | *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31)); 176 | } 177 | 178 | static inline void hci_clear_bit(int nr, void *addr) 179 | { 180 | *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31)); 181 | } 182 | 183 | static inline int hci_test_bit(int nr, void *addr) 184 | { 185 | return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31)); 186 | } 187 | 188 | /* HCI filter tools */ 189 | static inline void hci_filter_clear(struct hci_filter *f) 190 | { 191 | memset(f, 0, sizeof(*f)); 192 | } 193 | static inline void hci_filter_set_ptype(int t, struct hci_filter *f) 194 | { 195 | hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 196 | } 197 | static inline void hci_filter_clear_ptype(int t, struct hci_filter *f) 198 | { 199 | hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 200 | } 201 | static inline int hci_filter_test_ptype(int t, struct hci_filter *f) 202 | { 203 | return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 204 | } 205 | static inline void hci_filter_all_ptypes(struct hci_filter *f) 206 | { 207 | memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask)); 208 | } 209 | static inline void hci_filter_set_event(int e, struct hci_filter *f) 210 | { 211 | hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 212 | } 213 | static inline void hci_filter_clear_event(int e, struct hci_filter *f) 214 | { 215 | hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 216 | } 217 | static inline int hci_filter_test_event(int e, struct hci_filter *f) 218 | { 219 | return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 220 | } 221 | static inline void hci_filter_all_events(struct hci_filter *f) 222 | { 223 | memset((void *) f->event_mask, 0xff, sizeof(f->event_mask)); 224 | } 225 | static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f) 226 | { 227 | f->opcode = opcode; 228 | } 229 | static inline void hci_filter_clear_opcode(struct hci_filter *f) 230 | { 231 | f->opcode = 0; 232 | } 233 | static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f) 234 | { 235 | return (f->opcode == opcode); 236 | } 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif 241 | 242 | #endif /* __HCI_LIB_H */ 243 | -------------------------------------------------------------------------------- /ble_socket/include/hidp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2003-2010 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __HIDP_H 25 | #define __HIDP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* HIDP defaults */ 32 | #define HIDP_MINIMUM_MTU 48 33 | #define HIDP_DEFAULT_MTU 48 34 | 35 | /* HIDP ioctl defines */ 36 | #define HIDPCONNADD _IOW('H', 200, int) 37 | #define HIDPCONNDEL _IOW('H', 201, int) 38 | #define HIDPGETCONNLIST _IOR('H', 210, int) 39 | #define HIDPGETCONNINFO _IOR('H', 211, int) 40 | 41 | #define HIDP_VIRTUAL_CABLE_UNPLUG 0 42 | #define HIDP_BOOT_PROTOCOL_MODE 1 43 | #define HIDP_BLUETOOTH_VENDOR_ID 9 44 | 45 | struct hidp_connadd_req { 46 | int ctrl_sock; /* Connected control socket */ 47 | int intr_sock; /* Connected interrupt socket */ 48 | uint16_t parser; /* Parser version */ 49 | uint16_t rd_size; /* Report descriptor size */ 50 | uint8_t *rd_data; /* Report descriptor data */ 51 | uint8_t country; 52 | uint8_t subclass; 53 | uint16_t vendor; 54 | uint16_t product; 55 | uint16_t version; 56 | uint32_t flags; 57 | uint32_t idle_to; 58 | char name[128]; /* Device name */ 59 | }; 60 | 61 | struct hidp_conndel_req { 62 | bdaddr_t bdaddr; 63 | uint32_t flags; 64 | }; 65 | 66 | struct hidp_conninfo { 67 | bdaddr_t bdaddr; 68 | uint32_t flags; 69 | uint16_t state; 70 | uint16_t vendor; 71 | uint16_t product; 72 | uint16_t version; 73 | char name[128]; 74 | }; 75 | 76 | struct hidp_connlist_req { 77 | uint32_t cnum; 78 | struct hidp_conninfo *ci; 79 | }; 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* __HIDP_H */ 86 | -------------------------------------------------------------------------------- /ble_socket/include/l2cap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * Copyright (c) 2012 Code Aurora Forum. All rights reserved. 9 | * 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | #ifndef __L2CAP_H 28 | #define __L2CAP_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include 35 | 36 | /* L2CAP defaults */ 37 | #define L2CAP_DEFAULT_MTU 672 38 | #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 39 | 40 | /* L2CAP socket address */ 41 | struct sockaddr_l2 { 42 | sa_family_t l2_family; 43 | unsigned short l2_psm; 44 | bdaddr_t l2_bdaddr; 45 | unsigned short l2_cid; 46 | uint8_t l2_bdaddr_type; 47 | }; 48 | 49 | /* L2CAP socket options */ 50 | #define L2CAP_OPTIONS 0x01 51 | struct l2cap_options { 52 | uint16_t omtu; 53 | uint16_t imtu; 54 | uint16_t flush_to; 55 | uint8_t mode; 56 | uint8_t fcs; 57 | uint8_t max_tx; 58 | uint16_t txwin_size; 59 | }; 60 | 61 | #define L2CAP_CONNINFO 0x02 62 | struct l2cap_conninfo { 63 | uint16_t hci_handle; 64 | uint8_t dev_class[3]; 65 | }; 66 | 67 | #define L2CAP_LM 0x03 68 | #define L2CAP_LM_MASTER 0x0001 69 | #define L2CAP_LM_AUTH 0x0002 70 | #define L2CAP_LM_ENCRYPT 0x0004 71 | #define L2CAP_LM_TRUSTED 0x0008 72 | #define L2CAP_LM_RELIABLE 0x0010 73 | #define L2CAP_LM_SECURE 0x0020 74 | 75 | /* L2CAP command codes */ 76 | #define L2CAP_COMMAND_REJ 0x01 77 | #define L2CAP_CONN_REQ 0x02 78 | #define L2CAP_CONN_RSP 0x03 79 | #define L2CAP_CONF_REQ 0x04 80 | #define L2CAP_CONF_RSP 0x05 81 | #define L2CAP_DISCONN_REQ 0x06 82 | #define L2CAP_DISCONN_RSP 0x07 83 | #define L2CAP_ECHO_REQ 0x08 84 | #define L2CAP_ECHO_RSP 0x09 85 | #define L2CAP_INFO_REQ 0x0a 86 | #define L2CAP_INFO_RSP 0x0b 87 | #define L2CAP_CREATE_REQ 0x0c 88 | #define L2CAP_CREATE_RSP 0x0d 89 | #define L2CAP_MOVE_REQ 0x0e 90 | #define L2CAP_MOVE_RSP 0x0f 91 | #define L2CAP_MOVE_CFM 0x10 92 | #define L2CAP_MOVE_CFM_RSP 0x11 93 | 94 | /* L2CAP extended feature mask */ 95 | #define L2CAP_FEAT_FLOWCTL 0x00000001 96 | #define L2CAP_FEAT_RETRANS 0x00000002 97 | #define L2CAP_FEAT_BIDIR_QOS 0x00000004 98 | #define L2CAP_FEAT_ERTM 0x00000008 99 | #define L2CAP_FEAT_STREAMING 0x00000010 100 | #define L2CAP_FEAT_FCS 0x00000020 101 | #define L2CAP_FEAT_EXT_FLOW 0x00000040 102 | #define L2CAP_FEAT_FIXED_CHAN 0x00000080 103 | #define L2CAP_FEAT_EXT_WINDOW 0x00000100 104 | #define L2CAP_FEAT_UCD 0x00000200 105 | 106 | /* L2CAP fixed channels */ 107 | #define L2CAP_FC_L2CAP 0x02 108 | #define L2CAP_FC_CONNLESS 0x04 109 | #define L2CAP_FC_A2MP 0x08 110 | 111 | /* L2CAP structures */ 112 | typedef struct { 113 | uint16_t len; 114 | uint16_t cid; 115 | } __attribute__ ((packed)) l2cap_hdr; 116 | #define L2CAP_HDR_SIZE 4 117 | 118 | typedef struct { 119 | uint8_t code; 120 | uint8_t ident; 121 | uint16_t len; 122 | } __attribute__ ((packed)) l2cap_cmd_hdr; 123 | #define L2CAP_CMD_HDR_SIZE 4 124 | 125 | typedef struct { 126 | uint16_t reason; 127 | } __attribute__ ((packed)) l2cap_cmd_rej; 128 | #define L2CAP_CMD_REJ_SIZE 2 129 | 130 | typedef struct { 131 | uint16_t psm; 132 | uint16_t scid; 133 | } __attribute__ ((packed)) l2cap_conn_req; 134 | #define L2CAP_CONN_REQ_SIZE 4 135 | 136 | typedef struct { 137 | uint16_t dcid; 138 | uint16_t scid; 139 | uint16_t result; 140 | uint16_t status; 141 | } __attribute__ ((packed)) l2cap_conn_rsp; 142 | #define L2CAP_CONN_RSP_SIZE 8 143 | 144 | /* connect result */ 145 | #define L2CAP_CR_SUCCESS 0x0000 146 | #define L2CAP_CR_PEND 0x0001 147 | #define L2CAP_CR_BAD_PSM 0x0002 148 | #define L2CAP_CR_SEC_BLOCK 0x0003 149 | #define L2CAP_CR_NO_MEM 0x0004 150 | 151 | /* connect status */ 152 | #define L2CAP_CS_NO_INFO 0x0000 153 | #define L2CAP_CS_AUTHEN_PEND 0x0001 154 | #define L2CAP_CS_AUTHOR_PEND 0x0002 155 | 156 | typedef struct { 157 | uint16_t dcid; 158 | uint16_t flags; 159 | uint8_t data[0]; 160 | } __attribute__ ((packed)) l2cap_conf_req; 161 | #define L2CAP_CONF_REQ_SIZE 4 162 | 163 | typedef struct { 164 | uint16_t scid; 165 | uint16_t flags; 166 | uint16_t result; 167 | uint8_t data[0]; 168 | } __attribute__ ((packed)) l2cap_conf_rsp; 169 | #define L2CAP_CONF_RSP_SIZE 6 170 | 171 | #define L2CAP_CONF_SUCCESS 0x0000 172 | #define L2CAP_CONF_UNACCEPT 0x0001 173 | #define L2CAP_CONF_REJECT 0x0002 174 | #define L2CAP_CONF_UNKNOWN 0x0003 175 | #define L2CAP_CONF_PENDING 0x0004 176 | #define L2CAP_CONF_EFS_REJECT 0x0005 177 | 178 | typedef struct { 179 | uint8_t type; 180 | uint8_t len; 181 | uint8_t val[0]; 182 | } __attribute__ ((packed)) l2cap_conf_opt; 183 | #define L2CAP_CONF_OPT_SIZE 2 184 | 185 | #define L2CAP_CONF_MTU 0x01 186 | #define L2CAP_CONF_FLUSH_TO 0x02 187 | #define L2CAP_CONF_QOS 0x03 188 | #define L2CAP_CONF_RFC 0x04 189 | #define L2CAP_CONF_FCS 0x05 190 | #define L2CAP_CONF_EFS 0x06 191 | #define L2CAP_CONF_EWS 0x07 192 | 193 | #define L2CAP_CONF_MAX_SIZE 22 194 | 195 | #define L2CAP_MODE_BASIC 0x00 196 | #define L2CAP_MODE_RETRANS 0x01 197 | #define L2CAP_MODE_FLOWCTL 0x02 198 | #define L2CAP_MODE_ERTM 0x03 199 | #define L2CAP_MODE_STREAMING 0x04 200 | 201 | #define L2CAP_SERVTYPE_NOTRAFFIC 0x00 202 | #define L2CAP_SERVTYPE_BESTEFFORT 0x01 203 | #define L2CAP_SERVTYPE_GUARANTEED 0x02 204 | 205 | typedef struct { 206 | uint16_t dcid; 207 | uint16_t scid; 208 | } __attribute__ ((packed)) l2cap_disconn_req; 209 | #define L2CAP_DISCONN_REQ_SIZE 4 210 | 211 | typedef struct { 212 | uint16_t dcid; 213 | uint16_t scid; 214 | } __attribute__ ((packed)) l2cap_disconn_rsp; 215 | #define L2CAP_DISCONN_RSP_SIZE 4 216 | 217 | typedef struct { 218 | uint16_t type; 219 | } __attribute__ ((packed)) l2cap_info_req; 220 | #define L2CAP_INFO_REQ_SIZE 2 221 | 222 | typedef struct { 223 | uint16_t type; 224 | uint16_t result; 225 | uint8_t data[0]; 226 | } __attribute__ ((packed)) l2cap_info_rsp; 227 | #define L2CAP_INFO_RSP_SIZE 4 228 | 229 | /* info type */ 230 | #define L2CAP_IT_CL_MTU 0x0001 231 | #define L2CAP_IT_FEAT_MASK 0x0002 232 | 233 | /* info result */ 234 | #define L2CAP_IR_SUCCESS 0x0000 235 | #define L2CAP_IR_NOTSUPP 0x0001 236 | 237 | typedef struct { 238 | uint16_t psm; 239 | uint16_t scid; 240 | uint8_t id; 241 | } __attribute__ ((packed)) l2cap_create_req; 242 | #define L2CAP_CREATE_REQ_SIZE 5 243 | 244 | typedef struct { 245 | uint16_t dcid; 246 | uint16_t scid; 247 | uint16_t result; 248 | uint16_t status; 249 | } __attribute__ ((packed)) l2cap_create_rsp; 250 | #define L2CAP_CREATE_RSP_SIZE 8 251 | 252 | typedef struct { 253 | uint16_t icid; 254 | uint8_t id; 255 | } __attribute__ ((packed)) l2cap_move_req; 256 | #define L2CAP_MOVE_REQ_SIZE 3 257 | 258 | typedef struct { 259 | uint16_t icid; 260 | uint16_t result; 261 | } __attribute__ ((packed)) l2cap_move_rsp; 262 | #define L2CAP_MOVE_RSP_SIZE 4 263 | 264 | typedef struct { 265 | uint16_t icid; 266 | uint16_t result; 267 | } __attribute__ ((packed)) l2cap_move_cfm; 268 | #define L2CAP_MOVE_CFM_SIZE 4 269 | 270 | typedef struct { 271 | uint16_t icid; 272 | } __attribute__ ((packed)) l2cap_move_cfm_rsp; 273 | #define L2CAP_MOVE_CFM_RSP_SIZE 2 274 | 275 | #ifdef __cplusplus 276 | } 277 | #endif 278 | 279 | #endif /* __L2CAP_H */ 280 | -------------------------------------------------------------------------------- /ble_socket/include/mgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BlueZ - Bluetooth protocol stack for Linux 3 | * 4 | * Copyright (C) 2010 Nokia Corporation 5 | * Copyright (C) 2010 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __packed 25 | #define __packed __attribute__((packed)) 26 | #endif 27 | 28 | #define MGMT_INDEX_NONE 0xFFFF 29 | 30 | #define MGMT_STATUS_SUCCESS 0x00 31 | #define MGMT_STATUS_UNKNOWN_COMMAND 0x01 32 | #define MGMT_STATUS_NOT_CONNECTED 0x02 33 | #define MGMT_STATUS_FAILED 0x03 34 | #define MGMT_STATUS_CONNECT_FAILED 0x04 35 | #define MGMT_STATUS_AUTH_FAILED 0x05 36 | #define MGMT_STATUS_NOT_PAIRED 0x06 37 | #define MGMT_STATUS_NO_RESOURCES 0x07 38 | #define MGMT_STATUS_TIMEOUT 0x08 39 | #define MGMT_STATUS_ALREADY_CONNECTED 0x09 40 | #define MGMT_STATUS_BUSY 0x0a 41 | #define MGMT_STATUS_REJECTED 0x0b 42 | #define MGMT_STATUS_NOT_SUPPORTED 0x0c 43 | #define MGMT_STATUS_INVALID_PARAMS 0x0d 44 | #define MGMT_STATUS_DISCONNECTED 0x0e 45 | #define MGMT_STATUS_NOT_POWERED 0x0f 46 | #define MGMT_STATUS_CANCELLED 0x10 47 | #define MGMT_STATUS_INVALID_INDEX 0x11 48 | #define MGMT_STATUS_RFKILLED 0x12 49 | #define MGMT_STATUS_ALREADY_PAIRED 0x13 50 | #define MGMT_STATUS_PERMISSION_DENIED 0x14 51 | 52 | struct mgmt_hdr { 53 | uint16_t opcode; 54 | uint16_t index; 55 | uint16_t len; 56 | } __packed; 57 | #define MGMT_HDR_SIZE 6 58 | 59 | struct mgmt_addr_info { 60 | bdaddr_t bdaddr; 61 | uint8_t type; 62 | } __packed; 63 | 64 | #define MGMT_OP_READ_VERSION 0x0001 65 | struct mgmt_rp_read_version { 66 | uint8_t version; 67 | uint16_t revision; 68 | } __packed; 69 | 70 | #define MGMT_OP_READ_COMMANDS 0x0002 71 | struct mgmt_rp_read_commands { 72 | uint16_t num_commands; 73 | uint16_t num_events; 74 | uint16_t opcodes[0]; 75 | } __packed; 76 | 77 | #define MGMT_OP_READ_INDEX_LIST 0x0003 78 | struct mgmt_rp_read_index_list { 79 | uint16_t num_controllers; 80 | uint16_t index[0]; 81 | } __packed; 82 | 83 | /* Reserve one extra byte for names in management messages so that they 84 | * are always guaranteed to be nul-terminated */ 85 | #define MGMT_MAX_NAME_LENGTH (248 + 1) 86 | #define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1) 87 | 88 | #define MGMT_SETTING_POWERED 0x00000001 89 | #define MGMT_SETTING_CONNECTABLE 0x00000002 90 | #define MGMT_SETTING_FAST_CONNECTABLE 0x00000004 91 | #define MGMT_SETTING_DISCOVERABLE 0x00000008 92 | #define MGMT_SETTING_BONDABLE 0x00000010 93 | #define MGMT_SETTING_LINK_SECURITY 0x00000020 94 | #define MGMT_SETTING_SSP 0x00000040 95 | #define MGMT_SETTING_BREDR 0x00000080 96 | #define MGMT_SETTING_HS 0x00000100 97 | #define MGMT_SETTING_LE 0x00000200 98 | #define MGMT_SETTING_ADVERTISING 0x00000400 99 | #define MGMT_SETTING_SECURE_CONN 0x00000800 100 | #define MGMT_SETTING_DEBUG_KEYS 0x00001000 101 | #define MGMT_SETTING_PRIVACY 0x00002000 102 | #define MGMT_SETTING_CONFIGURATION 0x00004000 103 | #define MGMT_SETTING_STATIC_ADDRESS 0x00008000 104 | 105 | #define MGMT_OP_READ_INFO 0x0004 106 | struct mgmt_rp_read_info { 107 | bdaddr_t bdaddr; 108 | uint8_t version; 109 | uint16_t manufacturer; 110 | uint32_t supported_settings; 111 | uint32_t current_settings; 112 | uint8_t dev_class[3]; 113 | uint8_t name[MGMT_MAX_NAME_LENGTH]; 114 | uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH]; 115 | } __packed; 116 | 117 | struct mgmt_mode { 118 | uint8_t val; 119 | } __packed; 120 | 121 | struct mgmt_cod { 122 | uint8_t val[3]; 123 | } __packed; 124 | 125 | #define MGMT_OP_SET_POWERED 0x0005 126 | 127 | #define MGMT_OP_SET_DISCOVERABLE 0x0006 128 | struct mgmt_cp_set_discoverable { 129 | uint8_t val; 130 | uint16_t timeout; 131 | } __packed; 132 | 133 | #define MGMT_OP_SET_CONNECTABLE 0x0007 134 | 135 | #define MGMT_OP_SET_FAST_CONNECTABLE 0x0008 136 | 137 | #define MGMT_OP_SET_BONDABLE 0x0009 138 | 139 | #define MGMT_OP_SET_LINK_SECURITY 0x000A 140 | 141 | #define MGMT_OP_SET_SSP 0x000B 142 | 143 | #define MGMT_OP_SET_HS 0x000C 144 | 145 | #define MGMT_OP_SET_LE 0x000D 146 | 147 | #define MGMT_OP_SET_DEV_CLASS 0x000E 148 | struct mgmt_cp_set_dev_class { 149 | uint8_t major; 150 | uint8_t minor; 151 | } __packed; 152 | 153 | #define MGMT_OP_SET_LOCAL_NAME 0x000F 154 | struct mgmt_cp_set_local_name { 155 | uint8_t name[MGMT_MAX_NAME_LENGTH]; 156 | uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH]; 157 | } __packed; 158 | 159 | #define MGMT_OP_ADD_UUID 0x0010 160 | struct mgmt_cp_add_uuid { 161 | uint8_t uuid[16]; 162 | uint8_t svc_hint; 163 | } __packed; 164 | 165 | #define MGMT_OP_REMOVE_UUID 0x0011 166 | struct mgmt_cp_remove_uuid { 167 | uint8_t uuid[16]; 168 | } __packed; 169 | 170 | struct mgmt_link_key_info { 171 | struct mgmt_addr_info addr; 172 | uint8_t type; 173 | uint8_t val[16]; 174 | uint8_t pin_len; 175 | } __packed; 176 | 177 | #define MGMT_OP_LOAD_LINK_KEYS 0x0012 178 | struct mgmt_cp_load_link_keys { 179 | uint8_t debug_keys; 180 | uint16_t key_count; 181 | struct mgmt_link_key_info keys[0]; 182 | } __packed; 183 | 184 | struct mgmt_ltk_info { 185 | struct mgmt_addr_info addr; 186 | uint8_t type; 187 | uint8_t master; 188 | uint8_t enc_size; 189 | uint16_t ediv; 190 | uint64_t rand; 191 | uint8_t val[16]; 192 | } __packed; 193 | 194 | #define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013 195 | struct mgmt_cp_load_long_term_keys { 196 | uint16_t key_count; 197 | struct mgmt_ltk_info keys[0]; 198 | } __packed; 199 | 200 | #define MGMT_OP_DISCONNECT 0x0014 201 | struct mgmt_cp_disconnect { 202 | struct mgmt_addr_info addr; 203 | } __packed; 204 | struct mgmt_rp_disconnect { 205 | struct mgmt_addr_info addr; 206 | } __packed; 207 | 208 | #define MGMT_OP_GET_CONNECTIONS 0x0015 209 | struct mgmt_rp_get_connections { 210 | uint16_t conn_count; 211 | struct mgmt_addr_info addr[0]; 212 | } __packed; 213 | 214 | #define MGMT_OP_PIN_CODE_REPLY 0x0016 215 | struct mgmt_cp_pin_code_reply { 216 | struct mgmt_addr_info addr; 217 | uint8_t pin_len; 218 | uint8_t pin_code[16]; 219 | } __packed; 220 | 221 | #define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017 222 | struct mgmt_cp_pin_code_neg_reply { 223 | struct mgmt_addr_info addr; 224 | } __packed; 225 | 226 | #define MGMT_OP_SET_IO_CAPABILITY 0x0018 227 | struct mgmt_cp_set_io_capability { 228 | uint8_t io_capability; 229 | } __packed; 230 | 231 | #define MGMT_OP_PAIR_DEVICE 0x0019 232 | struct mgmt_cp_pair_device { 233 | struct mgmt_addr_info addr; 234 | uint8_t io_cap; 235 | } __packed; 236 | struct mgmt_rp_pair_device { 237 | struct mgmt_addr_info addr; 238 | } __packed; 239 | 240 | #define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A 241 | 242 | #define MGMT_OP_UNPAIR_DEVICE 0x001B 243 | struct mgmt_cp_unpair_device { 244 | struct mgmt_addr_info addr; 245 | uint8_t disconnect; 246 | } __packed; 247 | struct mgmt_rp_unpair_device { 248 | struct mgmt_addr_info addr; 249 | } __packed; 250 | 251 | #define MGMT_OP_USER_CONFIRM_REPLY 0x001C 252 | struct mgmt_cp_user_confirm_reply { 253 | struct mgmt_addr_info addr; 254 | } __packed; 255 | struct mgmt_rp_user_confirm_reply { 256 | struct mgmt_addr_info addr; 257 | } __packed; 258 | 259 | #define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D 260 | 261 | #define MGMT_OP_USER_PASSKEY_REPLY 0x001E 262 | struct mgmt_cp_user_passkey_reply { 263 | struct mgmt_addr_info addr; 264 | uint32_t passkey; 265 | } __packed; 266 | struct mgmt_rp_user_passkey_reply { 267 | struct mgmt_addr_info addr; 268 | } __packed; 269 | 270 | #define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F 271 | struct mgmt_cp_user_passkey_neg_reply { 272 | struct mgmt_addr_info addr; 273 | } __packed; 274 | 275 | #define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020 276 | struct mgmt_rp_read_local_oob_data { 277 | uint8_t hash192[16]; 278 | uint8_t rand192[16]; 279 | uint8_t hash256[16]; 280 | uint8_t rand256[16]; 281 | } __packed; 282 | 283 | #define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021 284 | struct mgmt_cp_add_remote_oob_data { 285 | struct mgmt_addr_info addr; 286 | uint8_t hash192[16]; 287 | uint8_t rand192[16]; 288 | uint8_t hash256[16]; 289 | uint8_t rand256[16]; 290 | } __packed; 291 | 292 | #define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022 293 | struct mgmt_cp_remove_remote_oob_data { 294 | struct mgmt_addr_info addr; 295 | } __packed; 296 | 297 | #define MGMT_OP_START_DISCOVERY 0x0023 298 | struct mgmt_cp_start_discovery { 299 | uint8_t type; 300 | } __packed; 301 | 302 | #define MGMT_OP_STOP_DISCOVERY 0x0024 303 | struct mgmt_cp_stop_discovery { 304 | uint8_t type; 305 | } __packed; 306 | 307 | #define MGMT_OP_CONFIRM_NAME 0x0025 308 | struct mgmt_cp_confirm_name { 309 | struct mgmt_addr_info addr; 310 | uint8_t name_known; 311 | } __packed; 312 | struct mgmt_rp_confirm_name { 313 | struct mgmt_addr_info addr; 314 | } __packed; 315 | 316 | #define MGMT_OP_BLOCK_DEVICE 0x0026 317 | struct mgmt_cp_block_device { 318 | struct mgmt_addr_info addr; 319 | } __packed; 320 | 321 | #define MGMT_OP_UNBLOCK_DEVICE 0x0027 322 | struct mgmt_cp_unblock_device { 323 | struct mgmt_addr_info addr; 324 | } __packed; 325 | 326 | #define MGMT_OP_SET_DEVICE_ID 0x0028 327 | struct mgmt_cp_set_device_id { 328 | uint16_t source; 329 | uint16_t vendor; 330 | uint16_t product; 331 | uint16_t version; 332 | } __packed; 333 | 334 | #define MGMT_OP_SET_ADVERTISING 0x0029 335 | 336 | #define MGMT_OP_SET_BREDR 0x002A 337 | 338 | #define MGMT_OP_SET_STATIC_ADDRESS 0x002B 339 | struct mgmt_cp_set_static_address { 340 | bdaddr_t bdaddr; 341 | } __packed; 342 | 343 | #define MGMT_OP_SET_SCAN_PARAMS 0x002C 344 | struct mgmt_cp_set_scan_params { 345 | uint16_t interval; 346 | uint16_t window; 347 | } __packed; 348 | 349 | #define MGMT_OP_SET_SECURE_CONN 0x002D 350 | 351 | #define MGMT_OP_SET_DEBUG_KEYS 0x002E 352 | 353 | struct mgmt_irk_info { 354 | struct mgmt_addr_info addr; 355 | uint8_t val[16]; 356 | } __packed; 357 | 358 | #define MGMT_OP_SET_PRIVACY 0x002F 359 | struct mgmt_cp_set_privacy { 360 | uint8_t privacy; 361 | uint8_t irk[16]; 362 | } __packed; 363 | 364 | #define MGMT_OP_LOAD_IRKS 0x0030 365 | struct mgmt_cp_load_irks { 366 | uint16_t irk_count; 367 | struct mgmt_irk_info irks[0]; 368 | } __packed; 369 | 370 | #define MGMT_OP_GET_CONN_INFO 0x0031 371 | struct mgmt_cp_get_conn_info { 372 | struct mgmt_addr_info addr; 373 | } __packed; 374 | struct mgmt_rp_get_conn_info { 375 | struct mgmt_addr_info addr; 376 | int8_t rssi; 377 | int8_t tx_power; 378 | int8_t max_tx_power; 379 | } __packed; 380 | 381 | #define MGMT_OP_GET_CLOCK_INFO 0x0032 382 | struct mgmt_cp_get_clock_info { 383 | struct mgmt_addr_info addr; 384 | } __packed; 385 | struct mgmt_rp_get_clock_info { 386 | struct mgmt_addr_info addr; 387 | uint32_t local_clock; 388 | uint32_t piconet_clock; 389 | uint16_t accuracy; 390 | } __packed; 391 | 392 | #define MGMT_OP_ADD_DEVICE 0x0033 393 | struct mgmt_cp_add_device { 394 | struct mgmt_addr_info addr; 395 | uint8_t action; 396 | } __packed; 397 | struct mgmt_rp_add_device { 398 | struct mgmt_addr_info addr; 399 | } __packed; 400 | 401 | #define MGMT_OP_REMOVE_DEVICE 0x0034 402 | struct mgmt_cp_remove_device { 403 | struct mgmt_addr_info addr; 404 | } __packed; 405 | struct mgmt_rp_remove_device { 406 | struct mgmt_addr_info addr; 407 | } __packed; 408 | 409 | struct mgmt_conn_param { 410 | struct mgmt_addr_info addr; 411 | uint16_t min_interval; 412 | uint16_t max_interval; 413 | uint16_t latency; 414 | uint16_t timeout; 415 | } __packed; 416 | 417 | #define MGMT_OP_LOAD_CONN_PARAM 0x0035 418 | struct mgmt_cp_load_conn_param { 419 | uint16_t param_count; 420 | struct mgmt_conn_param params[0]; 421 | } __packed; 422 | 423 | #define MGMT_OP_READ_UNCONF_INDEX_LIST 0x0036 424 | struct mgmt_rp_read_unconf_index_list { 425 | uint16_t num_controllers; 426 | uint16_t index[0]; 427 | } __packed; 428 | 429 | #define MGMT_OPTION_EXTERNAL_CONFIG 0x00000001 430 | #define MGMT_OPTION_PUBLIC_ADDRESS 0x00000002 431 | 432 | #define MGMT_OP_READ_CONFIG_INFO 0x0037 433 | struct mgmt_rp_read_config_info { 434 | uint16_t manufacturer; 435 | uint32_t supported_options; 436 | uint32_t missing_options; 437 | } __packed; 438 | 439 | #define MGMT_OP_SET_EXTERNAL_CONFIG 0x0038 440 | struct mgmt_cp_set_external_config { 441 | uint8_t config; 442 | } __packed; 443 | 444 | #define MGMT_OP_SET_PUBLIC_ADDRESS 0x0039 445 | struct mgmt_cp_set_public_address { 446 | bdaddr_t bdaddr; 447 | } __packed; 448 | 449 | #define MGMT_OP_START_SERVICE_DISCOVERY 0x003A 450 | struct mgmt_cp_start_service_discovery { 451 | uint8_t type; 452 | int8_t rssi; 453 | uint16_t uuid_count; 454 | uint8_t uuids[0][16]; 455 | } __packed; 456 | 457 | #define MGMT_OP_READ_LOCAL_OOB_EXT_DATA 0x003B 458 | struct mgmt_cp_read_local_oob_ext_data { 459 | uint8_t type; 460 | } __packed; 461 | struct mgmt_rp_read_local_oob_ext_data { 462 | uint8_t type; 463 | uint16_t eir_len; 464 | uint8_t eir[0]; 465 | } __packed; 466 | 467 | #define MGMT_OP_READ_EXT_INDEX_LIST 0x003C 468 | struct mgmt_rp_read_ext_index_list { 469 | uint16_t num_controllers; 470 | struct { 471 | uint16_t index; 472 | uint8_t type; 473 | uint8_t bus; 474 | } entry[0]; 475 | } __packed; 476 | 477 | #define MGMT_OP_READ_ADV_FEATURES 0x003D 478 | struct mgmt_rp_read_adv_features { 479 | uint32_t supported_flags; 480 | uint8_t max_adv_data_len; 481 | uint8_t max_scan_rsp_len; 482 | uint8_t max_instances; 483 | uint8_t num_instances; 484 | uint8_t instance[0]; 485 | } __packed; 486 | 487 | #define MGMT_OP_ADD_ADVERTISING 0x003E 488 | struct mgmt_cp_add_advertising { 489 | uint8_t instance; 490 | uint32_t flags; 491 | uint16_t duration; 492 | uint16_t timeout; 493 | uint8_t adv_data_len; 494 | uint8_t scan_rsp_len; 495 | uint8_t data[0]; 496 | } __packed; 497 | struct mgmt_rp_add_advertising { 498 | uint8_t instance; 499 | } __packed; 500 | 501 | #define MGMT_ADV_FLAG_CONNECTABLE (1 << 0) 502 | #define MGMT_ADV_FLAG_DISCOV (1 << 1) 503 | #define MGMT_ADV_FLAG_LIMITED_DISCOV (1 << 2) 504 | #define MGMT_ADV_FLAG_MANAGED_FLAGS (1 << 3) 505 | #define MGMT_ADV_FLAG_TX_POWER (1 << 4) 506 | #define MGMT_ADV_FLAG_APPEARANCE (1 << 5) 507 | #define MGMT_ADV_FLAG_LOCAL_NAME (1 << 6) 508 | 509 | #define MGMT_OP_REMOVE_ADVERTISING 0x003F 510 | struct mgmt_cp_remove_advertising { 511 | uint8_t instance; 512 | } __packed; 513 | #define MGMT_REMOVE_ADVERTISING_SIZE 1 514 | struct mgmt_rp_remove_advertising { 515 | uint8_t instance; 516 | } __packed; 517 | 518 | #define MGMT_OP_GET_ADV_SIZE_INFO 0x0040 519 | struct mgmt_cp_get_adv_size_info { 520 | uint8_t instance; 521 | uint32_t flags; 522 | } __packed; 523 | #define MGMT_GET_ADV_SIZE_INFO_SIZE 5 524 | struct mgmt_rp_get_adv_size_info { 525 | uint8_t instance; 526 | uint32_t flags; 527 | uint8_t max_adv_data_len; 528 | uint8_t max_scan_rsp_len; 529 | } __packed; 530 | 531 | #define MGMT_OP_START_LIMITED_DISCOVERY 0x0041 532 | 533 | #define MGMT_OP_READ_EXT_INFO 0x0042 534 | struct mgmt_rp_read_ext_info { 535 | bdaddr_t bdaddr; 536 | uint8_t version; 537 | uint16_t manufacturer; 538 | uint32_t supported_settings; 539 | uint32_t current_settings; 540 | uint16_t eir_len; 541 | uint8_t eir[0]; 542 | } __packed; 543 | 544 | #define MGMT_OP_SET_APPEARANCE 0x0043 545 | struct mgmt_cp_set_appearance { 546 | uint16_t appearance; 547 | } __packed; 548 | 549 | #define MGMT_EV_CMD_COMPLETE 0x0001 550 | struct mgmt_ev_cmd_complete { 551 | uint16_t opcode; 552 | uint8_t status; 553 | uint8_t data[0]; 554 | } __packed; 555 | 556 | #define MGMT_EV_CMD_STATUS 0x0002 557 | struct mgmt_ev_cmd_status { 558 | uint16_t opcode; 559 | uint8_t status; 560 | } __packed; 561 | 562 | #define MGMT_EV_CONTROLLER_ERROR 0x0003 563 | struct mgmt_ev_controller_error { 564 | uint8_t error_code; 565 | } __packed; 566 | 567 | #define MGMT_EV_INDEX_ADDED 0x0004 568 | 569 | #define MGMT_EV_INDEX_REMOVED 0x0005 570 | 571 | #define MGMT_EV_NEW_SETTINGS 0x0006 572 | 573 | #define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007 574 | struct mgmt_ev_class_of_dev_changed { 575 | uint8_t dev_class[3]; 576 | } __packed; 577 | 578 | #define MGMT_EV_LOCAL_NAME_CHANGED 0x0008 579 | struct mgmt_ev_local_name_changed { 580 | uint8_t name[MGMT_MAX_NAME_LENGTH]; 581 | uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH]; 582 | } __packed; 583 | 584 | #define MGMT_EV_NEW_LINK_KEY 0x0009 585 | struct mgmt_ev_new_link_key { 586 | uint8_t store_hint; 587 | struct mgmt_link_key_info key; 588 | } __packed; 589 | 590 | #define MGMT_EV_NEW_LONG_TERM_KEY 0x000A 591 | struct mgmt_ev_new_long_term_key { 592 | uint8_t store_hint; 593 | struct mgmt_ltk_info key; 594 | } __packed; 595 | 596 | #define MGMT_EV_DEVICE_CONNECTED 0x000B 597 | struct mgmt_ev_device_connected { 598 | struct mgmt_addr_info addr; 599 | uint32_t flags; 600 | uint16_t eir_len; 601 | uint8_t eir[0]; 602 | } __packed; 603 | 604 | #define MGMT_DEV_DISCONN_UNKNOWN 0x00 605 | #define MGMT_DEV_DISCONN_TIMEOUT 0x01 606 | #define MGMT_DEV_DISCONN_LOCAL_HOST 0x02 607 | #define MGMT_DEV_DISCONN_REMOTE 0x03 608 | 609 | #define MGMT_EV_DEVICE_DISCONNECTED 0x000C 610 | struct mgmt_ev_device_disconnected { 611 | struct mgmt_addr_info addr; 612 | uint8_t reason; 613 | } __packed; 614 | 615 | #define MGMT_EV_CONNECT_FAILED 0x000D 616 | struct mgmt_ev_connect_failed { 617 | struct mgmt_addr_info addr; 618 | uint8_t status; 619 | } __packed; 620 | 621 | #define MGMT_EV_PIN_CODE_REQUEST 0x000E 622 | struct mgmt_ev_pin_code_request { 623 | struct mgmt_addr_info addr; 624 | uint8_t secure; 625 | } __packed; 626 | 627 | #define MGMT_EV_USER_CONFIRM_REQUEST 0x000F 628 | struct mgmt_ev_user_confirm_request { 629 | struct mgmt_addr_info addr; 630 | uint8_t confirm_hint; 631 | uint32_t value; 632 | } __packed; 633 | 634 | #define MGMT_EV_USER_PASSKEY_REQUEST 0x0010 635 | struct mgmt_ev_user_passkey_request { 636 | struct mgmt_addr_info addr; 637 | } __packed; 638 | 639 | #define MGMT_EV_AUTH_FAILED 0x0011 640 | struct mgmt_ev_auth_failed { 641 | struct mgmt_addr_info addr; 642 | uint8_t status; 643 | } __packed; 644 | 645 | #define MGMT_DEV_FOUND_CONFIRM_NAME 0x01 646 | #define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02 647 | #define MGMT_DEV_FOUND_NOT_CONNECTABLE 0x04 648 | 649 | #define MGMT_EV_DEVICE_FOUND 0x0012 650 | struct mgmt_ev_device_found { 651 | struct mgmt_addr_info addr; 652 | int8_t rssi; 653 | uint32_t flags; 654 | uint16_t eir_len; 655 | uint8_t eir[0]; 656 | } __packed; 657 | 658 | #define MGMT_EV_DISCOVERING 0x0013 659 | struct mgmt_ev_discovering { 660 | uint8_t type; 661 | uint8_t discovering; 662 | } __packed; 663 | 664 | #define MGMT_EV_DEVICE_BLOCKED 0x0014 665 | struct mgmt_ev_device_blocked { 666 | struct mgmt_addr_info addr; 667 | } __packed; 668 | 669 | #define MGMT_EV_DEVICE_UNBLOCKED 0x0015 670 | struct mgmt_ev_device_unblocked { 671 | struct mgmt_addr_info addr; 672 | } __packed; 673 | 674 | #define MGMT_EV_DEVICE_UNPAIRED 0x0016 675 | struct mgmt_ev_device_unpaired { 676 | struct mgmt_addr_info addr; 677 | } __packed; 678 | 679 | #define MGMT_EV_PASSKEY_NOTIFY 0x0017 680 | struct mgmt_ev_passkey_notify { 681 | struct mgmt_addr_info addr; 682 | uint32_t passkey; 683 | uint8_t entered; 684 | } __packed; 685 | 686 | #define MGMT_EV_NEW_IRK 0x0018 687 | struct mgmt_ev_new_irk { 688 | uint8_t store_hint; 689 | bdaddr_t rpa; 690 | struct mgmt_irk_info key; 691 | } __packed; 692 | 693 | struct mgmt_csrk_info { 694 | struct mgmt_addr_info addr; 695 | uint8_t type; 696 | uint8_t val[16]; 697 | } __packed; 698 | 699 | #define MGMT_EV_NEW_CSRK 0x0019 700 | struct mgmt_ev_new_csrk { 701 | uint8_t store_hint; 702 | struct mgmt_csrk_info key; 703 | } __packed; 704 | 705 | #define MGMT_EV_DEVICE_ADDED 0x001a 706 | struct mgmt_ev_device_added { 707 | struct mgmt_addr_info addr; 708 | uint8_t action; 709 | } __packed; 710 | 711 | #define MGMT_EV_DEVICE_REMOVED 0x001b 712 | struct mgmt_ev_device_removed { 713 | struct mgmt_addr_info addr; 714 | } __packed; 715 | 716 | #define MGMT_EV_NEW_CONN_PARAM 0x001c 717 | struct mgmt_ev_new_conn_param { 718 | struct mgmt_addr_info addr; 719 | uint8_t store_hint; 720 | uint16_t min_interval; 721 | uint16_t max_interval; 722 | uint16_t latency; 723 | uint16_t timeout; 724 | } __packed; 725 | 726 | #define MGMT_EV_UNCONF_INDEX_ADDED 0x001d 727 | 728 | #define MGMT_EV_UNCONF_INDEX_REMOVED 0x001e 729 | 730 | #define MGMT_EV_NEW_CONFIG_OPTIONS 0x001f 731 | 732 | #define MGMT_EV_EXT_INDEX_ADDED 0x0020 733 | struct mgmt_ev_ext_index_added { 734 | uint8_t type; 735 | uint8_t bus; 736 | } __packed; 737 | 738 | #define MGMT_EV_EXT_INDEX_REMOVED 0x0021 739 | struct mgmt_ev_ext_index_removed { 740 | uint8_t type; 741 | uint8_t bus; 742 | } __packed; 743 | 744 | #define MGMT_EV_LOCAL_OOB_DATA_UPDATED 0x0022 745 | struct mgmt_ev_local_oob_data_updated { 746 | uint8_t type; 747 | uint16_t eir_len; 748 | uint8_t eir[0]; 749 | } __packed; 750 | 751 | #define MGMT_EV_ADVERTISING_ADDED 0x0023 752 | struct mgmt_ev_advertising_added { 753 | uint8_t instance; 754 | } __packed; 755 | 756 | #define MGMT_EV_ADVERTISING_REMOVED 0x0024 757 | struct mgmt_ev_advertising_removed { 758 | uint8_t instance; 759 | } __packed; 760 | 761 | #define MGMT_EV_EXT_INFO_CHANGED 0x0025 762 | struct mgmt_ev_ext_info_changed { 763 | uint16_t eir_len; 764 | uint8_t eir[0]; 765 | } __packed; 766 | 767 | static const char *mgmt_op[] = { 768 | "<0x0000>", 769 | "Read Version", 770 | "Read Commands", 771 | "Read Index List", 772 | "Read Controller Info", 773 | "Set Powered", 774 | "Set Discoverable", 775 | "Set Connectable", 776 | "Set Fast Connectable", /* 0x0008 */ 777 | "Set Bondable", 778 | "Set Link Security", 779 | "Set Secure Simple Pairing", 780 | "Set High Speed", 781 | "Set Low Energy", 782 | "Set Dev Class", 783 | "Set Local Name", 784 | "Add UUID", /* 0x0010 */ 785 | "Remove UUID", 786 | "Load Link Keys", 787 | "Load Long Term Keys", 788 | "Disconnect", 789 | "Get Connections", 790 | "PIN Code Reply", 791 | "PIN Code Neg Reply", 792 | "Set IO Capability", /* 0x0018 */ 793 | "Pair Device", 794 | "Cancel Pair Device", 795 | "Unpair Device", 796 | "User Confirm Reply", 797 | "User Confirm Neg Reply", 798 | "User Passkey Reply", 799 | "User Passkey Neg Reply", 800 | "Read Local OOB Data", /* 0x0020 */ 801 | "Add Remote OOB Data", 802 | "Remove Remove OOB Data", 803 | "Start Discovery", 804 | "Stop Discovery", 805 | "Confirm Name", 806 | "Block Device", 807 | "Unblock Device", 808 | "Set Device ID", /* 0x0028 */ 809 | "Set Advertising", 810 | "Set BR/EDR", 811 | "Set Static Address", 812 | "Set Scan Parameters", 813 | "Set Secure Connections", 814 | "Set Debug Keys", 815 | "Set Privacy", 816 | "Load Identity Resolving Keys", /* 0x0030 */ 817 | "Get Connection Information", 818 | "Get Clock Information", 819 | "Add Device", 820 | "Remove Device", 821 | "Load Connection Parameters", 822 | "Read Unconfigured Index List", 823 | "Read Controller Configuration Information", 824 | "Set External Configuration", /* 0x0038 */ 825 | "Set Public Address", 826 | "Start Service Discovery", 827 | "Read Local Out Of Band Extended Data", 828 | "Read Extended Controller Index List", 829 | "Read Advertising Features", 830 | "Add Advertising", 831 | "Remove Advertising", 832 | "Get Advertising Size Information", /* 0x0040 */ 833 | "Start Limited Discovery", 834 | "Read Extended Controller Information", 835 | "Set Appearance", 836 | }; 837 | 838 | static const char *mgmt_ev[] = { 839 | "<0x0000>", 840 | "Command Complete", 841 | "Command Status", 842 | "Controller Error", 843 | "Index Added", 844 | "Index Removed", 845 | "New Settings", 846 | "Class of Device Changed", 847 | "Local Name Changed", /* 0x0008 */ 848 | "New Link Key", 849 | "New Long Term Key", 850 | "Device Connected", 851 | "Device Disconnected", 852 | "Connect Failed", 853 | "PIN Code Request", 854 | "User Confirm Request", 855 | "User Passkey Request", /* 0x0010 */ 856 | "Authentication Failed", 857 | "Device Found", 858 | "Discovering", 859 | "Device Blocked", 860 | "Device Unblocked", 861 | "Device Unpaired", 862 | "Passkey Notify", 863 | "New Identity Resolving Key", /* 0x0018 */ 864 | "New Signature Resolving Key", 865 | "Device Added", 866 | "Device Removed", 867 | "New Connection Parameter", 868 | "Unconfigured Index Added", 869 | "Unconfigured Index Removed", 870 | "New Configuration Options", 871 | "Extended Index Added", /* 0x0020 */ 872 | "Extended Index Removed", 873 | "Local Out Of Band Extended Data Updated", 874 | "Advertising Added", 875 | "Advertising Removed", 876 | "Extended Controller Information Changed", 877 | }; 878 | 879 | static const char *mgmt_status[] = { 880 | "Success", 881 | "Unknown Command", 882 | "Not Connected", 883 | "Failed", 884 | "Connect Failed", 885 | "Authentication Failed", 886 | "Not Paired", 887 | "No Resources", 888 | "Timeout", 889 | "Already Connected", 890 | "Busy", 891 | "Rejected", 892 | "Not Supported", 893 | "Invalid Parameters", 894 | "Disconnected", 895 | "Not Powered", 896 | "Cancelled", 897 | "Invalid Index", 898 | "Blocked through rfkill", 899 | "Already Paired", 900 | "Permission Denied", 901 | }; 902 | 903 | #ifndef NELEM 904 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) 905 | #endif 906 | 907 | static inline const char *mgmt_opstr(uint16_t op) 908 | { 909 | if (op >= NELEM(mgmt_op)) 910 | return ""; 911 | return mgmt_op[op]; 912 | } 913 | 914 | static inline const char *mgmt_evstr(uint16_t ev) 915 | { 916 | if (ev >= NELEM(mgmt_ev)) 917 | return ""; 918 | return mgmt_ev[ev]; 919 | } 920 | 921 | static inline const char *mgmt_errstr(uint8_t status) 922 | { 923 | if (status >= NELEM(mgmt_status)) 924 | return ""; 925 | return mgmt_status[status]; 926 | } 927 | -------------------------------------------------------------------------------- /ble_socket/include/rfcomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __RFCOMM_H 26 | #define __RFCOMM_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include "bluetooth.h" 37 | 38 | 39 | /* RFCOMM defaults */ 40 | #define RFCOMM_DEFAULT_MTU 127 41 | 42 | #define RFCOMM_PSM 3 43 | 44 | /* RFCOMM socket address */ 45 | struct sockaddr_rc { 46 | sa_family_t rc_family; 47 | bdaddr_t rc_bdaddr; 48 | uint8_t rc_channel; 49 | }; 50 | 51 | /* RFCOMM socket options */ 52 | #define RFCOMM_CONNINFO 0x02 53 | struct rfcomm_conninfo { 54 | uint16_t hci_handle; 55 | uint8_t dev_class[3]; 56 | }; 57 | 58 | #define RFCOMM_LM 0x03 59 | #define RFCOMM_LM_MASTER 0x0001 60 | #define RFCOMM_LM_AUTH 0x0002 61 | #define RFCOMM_LM_ENCRYPT 0x0004 62 | #define RFCOMM_LM_TRUSTED 0x0008 63 | #define RFCOMM_LM_RELIABLE 0x0010 64 | #define RFCOMM_LM_SECURE 0x0020 65 | 66 | /* RFCOMM TTY support */ 67 | #define RFCOMM_MAX_DEV 256 68 | 69 | #define RFCOMMCREATEDEV _IOW('R', 200, int) 70 | #define RFCOMMRELEASEDEV _IOW('R', 201, int) 71 | #define RFCOMMGETDEVLIST _IOR('R', 210, int) 72 | #define RFCOMMGETDEVINFO _IOR('R', 211, int) 73 | 74 | struct rfcomm_dev_req { 75 | int16_t dev_id; 76 | uint32_t flags; 77 | bdaddr_t src; 78 | bdaddr_t dst; 79 | uint8_t channel; 80 | }; 81 | #define RFCOMM_REUSE_DLC 0 82 | #define RFCOMM_RELEASE_ONHUP 1 83 | #define RFCOMM_HANGUP_NOW 2 84 | #define RFCOMM_TTY_ATTACHED 3 85 | 86 | struct rfcomm_dev_info { 87 | int16_t id; 88 | uint32_t flags; 89 | uint16_t state; 90 | bdaddr_t src; 91 | bdaddr_t dst; 92 | uint8_t channel; 93 | }; 94 | 95 | struct rfcomm_dev_list_req { 96 | uint16_t dev_num; 97 | struct rfcomm_dev_info dev_info[0]; 98 | }; 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* __RFCOMM_H */ 105 | -------------------------------------------------------------------------------- /ble_socket/include/sco.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __SCO_H 26 | #define __SCO_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* SCO defaults */ 33 | #define SCO_DEFAULT_MTU 500 34 | #define SCO_DEFAULT_FLUSH_TO 0xFFFF 35 | 36 | #define SCO_CONN_TIMEOUT (HZ * 40) 37 | #define SCO_DISCONN_TIMEOUT (HZ * 2) 38 | #define SCO_CONN_IDLE_TIMEOUT (HZ * 60) 39 | 40 | /* SCO socket address */ 41 | struct sockaddr_sco { 42 | sa_family_t sco_family; 43 | bdaddr_t sco_bdaddr; 44 | }; 45 | 46 | /* set/get sockopt defines */ 47 | #define SCO_OPTIONS 0x01 48 | struct sco_options { 49 | uint16_t mtu; 50 | }; 51 | 52 | #define SCO_CONNINFO 0x02 53 | struct sco_conninfo { 54 | uint16_t hci_handle; 55 | uint8_t dev_class[3]; 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __SCO_H */ 63 | -------------------------------------------------------------------------------- /ble_socket/include/sdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2001-2002 Nokia Corporation 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * Copyright (C) 2002-2003 Stephen Crane 9 | * 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | #ifndef __SDP_H 28 | #define __SDP_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include 35 | #include "bluetooth.h" 36 | 37 | #define SDP_UNIX_PATH "/var/run/sdp" 38 | #define SDP_RESPONSE_TIMEOUT 20 39 | #define SDP_REQ_BUFFER_SIZE 2048 40 | #define SDP_RSP_BUFFER_SIZE 65535 41 | #define SDP_PDU_CHUNK_SIZE 1024 42 | 43 | /* 44 | * All definitions are based on Bluetooth Assigned Numbers 45 | * of the Bluetooth Specification 46 | */ 47 | #define SDP_PSM 0x0001 48 | 49 | /* 50 | * Protocol UUIDs 51 | */ 52 | #define SDP_UUID 0x0001 53 | #define UDP_UUID 0x0002 54 | #define RFCOMM_UUID 0x0003 55 | #define TCP_UUID 0x0004 56 | #define TCS_BIN_UUID 0x0005 57 | #define TCS_AT_UUID 0x0006 58 | #define ATT_UUID 0x0007 59 | #define OBEX_UUID 0x0008 60 | #define IP_UUID 0x0009 61 | #define FTP_UUID 0x000a 62 | #define HTTP_UUID 0x000c 63 | #define WSP_UUID 0x000e 64 | #define BNEP_UUID 0x000f 65 | #define UPNP_UUID 0x0010 66 | #define HIDP_UUID 0x0011 67 | #define HCRP_CTRL_UUID 0x0012 68 | #define HCRP_DATA_UUID 0x0014 69 | #define HCRP_NOTE_UUID 0x0016 70 | #define AVCTP_UUID 0x0017 71 | #define AVDTP_UUID 0x0019 72 | #define CMTP_UUID 0x001b 73 | #define UDI_UUID 0x001d 74 | #define MCAP_CTRL_UUID 0x001e 75 | #define MCAP_DATA_UUID 0x001f 76 | #define L2CAP_UUID 0x0100 77 | 78 | /* 79 | * Service class identifiers of standard services and service groups 80 | */ 81 | #define SDP_SERVER_SVCLASS_ID 0x1000 82 | #define BROWSE_GRP_DESC_SVCLASS_ID 0x1001 83 | #define PUBLIC_BROWSE_GROUP 0x1002 84 | #define SERIAL_PORT_SVCLASS_ID 0x1101 85 | #define LAN_ACCESS_SVCLASS_ID 0x1102 86 | #define DIALUP_NET_SVCLASS_ID 0x1103 87 | #define IRMC_SYNC_SVCLASS_ID 0x1104 88 | #define OBEX_OBJPUSH_SVCLASS_ID 0x1105 89 | #define OBEX_FILETRANS_SVCLASS_ID 0x1106 90 | #define IRMC_SYNC_CMD_SVCLASS_ID 0x1107 91 | #define HEADSET_SVCLASS_ID 0x1108 92 | #define CORDLESS_TELEPHONY_SVCLASS_ID 0x1109 93 | #define AUDIO_SOURCE_SVCLASS_ID 0x110a 94 | #define AUDIO_SINK_SVCLASS_ID 0x110b 95 | #define AV_REMOTE_TARGET_SVCLASS_ID 0x110c 96 | #define ADVANCED_AUDIO_SVCLASS_ID 0x110d 97 | #define AV_REMOTE_SVCLASS_ID 0x110e 98 | #define AV_REMOTE_CONTROLLER_SVCLASS_ID 0x110f 99 | #define INTERCOM_SVCLASS_ID 0x1110 100 | #define FAX_SVCLASS_ID 0x1111 101 | #define HEADSET_AGW_SVCLASS_ID 0x1112 102 | #define WAP_SVCLASS_ID 0x1113 103 | #define WAP_CLIENT_SVCLASS_ID 0x1114 104 | #define PANU_SVCLASS_ID 0x1115 105 | #define NAP_SVCLASS_ID 0x1116 106 | #define GN_SVCLASS_ID 0x1117 107 | #define DIRECT_PRINTING_SVCLASS_ID 0x1118 108 | #define REFERENCE_PRINTING_SVCLASS_ID 0x1119 109 | #define IMAGING_SVCLASS_ID 0x111a 110 | #define IMAGING_RESPONDER_SVCLASS_ID 0x111b 111 | #define IMAGING_ARCHIVE_SVCLASS_ID 0x111c 112 | #define IMAGING_REFOBJS_SVCLASS_ID 0x111d 113 | #define HANDSFREE_SVCLASS_ID 0x111e 114 | #define HANDSFREE_AGW_SVCLASS_ID 0x111f 115 | #define DIRECT_PRT_REFOBJS_SVCLASS_ID 0x1120 116 | #define REFLECTED_UI_SVCLASS_ID 0x1121 117 | #define BASIC_PRINTING_SVCLASS_ID 0x1122 118 | #define PRINTING_STATUS_SVCLASS_ID 0x1123 119 | #define HID_SVCLASS_ID 0x1124 120 | #define HCR_SVCLASS_ID 0x1125 121 | #define HCR_PRINT_SVCLASS_ID 0x1126 122 | #define HCR_SCAN_SVCLASS_ID 0x1127 123 | #define CIP_SVCLASS_ID 0x1128 124 | #define VIDEO_CONF_GW_SVCLASS_ID 0x1129 125 | #define UDI_MT_SVCLASS_ID 0x112a 126 | #define UDI_TA_SVCLASS_ID 0x112b 127 | #define AV_SVCLASS_ID 0x112c 128 | #define SAP_SVCLASS_ID 0x112d 129 | #define PBAP_PCE_SVCLASS_ID 0x112e 130 | #define PBAP_PSE_SVCLASS_ID 0x112f 131 | #define PBAP_SVCLASS_ID 0x1130 132 | #define MAP_MSE_SVCLASS_ID 0x1132 133 | #define MAP_MCE_SVCLASS_ID 0x1133 134 | #define MAP_SVCLASS_ID 0x1134 135 | #define GNSS_SVCLASS_ID 0x1135 136 | #define GNSS_SERVER_SVCLASS_ID 0x1136 137 | #define MPS_SC_SVCLASS_ID 0x113A 138 | #define MPS_SVCLASS_ID 0x113B 139 | #define PNP_INFO_SVCLASS_ID 0x1200 140 | #define GENERIC_NETWORKING_SVCLASS_ID 0x1201 141 | #define GENERIC_FILETRANS_SVCLASS_ID 0x1202 142 | #define GENERIC_AUDIO_SVCLASS_ID 0x1203 143 | #define GENERIC_TELEPHONY_SVCLASS_ID 0x1204 144 | #define UPNP_SVCLASS_ID 0x1205 145 | #define UPNP_IP_SVCLASS_ID 0x1206 146 | #define UPNP_PAN_SVCLASS_ID 0x1300 147 | #define UPNP_LAP_SVCLASS_ID 0x1301 148 | #define UPNP_L2CAP_SVCLASS_ID 0x1302 149 | #define VIDEO_SOURCE_SVCLASS_ID 0x1303 150 | #define VIDEO_SINK_SVCLASS_ID 0x1304 151 | #define VIDEO_DISTRIBUTION_SVCLASS_ID 0x1305 152 | #define HDP_SVCLASS_ID 0x1400 153 | #define HDP_SOURCE_SVCLASS_ID 0x1401 154 | #define HDP_SINK_SVCLASS_ID 0x1402 155 | #define GENERIC_ACCESS_SVCLASS_ID 0x1800 156 | #define GENERIC_ATTRIB_SVCLASS_ID 0x1801 157 | #define APPLE_AGENT_SVCLASS_ID 0x2112 158 | 159 | /* 160 | * Standard profile descriptor identifiers; note these 161 | * may be identical to some of the service classes defined above 162 | */ 163 | #define SDP_SERVER_PROFILE_ID SDP_SERVER_SVCLASS_ID 164 | #define BROWSE_GRP_DESC_PROFILE_ID BROWSE_GRP_DESC_SVCLASS_ID 165 | #define SERIAL_PORT_PROFILE_ID SERIAL_PORT_SVCLASS_ID 166 | #define LAN_ACCESS_PROFILE_ID LAN_ACCESS_SVCLASS_ID 167 | #define DIALUP_NET_PROFILE_ID DIALUP_NET_SVCLASS_ID 168 | #define IRMC_SYNC_PROFILE_ID IRMC_SYNC_SVCLASS_ID 169 | #define OBEX_OBJPUSH_PROFILE_ID OBEX_OBJPUSH_SVCLASS_ID 170 | #define OBEX_FILETRANS_PROFILE_ID OBEX_FILETRANS_SVCLASS_ID 171 | #define IRMC_SYNC_CMD_PROFILE_ID IRMC_SYNC_CMD_SVCLASS_ID 172 | #define HEADSET_PROFILE_ID HEADSET_SVCLASS_ID 173 | #define CORDLESS_TELEPHONY_PROFILE_ID CORDLESS_TELEPHONY_SVCLASS_ID 174 | #define AUDIO_SOURCE_PROFILE_ID AUDIO_SOURCE_SVCLASS_ID 175 | #define AUDIO_SINK_PROFILE_ID AUDIO_SINK_SVCLASS_ID 176 | #define AV_REMOTE_TARGET_PROFILE_ID AV_REMOTE_TARGET_SVCLASS_ID 177 | #define ADVANCED_AUDIO_PROFILE_ID ADVANCED_AUDIO_SVCLASS_ID 178 | #define AV_REMOTE_PROFILE_ID AV_REMOTE_SVCLASS_ID 179 | #define INTERCOM_PROFILE_ID INTERCOM_SVCLASS_ID 180 | #define FAX_PROFILE_ID FAX_SVCLASS_ID 181 | #define HEADSET_AGW_PROFILE_ID HEADSET_AGW_SVCLASS_ID 182 | #define WAP_PROFILE_ID WAP_SVCLASS_ID 183 | #define WAP_CLIENT_PROFILE_ID WAP_CLIENT_SVCLASS_ID 184 | #define PANU_PROFILE_ID PANU_SVCLASS_ID 185 | #define NAP_PROFILE_ID NAP_SVCLASS_ID 186 | #define GN_PROFILE_ID GN_SVCLASS_ID 187 | #define DIRECT_PRINTING_PROFILE_ID DIRECT_PRINTING_SVCLASS_ID 188 | #define REFERENCE_PRINTING_PROFILE_ID REFERENCE_PRINTING_SVCLASS_ID 189 | #define IMAGING_PROFILE_ID IMAGING_SVCLASS_ID 190 | #define IMAGING_RESPONDER_PROFILE_ID IMAGING_RESPONDER_SVCLASS_ID 191 | #define IMAGING_ARCHIVE_PROFILE_ID IMAGING_ARCHIVE_SVCLASS_ID 192 | #define IMAGING_REFOBJS_PROFILE_ID IMAGING_REFOBJS_SVCLASS_ID 193 | #define HANDSFREE_PROFILE_ID HANDSFREE_SVCLASS_ID 194 | #define HANDSFREE_AGW_PROFILE_ID HANDSFREE_AGW_SVCLASS_ID 195 | #define DIRECT_PRT_REFOBJS_PROFILE_ID DIRECT_PRT_REFOBJS_SVCLASS_ID 196 | #define REFLECTED_UI_PROFILE_ID REFLECTED_UI_SVCLASS_ID 197 | #define BASIC_PRINTING_PROFILE_ID BASIC_PRINTING_SVCLASS_ID 198 | #define PRINTING_STATUS_PROFILE_ID PRINTING_STATUS_SVCLASS_ID 199 | #define HID_PROFILE_ID HID_SVCLASS_ID 200 | #define HCR_PROFILE_ID HCR_SCAN_SVCLASS_ID 201 | #define HCR_PRINT_PROFILE_ID HCR_PRINT_SVCLASS_ID 202 | #define HCR_SCAN_PROFILE_ID HCR_SCAN_SVCLASS_ID 203 | #define CIP_PROFILE_ID CIP_SVCLASS_ID 204 | #define VIDEO_CONF_GW_PROFILE_ID VIDEO_CONF_GW_SVCLASS_ID 205 | #define UDI_MT_PROFILE_ID UDI_MT_SVCLASS_ID 206 | #define UDI_TA_PROFILE_ID UDI_TA_SVCLASS_ID 207 | #define AV_PROFILE_ID AV_SVCLASS_ID 208 | #define SAP_PROFILE_ID SAP_SVCLASS_ID 209 | #define PBAP_PCE_PROFILE_ID PBAP_PCE_SVCLASS_ID 210 | #define PBAP_PSE_PROFILE_ID PBAP_PSE_SVCLASS_ID 211 | #define PBAP_PROFILE_ID PBAP_SVCLASS_ID 212 | #define MAP_PROFILE_ID MAP_SVCLASS_ID 213 | #define PNP_INFO_PROFILE_ID PNP_INFO_SVCLASS_ID 214 | #define GENERIC_NETWORKING_PROFILE_ID GENERIC_NETWORKING_SVCLASS_ID 215 | #define GENERIC_FILETRANS_PROFILE_ID GENERIC_FILETRANS_SVCLASS_ID 216 | #define GENERIC_AUDIO_PROFILE_ID GENERIC_AUDIO_SVCLASS_ID 217 | #define GENERIC_TELEPHONY_PROFILE_ID GENERIC_TELEPHONY_SVCLASS_ID 218 | #define UPNP_PROFILE_ID UPNP_SVCLASS_ID 219 | #define UPNP_IP_PROFILE_ID UPNP_IP_SVCLASS_ID 220 | #define UPNP_PAN_PROFILE_ID UPNP_PAN_SVCLASS_ID 221 | #define UPNP_LAP_PROFILE_ID UPNP_LAP_SVCLASS_ID 222 | #define UPNP_L2CAP_PROFILE_ID UPNP_L2CAP_SVCLASS_ID 223 | #define VIDEO_SOURCE_PROFILE_ID VIDEO_SOURCE_SVCLASS_ID 224 | #define VIDEO_SINK_PROFILE_ID VIDEO_SINK_SVCLASS_ID 225 | #define VIDEO_DISTRIBUTION_PROFILE_ID VIDEO_DISTRIBUTION_SVCLASS_ID 226 | #define HDP_PROFILE_ID HDP_SVCLASS_ID 227 | #define HDP_SOURCE_PROFILE_ID HDP_SOURCE_SVCLASS_ID 228 | #define HDP_SINK_PROFILE_ID HDP_SINK_SVCLASS_ID 229 | #define GENERIC_ACCESS_PROFILE_ID GENERIC_ACCESS_SVCLASS_ID 230 | #define GENERIC_ATTRIB_PROFILE_ID GENERIC_ATTRIB_SVCLASS_ID 231 | #define APPLE_AGENT_PROFILE_ID APPLE_AGENT_SVCLASS_ID 232 | #define MPS_PROFILE_ID MPS_SC_SVCLASS_ID 233 | 234 | /* 235 | * Compatibility macros for the old MDP acronym 236 | */ 237 | #define MDP_SVCLASS_ID HDP_SVCLASS_ID 238 | #define MDP_SOURCE_SVCLASS_ID HDP_SOURCE_SVCLASS_ID 239 | #define MDP_SINK_SVCLASS_ID HDP_SINK_SVCLASS_ID 240 | #define MDP_PROFILE_ID HDP_PROFILE_ID 241 | #define MDP_SOURCE_PROFILE_ID HDP_SOURCE_PROFILE_ID 242 | #define MDP_SINK_PROFILE_ID HDP_SINK_PROFILE_ID 243 | 244 | /* 245 | * Attribute identifier codes 246 | */ 247 | #define SDP_SERVER_RECORD_HANDLE 0x0000 248 | 249 | /* 250 | * Possible values for attribute-id are listed below. 251 | * See SDP Spec, section "Service Attribute Definitions" for more details. 252 | */ 253 | #define SDP_ATTR_RECORD_HANDLE 0x0000 254 | #define SDP_ATTR_SVCLASS_ID_LIST 0x0001 255 | #define SDP_ATTR_RECORD_STATE 0x0002 256 | #define SDP_ATTR_SERVICE_ID 0x0003 257 | #define SDP_ATTR_PROTO_DESC_LIST 0x0004 258 | #define SDP_ATTR_BROWSE_GRP_LIST 0x0005 259 | #define SDP_ATTR_LANG_BASE_ATTR_ID_LIST 0x0006 260 | #define SDP_ATTR_SVCINFO_TTL 0x0007 261 | #define SDP_ATTR_SERVICE_AVAILABILITY 0x0008 262 | #define SDP_ATTR_PFILE_DESC_LIST 0x0009 263 | #define SDP_ATTR_DOC_URL 0x000a 264 | #define SDP_ATTR_CLNT_EXEC_URL 0x000b 265 | #define SDP_ATTR_ICON_URL 0x000c 266 | #define SDP_ATTR_ADD_PROTO_DESC_LIST 0x000d 267 | 268 | #define SDP_ATTR_GROUP_ID 0x0200 269 | #define SDP_ATTR_IP_SUBNET 0x0200 270 | #define SDP_ATTR_VERSION_NUM_LIST 0x0200 271 | #define SDP_ATTR_SUPPORTED_FEATURES_LIST 0x0200 272 | #define SDP_ATTR_GOEP_L2CAP_PSM 0x0200 273 | #define SDP_ATTR_SVCDB_STATE 0x0201 274 | 275 | #define SDP_ATTR_MPSD_SCENARIOS 0x0200 276 | #define SDP_ATTR_MPMD_SCENARIOS 0x0201 277 | #define SDP_ATTR_MPS_DEPENDENCIES 0x0202 278 | 279 | #define SDP_ATTR_SERVICE_VERSION 0x0300 280 | #define SDP_ATTR_EXTERNAL_NETWORK 0x0301 281 | #define SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301 282 | #define SDP_ATTR_DATA_EXCHANGE_SPEC 0x0301 283 | #define SDP_ATTR_NETWORK 0x0301 284 | #define SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302 285 | #define SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 286 | #define SDP_ATTR_MCAP_SUPPORTED_PROCEDURES 0x0302 287 | #define SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303 288 | #define SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303 289 | #define SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304 290 | #define SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305 291 | #define SDP_ATTR_NETWORK_ADDRESS 0x0306 292 | #define SDP_ATTR_WAP_GATEWAY 0x0307 293 | #define SDP_ATTR_HOMEPAGE_URL 0x0308 294 | #define SDP_ATTR_WAP_STACK_TYPE 0x0309 295 | #define SDP_ATTR_SECURITY_DESC 0x030a 296 | #define SDP_ATTR_NET_ACCESS_TYPE 0x030b 297 | #define SDP_ATTR_MAX_NET_ACCESSRATE 0x030c 298 | #define SDP_ATTR_IP4_SUBNET 0x030d 299 | #define SDP_ATTR_IP6_SUBNET 0x030e 300 | #define SDP_ATTR_SUPPORTED_CAPABILITIES 0x0310 301 | #define SDP_ATTR_SUPPORTED_FEATURES 0x0311 302 | #define SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312 303 | #define SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313 304 | #define SDP_ATTR_SUPPORTED_REPOSITORIES 0x0314 305 | #define SDP_ATTR_MAS_INSTANCE_ID 0x0315 306 | #define SDP_ATTR_SUPPORTED_MESSAGE_TYPES 0x0316 307 | #define SDP_ATTR_PBAP_SUPPORTED_FEATURES 0x0317 308 | #define SDP_ATTR_MAP_SUPPORTED_FEATURES 0x0317 309 | 310 | #define SDP_ATTR_SPECIFICATION_ID 0x0200 311 | #define SDP_ATTR_VENDOR_ID 0x0201 312 | #define SDP_ATTR_PRODUCT_ID 0x0202 313 | #define SDP_ATTR_VERSION 0x0203 314 | #define SDP_ATTR_PRIMARY_RECORD 0x0204 315 | #define SDP_ATTR_VENDOR_ID_SOURCE 0x0205 316 | 317 | #define SDP_ATTR_HID_DEVICE_RELEASE_NUMBER 0x0200 318 | #define SDP_ATTR_HID_PARSER_VERSION 0x0201 319 | #define SDP_ATTR_HID_DEVICE_SUBCLASS 0x0202 320 | #define SDP_ATTR_HID_COUNTRY_CODE 0x0203 321 | #define SDP_ATTR_HID_VIRTUAL_CABLE 0x0204 322 | #define SDP_ATTR_HID_RECONNECT_INITIATE 0x0205 323 | #define SDP_ATTR_HID_DESCRIPTOR_LIST 0x0206 324 | #define SDP_ATTR_HID_LANG_ID_BASE_LIST 0x0207 325 | #define SDP_ATTR_HID_SDP_DISABLE 0x0208 326 | #define SDP_ATTR_HID_BATTERY_POWER 0x0209 327 | #define SDP_ATTR_HID_REMOTE_WAKEUP 0x020a 328 | #define SDP_ATTR_HID_PROFILE_VERSION 0x020b 329 | #define SDP_ATTR_HID_SUPERVISION_TIMEOUT 0x020c 330 | #define SDP_ATTR_HID_NORMALLY_CONNECTABLE 0x020d 331 | #define SDP_ATTR_HID_BOOT_DEVICE 0x020e 332 | 333 | /* 334 | * These identifiers are based on the SDP spec stating that 335 | * "base attribute id of the primary (universal) language must be 0x0100" 336 | * 337 | * Other languages should have their own offset; e.g.: 338 | * #define XXXLangBase yyyy 339 | * #define AttrServiceName_XXX 0x0000+XXXLangBase 340 | */ 341 | #define SDP_PRIMARY_LANG_BASE 0x0100 342 | 343 | #define SDP_ATTR_SVCNAME_PRIMARY 0x0000 + SDP_PRIMARY_LANG_BASE 344 | #define SDP_ATTR_SVCDESC_PRIMARY 0x0001 + SDP_PRIMARY_LANG_BASE 345 | #define SDP_ATTR_PROVNAME_PRIMARY 0x0002 + SDP_PRIMARY_LANG_BASE 346 | 347 | /* 348 | * The Data representation in SDP PDUs (pps 339, 340 of BT SDP Spec) 349 | * These are the exact data type+size descriptor values 350 | * that go into the PDU buffer. 351 | * 352 | * The datatype (leading 5bits) + size descriptor (last 3 bits) 353 | * is 8 bits. The size descriptor is critical to extract the 354 | * right number of bytes for the data value from the PDU. 355 | * 356 | * For most basic types, the datatype+size descriptor is 357 | * straightforward. However for constructed types and strings, 358 | * the size of the data is in the next "n" bytes following the 359 | * 8 bits (datatype+size) descriptor. Exactly what the "n" is 360 | * specified in the 3 bits of the data size descriptor. 361 | * 362 | * TextString and URLString can be of size 2^{8, 16, 32} bytes 363 | * DataSequence and DataSequenceAlternates can be of size 2^{8, 16, 32} 364 | * The size are computed post-facto in the API and are not known apriori 365 | */ 366 | #define SDP_DATA_NIL 0x00 367 | #define SDP_UINT8 0x08 368 | #define SDP_UINT16 0x09 369 | #define SDP_UINT32 0x0A 370 | #define SDP_UINT64 0x0B 371 | #define SDP_UINT128 0x0C 372 | #define SDP_INT8 0x10 373 | #define SDP_INT16 0x11 374 | #define SDP_INT32 0x12 375 | #define SDP_INT64 0x13 376 | #define SDP_INT128 0x14 377 | #define SDP_UUID_UNSPEC 0x18 378 | #define SDP_UUID16 0x19 379 | #define SDP_UUID32 0x1A 380 | #define SDP_UUID128 0x1C 381 | #define SDP_TEXT_STR_UNSPEC 0x20 382 | #define SDP_TEXT_STR8 0x25 383 | #define SDP_TEXT_STR16 0x26 384 | #define SDP_TEXT_STR32 0x27 385 | #define SDP_BOOL 0x28 386 | #define SDP_SEQ_UNSPEC 0x30 387 | #define SDP_SEQ8 0x35 388 | #define SDP_SEQ16 0x36 389 | #define SDP_SEQ32 0x37 390 | #define SDP_ALT_UNSPEC 0x38 391 | #define SDP_ALT8 0x3D 392 | #define SDP_ALT16 0x3E 393 | #define SDP_ALT32 0x3F 394 | #define SDP_URL_STR_UNSPEC 0x40 395 | #define SDP_URL_STR8 0x45 396 | #define SDP_URL_STR16 0x46 397 | #define SDP_URL_STR32 0x47 398 | 399 | /* 400 | * The PDU identifiers of SDP packets between client and server 401 | */ 402 | #define SDP_ERROR_RSP 0x01 403 | #define SDP_SVC_SEARCH_REQ 0x02 404 | #define SDP_SVC_SEARCH_RSP 0x03 405 | #define SDP_SVC_ATTR_REQ 0x04 406 | #define SDP_SVC_ATTR_RSP 0x05 407 | #define SDP_SVC_SEARCH_ATTR_REQ 0x06 408 | #define SDP_SVC_SEARCH_ATTR_RSP 0x07 409 | 410 | /* 411 | * Some additions to support service registration. 412 | * These are outside the scope of the Bluetooth specification 413 | */ 414 | #define SDP_SVC_REGISTER_REQ 0x75 415 | #define SDP_SVC_REGISTER_RSP 0x76 416 | #define SDP_SVC_UPDATE_REQ 0x77 417 | #define SDP_SVC_UPDATE_RSP 0x78 418 | #define SDP_SVC_REMOVE_REQ 0x79 419 | #define SDP_SVC_REMOVE_RSP 0x80 420 | 421 | /* 422 | * SDP Error codes 423 | */ 424 | #define SDP_INVALID_VERSION 0x0001 425 | #define SDP_INVALID_RECORD_HANDLE 0x0002 426 | #define SDP_INVALID_SYNTAX 0x0003 427 | #define SDP_INVALID_PDU_SIZE 0x0004 428 | #define SDP_INVALID_CSTATE 0x0005 429 | 430 | /* 431 | * SDP PDU 432 | */ 433 | typedef struct { 434 | uint8_t pdu_id; 435 | uint16_t tid; 436 | uint16_t plen; 437 | } __attribute__ ((packed)) sdp_pdu_hdr_t; 438 | 439 | /* 440 | * Common definitions for attributes in the SDP. 441 | * Should the type of any of these change, you need only make a change here. 442 | */ 443 | 444 | typedef struct { 445 | uint8_t type; 446 | union { 447 | uint16_t uuid16; 448 | uint32_t uuid32; 449 | uint128_t uuid128; 450 | } value; 451 | } uuid_t; 452 | 453 | #define SDP_IS_UUID(x) ((x) == SDP_UUID16 || (x) == SDP_UUID32 || \ 454 | (x) == SDP_UUID128) 455 | #define SDP_IS_ALT(x) ((x) == SDP_ALT8 || (x) == SDP_ALT16 || (x) == SDP_ALT32) 456 | #define SDP_IS_SEQ(x) ((x) == SDP_SEQ8 || (x) == SDP_SEQ16 || (x) == SDP_SEQ32) 457 | #define SDP_IS_TEXT_STR(x) ((x) == SDP_TEXT_STR8 || (x) == SDP_TEXT_STR16 || \ 458 | (x) == SDP_TEXT_STR32) 459 | 460 | typedef struct _sdp_list sdp_list_t; 461 | struct _sdp_list { 462 | sdp_list_t *next; 463 | void *data; 464 | }; 465 | 466 | /* 467 | * User-visible strings can be in many languages 468 | * in addition to the universal language. 469 | * 470 | * Language meta-data includes language code in ISO639 471 | * followed by the encoding format. The third field in this 472 | * structure is the attribute offset for the language. 473 | * User-visible strings in the specified language can be 474 | * obtained at this offset. 475 | */ 476 | typedef struct { 477 | uint16_t code_ISO639; 478 | uint16_t encoding; 479 | uint16_t base_offset; 480 | } sdp_lang_attr_t; 481 | 482 | /* 483 | * Profile descriptor is the Bluetooth profile metadata. If a 484 | * service conforms to a well-known profile, then its profile 485 | * identifier (UUID) is an attribute of the service. In addition, 486 | * if the profile has a version number it is specified here. 487 | */ 488 | typedef struct { 489 | uuid_t uuid; 490 | uint16_t version; 491 | } sdp_profile_desc_t; 492 | 493 | typedef struct { 494 | uint8_t major; 495 | uint8_t minor; 496 | } sdp_version_t; 497 | 498 | typedef struct { 499 | uint8_t *data; 500 | uint32_t data_size; 501 | uint32_t buf_size; 502 | } sdp_buf_t; 503 | 504 | typedef struct { 505 | uint32_t handle; 506 | 507 | /* Search pattern: a sequence of all UUIDs seen in this record */ 508 | sdp_list_t *pattern; 509 | sdp_list_t *attrlist; 510 | 511 | /* Main service class for Extended Inquiry Response */ 512 | uuid_t svclass; 513 | } sdp_record_t; 514 | 515 | typedef struct sdp_data_struct sdp_data_t; 516 | struct sdp_data_struct { 517 | uint8_t dtd; 518 | uint16_t attrId; 519 | union { 520 | int8_t int8; 521 | int16_t int16; 522 | int32_t int32; 523 | int64_t int64; 524 | uint128_t int128; 525 | uint8_t uint8; 526 | uint16_t uint16; 527 | uint32_t uint32; 528 | uint64_t uint64; 529 | uint128_t uint128; 530 | uuid_t uuid; 531 | char *str; 532 | sdp_data_t *dataseq; 533 | } val; 534 | sdp_data_t *next; 535 | int unitSize; 536 | }; 537 | 538 | #ifdef __cplusplus 539 | } 540 | #endif 541 | 542 | #endif /* __SDP_H */ 543 | -------------------------------------------------------------------------------- /ble_socket/include/sdp_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2001-2002 Nokia Corporation 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * Copyright (C) 2002-2003 Stephen Crane 9 | * 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | #ifndef __SDP_LIB_H 28 | #define __SDP_LIB_H 29 | 30 | #include 31 | #include "bluetooth.h" 32 | #include "hci.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define NULL ((void *)0) 39 | 40 | /* 41 | * SDP lists 42 | */ 43 | typedef void(*sdp_list_func_t)(void *, void *); 44 | typedef void(*sdp_free_func_t)(void *); 45 | typedef int (*sdp_comp_func_t)(const void *, const void *); 46 | 47 | sdp_list_t *sdp_list_append(sdp_list_t *list, void *d); 48 | sdp_list_t *sdp_list_remove(sdp_list_t *list, void *d); 49 | sdp_list_t *sdp_list_insert_sorted(sdp_list_t *list, void *data, sdp_comp_func_t f); 50 | void sdp_list_free(sdp_list_t *list, sdp_free_func_t f); 51 | 52 | static inline int sdp_list_len(const sdp_list_t *list) 53 | { 54 | int n = 0; 55 | for (; list; list = list->next) 56 | n++; 57 | return n; 58 | } 59 | 60 | static inline sdp_list_t *sdp_list_find(sdp_list_t *list, void *u, sdp_comp_func_t f) 61 | { 62 | for (; list; list = list->next) 63 | if (f(list->data, u) == 0) 64 | return list; 65 | return NULL; 66 | } 67 | 68 | static inline void sdp_list_foreach(sdp_list_t *list, sdp_list_func_t f, void *u) 69 | { 70 | for (; list; list = list->next) 71 | f(list->data, u); 72 | } 73 | 74 | /* 75 | * Values of the flags parameter to sdp_record_register 76 | */ 77 | #define SDP_RECORD_PERSIST 0x01 78 | #define SDP_DEVICE_RECORD 0x02 79 | 80 | /* 81 | * Values of the flags parameter to sdp_connect 82 | */ 83 | #define SDP_RETRY_IF_BUSY 0x01 84 | #define SDP_WAIT_ON_CLOSE 0x02 85 | #define SDP_NON_BLOCKING 0x04 86 | #define SDP_LARGE_MTU 0x08 87 | 88 | /* 89 | * a session with an SDP server 90 | */ 91 | typedef struct { 92 | int sock; 93 | int state; 94 | int local; 95 | int flags; 96 | uint16_t tid; /* Current transaction ID */ 97 | void *priv; 98 | } sdp_session_t; 99 | 100 | typedef enum { 101 | /* 102 | * Attributes are specified as individual elements 103 | */ 104 | SDP_ATTR_REQ_INDIVIDUAL = 1, 105 | /* 106 | * Attributes are specified as a range 107 | */ 108 | SDP_ATTR_REQ_RANGE 109 | } sdp_attrreq_type_t; 110 | 111 | /* 112 | * When the pdu_id(type) is a sdp error response, check the status value 113 | * to figure out the error reason. For status values 0x0001-0x0006 check 114 | * Bluetooth SPEC. If the status is 0xffff, call sdp_get_error function 115 | * to get the real reason: 116 | * - wrong transaction ID(EPROTO) 117 | * - wrong PDU id or(EPROTO) 118 | * - I/O error 119 | */ 120 | typedef void sdp_callback_t(uint8_t type, uint16_t status, uint8_t *rsp, size_t size, void *udata); 121 | 122 | /* 123 | * create an L2CAP connection to a Bluetooth device 124 | * 125 | * INPUT: 126 | * 127 | * bdaddr_t *src: 128 | * Address of the local device to use to make the connection 129 | * (or BDADDR_ANY) 130 | * 131 | * bdaddr_t *dst: 132 | * Address of the SDP server device 133 | */ 134 | sdp_session_t *sdp_connect(const bdaddr_t *src, const bdaddr_t *dst, uint32_t flags); 135 | int sdp_close(sdp_session_t *session); 136 | int sdp_get_socket(const sdp_session_t *session); 137 | 138 | /* 139 | * SDP transaction: functions for asynchronous search. 140 | */ 141 | sdp_session_t *sdp_create(int sk, uint32_t flags); 142 | int sdp_get_error(sdp_session_t *session); 143 | int sdp_process(sdp_session_t *session); 144 | int sdp_set_notify(sdp_session_t *session, sdp_callback_t *func, void *udata); 145 | 146 | int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, uint16_t max_rec_num); 147 | int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); 148 | int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *search, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); 149 | 150 | uint16_t sdp_gen_tid(sdp_session_t *session); 151 | 152 | /* 153 | * find all devices in the piconet 154 | */ 155 | int sdp_general_inquiry(inquiry_info *ii, int dev_num, int duration, uint8_t *found); 156 | 157 | /* flexible extraction of basic attributes - Jean II */ 158 | int sdp_get_int_attr(const sdp_record_t *rec, uint16_t attr, int *value); 159 | int sdp_get_string_attr(const sdp_record_t *rec, uint16_t attr, char *value, int valuelen); 160 | 161 | /* 162 | * Basic sdp data functions 163 | */ 164 | sdp_data_t *sdp_data_alloc(uint8_t dtd, const void *value); 165 | sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value, uint32_t length); 166 | void sdp_data_free(sdp_data_t *data); 167 | sdp_data_t *sdp_data_get(const sdp_record_t *rec, uint16_t attr_id); 168 | 169 | sdp_data_t *sdp_seq_alloc(void **dtds, void **values, int len); 170 | sdp_data_t *sdp_seq_alloc_with_length(void **dtds, void **values, int *length, int len); 171 | sdp_data_t *sdp_seq_append(sdp_data_t *seq, sdp_data_t *data); 172 | 173 | int sdp_attr_add(sdp_record_t *rec, uint16_t attr, sdp_data_t *data); 174 | void sdp_attr_remove(sdp_record_t *rec, uint16_t attr); 175 | void sdp_attr_replace(sdp_record_t *rec, uint16_t attr, sdp_data_t *data); 176 | int sdp_set_uuidseq_attr(sdp_record_t *rec, uint16_t attr, sdp_list_t *seq); 177 | int sdp_get_uuidseq_attr(const sdp_record_t *rec, uint16_t attr, sdp_list_t **seqp); 178 | 179 | /* 180 | * NOTE that none of the functions below will update the SDP server, 181 | * unless the {register, update}sdp_record_t() function is invoked. 182 | * All functions which return an integer value, return 0 on success 183 | * or -1 on failure. 184 | */ 185 | 186 | /* 187 | * Create an attribute and add it to the service record's attribute list. 188 | * This consists of the data type descriptor of the attribute, 189 | * the value of the attribute and the attribute identifier. 190 | */ 191 | int sdp_attr_add_new(sdp_record_t *rec, uint16_t attr, uint8_t dtd, const void *p); 192 | 193 | /* 194 | * Set the information attributes of the service record. 195 | * The set of attributes comprises service name, description 196 | * and provider name 197 | */ 198 | void sdp_set_info_attr(sdp_record_t *rec, const char *name, const char *prov, const char *desc); 199 | 200 | /* 201 | * Set the ServiceClassID attribute to the sequence specified by seq. 202 | * Note that the identifiers need to be in sorted order from the most 203 | * specific to the most generic service class that this service 204 | * conforms to. 205 | */ 206 | static inline int sdp_set_service_classes(sdp_record_t *rec, sdp_list_t *seq) 207 | { 208 | return sdp_set_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seq); 209 | } 210 | 211 | /* 212 | * Get the service classes to which the service conforms. 213 | * 214 | * When set, the list contains elements of ServiceClassIdentifer(uint16_t) 215 | * ordered from most specific to most generic 216 | */ 217 | static inline int sdp_get_service_classes(const sdp_record_t *rec, sdp_list_t **seqp) 218 | { 219 | return sdp_get_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seqp); 220 | } 221 | 222 | /* 223 | * Set the BrowseGroupList attribute to the list specified by seq. 224 | * 225 | * A service can belong to one or more service groups 226 | * and the list comprises such group identifiers (UUIDs) 227 | */ 228 | static inline int sdp_set_browse_groups(sdp_record_t *rec, sdp_list_t *seq) 229 | { 230 | return sdp_set_uuidseq_attr(rec, SDP_ATTR_BROWSE_GRP_LIST, seq); 231 | } 232 | 233 | /* 234 | * Set the access protocols of the record to those specified in proto 235 | */ 236 | int sdp_set_access_protos(sdp_record_t *rec, const sdp_list_t *proto); 237 | 238 | /* 239 | * Set the additional access protocols of the record to those specified in proto 240 | */ 241 | int sdp_set_add_access_protos(sdp_record_t *rec, const sdp_list_t *proto); 242 | 243 | /* 244 | * Get protocol port (i.e. PSM for L2CAP, Channel for RFCOMM) 245 | */ 246 | int sdp_get_proto_port(const sdp_list_t *list, int proto); 247 | 248 | /* 249 | * Get protocol descriptor. 250 | */ 251 | sdp_data_t *sdp_get_proto_desc(sdp_list_t *list, int proto); 252 | 253 | /* 254 | * Set the LanguageBase attributes to the values specified in list 255 | * (a linked list of sdp_lang_attr_t objects, one for each language in 256 | * which user-visible attributes are present). 257 | */ 258 | int sdp_set_lang_attr(sdp_record_t *rec, const sdp_list_t *list); 259 | 260 | /* 261 | * Set the ServiceInfoTimeToLive attribute of the service. 262 | * This is the number of seconds that this record is guaranteed 263 | * not to change after being obtained by a client. 264 | */ 265 | static inline int sdp_set_service_ttl(sdp_record_t *rec, uint32_t ttl) 266 | { 267 | return sdp_attr_add_new(rec, SDP_ATTR_SVCINFO_TTL, SDP_UINT32, &ttl); 268 | } 269 | 270 | /* 271 | * Set the ServiceRecordState attribute of a service. This is 272 | * guaranteed to change if there is any kind of modification to 273 | * the record. 274 | */ 275 | static inline int sdp_set_record_state(sdp_record_t *rec, uint32_t state) 276 | { 277 | return sdp_attr_add_new(rec, SDP_ATTR_RECORD_STATE, SDP_UINT32, &state); 278 | } 279 | 280 | /* 281 | * Set the ServiceID attribute of a service. 282 | */ 283 | void sdp_set_service_id(sdp_record_t *rec, uuid_t uuid); 284 | 285 | /* 286 | * Set the GroupID attribute of a service 287 | */ 288 | void sdp_set_group_id(sdp_record_t *rec, uuid_t grouuuid); 289 | 290 | /* 291 | * Set the ServiceAvailability attribute of a service. 292 | * 293 | * Note that this represents the relative availability 294 | * of the service: 0x00 means completely unavailable; 295 | * 0xFF means maximum availability. 296 | */ 297 | static inline int sdp_set_service_avail(sdp_record_t *rec, uint8_t avail) 298 | { 299 | return sdp_attr_add_new(rec, SDP_ATTR_SERVICE_AVAILABILITY, SDP_UINT8, &avail); 300 | } 301 | 302 | /* 303 | * Set the profile descriptor list attribute of a record. 304 | * 305 | * Each element in the list is an object of type 306 | * sdp_profile_desc_t which is a definition of the 307 | * Bluetooth profile that this service conforms to. 308 | */ 309 | int sdp_set_profile_descs(sdp_record_t *rec, const sdp_list_t *desc); 310 | 311 | /* 312 | * Set URL attributes of a record. 313 | * 314 | * ClientExecutableURL: a URL to a client's platform specific (WinCE, 315 | * PalmOS) executable code that can be used to access this service. 316 | * 317 | * DocumentationURL: a URL pointing to service documentation 318 | * 319 | * IconURL: a URL to an icon that can be used to represent this service. 320 | * 321 | * Note: pass NULL for any URLs that you don't want to set or remove 322 | */ 323 | void sdp_set_url_attr(sdp_record_t *rec, const char *clientExecURL, const char *docURL, const char *iconURL); 324 | 325 | /* 326 | * a service search request. 327 | * 328 | * INPUT : 329 | * 330 | * sdp_list_t *search 331 | * list containing elements of the search 332 | * pattern. Each entry in the list is a UUID 333 | * of the service to be searched 334 | * 335 | * uint16_t max_rec_num 336 | * An integer specifying the maximum number of 337 | * entries that the client can handle in the response. 338 | * 339 | * OUTPUT : 340 | * 341 | * int return value 342 | * 0 343 | * The request completed successfully. This does not 344 | * mean the requested services were found 345 | * -1 346 | * The request completed unsuccessfully 347 | * 348 | * sdp_list_t *rsp_list 349 | * This variable is set on a successful return if there are 350 | * non-zero service handles. It is a singly linked list of 351 | * service record handles (uint16_t) 352 | */ 353 | int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search, uint16_t max_rec_num, sdp_list_t **rsp_list); 354 | 355 | /* 356 | * a service attribute request. 357 | * 358 | * INPUT : 359 | * 360 | * uint32_t handle 361 | * The handle of the service for which the attribute(s) are 362 | * requested 363 | * 364 | * sdp_attrreq_type_t reqtype 365 | * Attribute identifiers are 16 bit unsigned integers specified 366 | * in one of 2 ways described below : 367 | * SDP_ATTR_REQ_INDIVIDUAL - 16bit individual identifiers 368 | * They are the actual attribute identifiers in ascending order 369 | * 370 | * SDP_ATTR_REQ_RANGE - 32bit identifier range 371 | * The high-order 16bits is the start of range 372 | * the low-order 16bits are the end of range 373 | * 0x0000 to 0xFFFF gets all attributes 374 | * 375 | * sdp_list_t *attrid_list 376 | * Singly linked list containing attribute identifiers desired. 377 | * Every element is either a uint16_t(attrSpec = SDP_ATTR_REQ_INDIVIDUAL) 378 | * or a uint32_t(attrSpec=SDP_ATTR_REQ_RANGE) 379 | * 380 | * OUTPUT : 381 | * int return value 382 | * 0 383 | * The request completed successfully. This does not 384 | * mean the requested services were found 385 | * -1 386 | * The request completed unsuccessfully due to a timeout 387 | */ 388 | sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); 389 | 390 | /* 391 | * This is a service search request combined with the service 392 | * attribute request. First a service class match is done and 393 | * for matching service, requested attributes are extracted 394 | * 395 | * INPUT : 396 | * 397 | * sdp_list_t *search 398 | * Singly linked list containing elements of the search 399 | * pattern. Each entry in the list is a UUID(DataTypeSDP_UUID16) 400 | * of the service to be searched 401 | * 402 | * AttributeSpecification attrSpec 403 | * Attribute identifiers are 16 bit unsigned integers specified 404 | * in one of 2 ways described below : 405 | * SDP_ATTR_REQ_INDIVIDUAL - 16bit individual identifiers 406 | * They are the actual attribute identifiers in ascending order 407 | * 408 | * SDP_ATTR_REQ_RANGE - 32bit identifier range 409 | * The high-order 16bits is the start of range 410 | * the low-order 16bits are the end of range 411 | * 0x0000 to 0xFFFF gets all attributes 412 | * 413 | * sdp_list_t *attrid_list 414 | * Singly linked list containing attribute identifiers desired. 415 | * Every element is either a uint16_t(attrSpec = SDP_ATTR_REQ_INDIVIDUAL) 416 | * or a uint32_t(attrSpec=SDP_ATTR_REQ_RANGE) 417 | * 418 | * OUTPUT : 419 | * int return value 420 | * 0 421 | * The request completed successfully. This does not 422 | * mean the requested services were found 423 | * -1 424 | * The request completed unsuccessfully due to a timeout 425 | * 426 | * sdp_list_t *rsp_list 427 | * This variable is set on a successful return to point to 428 | * service(s) found. Each element of this list is of type 429 | * sdp_record_t *. 430 | */ 431 | int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list, sdp_list_t **rsp_list); 432 | 433 | /* 434 | * Allocate/free a service record and its attributes 435 | */ 436 | sdp_record_t *sdp_record_alloc(void); 437 | void sdp_record_free(sdp_record_t *rec); 438 | 439 | /* 440 | * Register a service record. 441 | * 442 | * Note: It is the responsbility of the Service Provider to create the 443 | * record first and set its attributes using setXXX() methods. 444 | * 445 | * The service provider must then call sdp_record_register() to make 446 | * the service record visible to SDP clients. This function returns 0 447 | * on success or -1 on failure (and sets errno). 448 | */ 449 | int sdp_device_record_register_binary(sdp_session_t *session, bdaddr_t *device, uint8_t *data, uint32_t size, uint8_t flags, uint32_t *handle); 450 | int sdp_device_record_register(sdp_session_t *session, bdaddr_t *device, sdp_record_t *rec, uint8_t flags); 451 | int sdp_record_register(sdp_session_t *session, sdp_record_t *rec, uint8_t flags); 452 | 453 | /* 454 | * Unregister a service record. 455 | */ 456 | int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device, uint32_t handle); 457 | int sdp_device_record_unregister(sdp_session_t *session, bdaddr_t *device, sdp_record_t *rec); 458 | int sdp_record_unregister(sdp_session_t *session, sdp_record_t *rec); 459 | 460 | /* 461 | * Update an existing service record. (Calling this function 462 | * before a previous call to sdp_record_register() will result 463 | * in an error.) 464 | */ 465 | int sdp_device_record_update_binary(sdp_session_t *session, bdaddr_t *device, uint32_t handle, uint8_t *data, uint32_t size); 466 | int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp_record_t *rec); 467 | int sdp_record_update(sdp_session_t *sess, const sdp_record_t *rec); 468 | 469 | void sdp_record_print(const sdp_record_t *rec); 470 | 471 | /* 472 | * UUID functions 473 | */ 474 | uuid_t *sdp_uuid16_create(uuid_t *uuid, uint16_t data); 475 | uuid_t *sdp_uuid32_create(uuid_t *uuid, uint32_t data); 476 | uuid_t *sdp_uuid128_create(uuid_t *uuid, const void *data); 477 | int sdp_uuid16_cmp(const void *p1, const void *p2); 478 | int sdp_uuid128_cmp(const void *p1, const void *p2); 479 | int sdp_uuid_cmp(const void *p1, const void *p2); 480 | uuid_t *sdp_uuid_to_uuid128(const uuid_t *uuid); 481 | void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16); 482 | void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32); 483 | int sdp_uuid128_to_uuid(uuid_t *uuid); 484 | int sdp_uuid_to_proto(uuid_t *uuid); 485 | int sdp_uuid_extract(const uint8_t *buffer, int bufsize, uuid_t *uuid, int *scanned); 486 | void sdp_uuid_print(const uuid_t *uuid); 487 | 488 | #define MAX_LEN_UUID_STR 37 489 | #define MAX_LEN_PROTOCOL_UUID_STR 8 490 | #define MAX_LEN_SERVICECLASS_UUID_STR 28 491 | #define MAX_LEN_PROFILEDESCRIPTOR_UUID_STR 28 492 | 493 | int sdp_uuid2strn(const uuid_t *uuid, char *str, size_t n); 494 | int sdp_proto_uuid2strn(const uuid_t *uuid, char *str, size_t n); 495 | int sdp_svclass_uuid2strn(const uuid_t *uuid, char *str, size_t n); 496 | int sdp_profile_uuid2strn(const uuid_t *uuid, char *str, size_t n); 497 | 498 | /* 499 | * In all the sdp_get_XXX(handle, XXX *xxx) functions below, 500 | * the XXX * is set to point to the value, should it exist 501 | * and 0 is returned. If the value does not exist, -1 is 502 | * returned and errno set to ENODATA. 503 | * 504 | * In all the methods below, the memory management rules are 505 | * simple. Don't free anything! The pointer returned, in the 506 | * case of constructed types, is a pointer to the contents 507 | * of the sdp_record_t. 508 | */ 509 | 510 | /* 511 | * Get the access protocols from the service record 512 | */ 513 | int sdp_get_access_protos(const sdp_record_t *rec, sdp_list_t **protos); 514 | 515 | /* 516 | * Get the additional access protocols from the service record 517 | */ 518 | int sdp_get_add_access_protos(const sdp_record_t *rec, sdp_list_t **protos); 519 | 520 | /* 521 | * Extract the list of browse groups to which the service belongs. 522 | * When set, seqp contains elements of GroupID (uint16_t) 523 | */ 524 | static inline int sdp_get_browse_groups(const sdp_record_t *rec, sdp_list_t **seqp) 525 | { 526 | return sdp_get_uuidseq_attr(rec, SDP_ATTR_BROWSE_GRP_LIST, seqp); 527 | } 528 | 529 | /* 530 | * Extract language attribute meta-data of the service record. 531 | * For each language in the service record, LangSeq has a struct of type 532 | * sdp_lang_attr_t. 533 | */ 534 | int sdp_get_lang_attr(const sdp_record_t *rec, sdp_list_t **langSeq); 535 | 536 | /* 537 | * Extract the Bluetooth profile descriptor sequence from a record. 538 | * Each element in the list is of type sdp_profile_desc_t 539 | * which contains the UUID of the profile and its version number 540 | * (encoded as major and minor in the high-order 8bits 541 | * and low-order 8bits respectively of the uint16_t) 542 | */ 543 | int sdp_get_profile_descs(const sdp_record_t *rec, sdp_list_t **profDesc); 544 | 545 | /* 546 | * Extract SDP server version numbers 547 | * 548 | * Note: that this is an attribute of the SDP server only and 549 | * contains a list of uint16_t each of which represent the 550 | * major and minor SDP version numbers supported by this server 551 | */ 552 | int sdp_get_server_ver(const sdp_record_t *rec, sdp_list_t **pVnumList); 553 | 554 | int sdp_get_service_id(const sdp_record_t *rec, uuid_t *uuid); 555 | int sdp_get_group_id(const sdp_record_t *rec, uuid_t *uuid); 556 | int sdp_get_record_state(const sdp_record_t *rec, uint32_t *svcRecState); 557 | int sdp_get_service_avail(const sdp_record_t *rec, uint8_t *svcAvail); 558 | int sdp_get_service_ttl(const sdp_record_t *rec, uint32_t *svcTTLInfo); 559 | int sdp_get_database_state(const sdp_record_t *rec, uint32_t *svcDBState); 560 | 561 | static inline int sdp_get_service_name(const sdp_record_t *rec, char *str, int len) 562 | { 563 | return sdp_get_string_attr(rec, SDP_ATTR_SVCNAME_PRIMARY, str, len); 564 | } 565 | 566 | static inline int sdp_get_service_desc(const sdp_record_t *rec, char *str, int len) 567 | { 568 | return sdp_get_string_attr(rec, SDP_ATTR_SVCDESC_PRIMARY, str, len); 569 | } 570 | 571 | static inline int sdp_get_provider_name(const sdp_record_t *rec, char *str, int len) 572 | { 573 | return sdp_get_string_attr(rec, SDP_ATTR_PROVNAME_PRIMARY, str, len); 574 | } 575 | 576 | static inline int sdp_get_doc_url(const sdp_record_t *rec, char *str, int len) 577 | { 578 | return sdp_get_string_attr(rec, SDP_ATTR_DOC_URL, str, len); 579 | } 580 | 581 | static inline int sdp_get_clnt_exec_url(const sdp_record_t *rec, char *str, int len) 582 | { 583 | return sdp_get_string_attr(rec, SDP_ATTR_CLNT_EXEC_URL, str, len); 584 | } 585 | 586 | static inline int sdp_get_icon_url(const sdp_record_t *rec, char *str, int len) 587 | { 588 | return sdp_get_string_attr(rec, SDP_ATTR_ICON_URL, str, len); 589 | } 590 | 591 | /* 592 | * Set the supported features 593 | * sf should be a list of list with each feature data 594 | * Returns 0 on success -1 on fail 595 | */ 596 | int sdp_set_supp_feat(sdp_record_t *rec, const sdp_list_t *sf); 597 | 598 | /* 599 | * Get the supported features 600 | * seqp is set to a list of list with each feature data 601 | * Returns 0 on success, if an error occurred -1 is returned and errno is set 602 | */ 603 | int sdp_get_supp_feat(const sdp_record_t *rec, sdp_list_t **seqp); 604 | 605 | sdp_record_t *sdp_extract_pdu(const uint8_t *pdata, int bufsize, int *scanned); 606 | sdp_record_t *sdp_copy_record(sdp_record_t *rec); 607 | 608 | void sdp_data_print(sdp_data_t *data); 609 | void sdp_print_service_attr(sdp_list_t *alist); 610 | 611 | int sdp_attrid_comp_func(const void *key1, const void *key2); 612 | 613 | void sdp_set_seq_len(uint8_t *ptr, uint32_t length); 614 | void sdp_set_attrid(sdp_buf_t *pdu, uint16_t id); 615 | void sdp_append_to_pdu(sdp_buf_t *dst, sdp_data_t *d); 616 | void sdp_append_to_buf(sdp_buf_t *dst, uint8_t *data, uint32_t len); 617 | 618 | int sdp_gen_pdu(sdp_buf_t *pdu, sdp_data_t *data); 619 | int sdp_gen_record_pdu(const sdp_record_t *rec, sdp_buf_t *pdu); 620 | 621 | int sdp_extract_seqtype(const uint8_t *buf, int bufsize, uint8_t *dtdp, int *size); 622 | 623 | sdp_data_t *sdp_extract_attr(const uint8_t *pdata, int bufsize, int *extractedLength, sdp_record_t *rec); 624 | 625 | void sdp_pattern_add_uuid(sdp_record_t *rec, uuid_t *uuid); 626 | void sdp_pattern_add_uuidseq(sdp_record_t *rec, sdp_list_t *seq); 627 | 628 | int sdp_send_req_w4_rsp(sdp_session_t *session, uint8_t *req, uint8_t *rsp, uint32_t reqsize, uint32_t *rspsize); 629 | 630 | void sdp_add_lang_attr(sdp_record_t *rec); 631 | 632 | #ifdef __cplusplus 633 | } 634 | #endif 635 | 636 | #endif /* __SDP_LIB_H */ 637 | -------------------------------------------------------------------------------- /ble_socket/include/uuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2011 Nokia Corporation 6 | * Copyright (C) 2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __BLUETOOTH_UUID_H 26 | #define __BLUETOOTH_UUID_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | #define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb" 35 | 36 | #define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb" 37 | #define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb" 38 | 39 | #define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb" 40 | #define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb" 41 | 42 | #define ADVANCED_AUDIO_UUID "0000110d-0000-1000-8000-00805f9b34fb" 43 | 44 | #define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb" 45 | #define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb" 46 | 47 | #define AVRCP_REMOTE_UUID "0000110e-0000-1000-8000-00805f9b34fb" 48 | #define AVRCP_TARGET_UUID "0000110c-0000-1000-8000-00805f9b34fb" 49 | 50 | #define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb" 51 | #define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" 52 | #define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" 53 | #define BNEP_SVC_UUID "0000000f-0000-1000-8000-00805f9b34fb" 54 | 55 | #define PNPID_UUID "00002a50-0000-1000-8000-00805f9b34fb" 56 | #define DEVICE_INFORMATION_UUID "0000180a-0000-1000-8000-00805f9b34fb" 57 | 58 | #define GATT_UUID "00001801-0000-1000-8000-00805f9b34fb" 59 | #define IMMEDIATE_ALERT_UUID "00001802-0000-1000-8000-00805f9b34fb" 60 | #define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb" 61 | #define TX_POWER_UUID "00001804-0000-1000-8000-00805f9b34fb" 62 | #define BATTERY_UUID "0000180f-0000-1000-8000-00805f9b34fb" 63 | #define SCAN_PARAMETERS_UUID "00001813-0000-1000-8000-00805f9b34fb" 64 | 65 | #define SAP_UUID "0000112D-0000-1000-8000-00805f9b34fb" 66 | 67 | #define HEART_RATE_UUID "0000180d-0000-1000-8000-00805f9b34fb" 68 | #define HEART_RATE_MEASUREMENT_UUID "00002a37-0000-1000-8000-00805f9b34fb" 69 | #define BODY_SENSOR_LOCATION_UUID "00002a38-0000-1000-8000-00805f9b34fb" 70 | #define HEART_RATE_CONTROL_POINT_UUID "00002a39-0000-1000-8000-00805f9b34fb" 71 | 72 | #define HEALTH_THERMOMETER_UUID "00001809-0000-1000-8000-00805f9b34fb" 73 | #define TEMPERATURE_MEASUREMENT_UUID "00002a1c-0000-1000-8000-00805f9b34fb" 74 | #define TEMPERATURE_TYPE_UUID "00002a1d-0000-1000-8000-00805f9b34fb" 75 | #define INTERMEDIATE_TEMPERATURE_UUID "00002a1e-0000-1000-8000-00805f9b34fb" 76 | #define MEASUREMENT_INTERVAL_UUID "00002a21-0000-1000-8000-00805f9b34fb" 77 | 78 | #define CYCLING_SC_UUID "00001816-0000-1000-8000-00805f9b34fb" 79 | #define CSC_MEASUREMENT_UUID "00002a5b-0000-1000-8000-00805f9b34fb" 80 | #define CSC_FEATURE_UUID "00002a5c-0000-1000-8000-00805f9b34fb" 81 | #define SENSOR_LOCATION_UUID "00002a5d-0000-1000-8000-00805f9b34fb" 82 | #define SC_CONTROL_POINT_UUID "00002a55-0000-1000-8000-00805f9b34fb" 83 | 84 | #define RFCOMM_UUID_STR "00000003-0000-1000-8000-00805f9b34fb" 85 | 86 | #define HDP_UUID "00001400-0000-1000-8000-00805f9b34fb" 87 | #define HDP_SOURCE_UUID "00001401-0000-1000-8000-00805f9b34fb" 88 | #define HDP_SINK_UUID "00001402-0000-1000-8000-00805f9b34fb" 89 | 90 | #define HID_UUID "00001124-0000-1000-8000-00805f9b34fb" 91 | 92 | #define DUN_GW_UUID "00001103-0000-1000-8000-00805f9b34fb" 93 | 94 | #define GAP_UUID "00001800-0000-1000-8000-00805f9b34fb" 95 | #define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb" 96 | 97 | #define SPP_UUID "00001101-0000-1000-8000-00805f9b34fb" 98 | 99 | #define OBEX_SYNC_UUID "00001104-0000-1000-8000-00805f9b34fb" 100 | #define OBEX_OPP_UUID "00001105-0000-1000-8000-00805f9b34fb" 101 | #define OBEX_FTP_UUID "00001106-0000-1000-8000-00805f9b34fb" 102 | #define OBEX_PCE_UUID "0000112e-0000-1000-8000-00805f9b34fb" 103 | #define OBEX_PSE_UUID "0000112f-0000-1000-8000-00805f9b34fb" 104 | #define OBEX_PBAP_UUID "00001130-0000-1000-8000-00805f9b34fb" 105 | #define OBEX_MAS_UUID "00001132-0000-1000-8000-00805f9b34fb" 106 | #define OBEX_MNS_UUID "00001133-0000-1000-8000-00805f9b34fb" 107 | #define OBEX_MAP_UUID "00001134-0000-1000-8000-00805f9b34fb" 108 | 109 | /* GATT UUIDs section */ 110 | #define GATT_PRIM_SVC_UUID 0x2800 111 | #define GATT_SND_SVC_UUID 0x2801 112 | #define GATT_INCLUDE_UUID 0x2802 113 | #define GATT_CHARAC_UUID 0x2803 114 | 115 | /* GATT Characteristic Types */ 116 | #define GATT_CHARAC_DEVICE_NAME 0x2A00 117 | #define GATT_CHARAC_APPEARANCE 0x2A01 118 | #define GATT_CHARAC_PERIPHERAL_PRIV_FLAG 0x2A02 119 | #define GATT_CHARAC_RECONNECTION_ADDRESS 0x2A03 120 | #define GATT_CHARAC_PERIPHERAL_PREF_CONN 0x2A04 121 | #define GATT_CHARAC_SERVICE_CHANGED 0x2A05 122 | #define GATT_CHARAC_BATTERY_LEVEL 0x2A19 123 | #define GATT_CHARAC_SYSTEM_ID 0x2A23 124 | #define GATT_CHARAC_MODEL_NUMBER_STRING 0x2A24 125 | #define GATT_CHARAC_SERIAL_NUMBER_STRING 0x2A25 126 | #define GATT_CHARAC_FIRMWARE_REVISION_STRING 0x2A26 127 | #define GATT_CHARAC_HARDWARE_REVISION_STRING 0x2A27 128 | #define GATT_CHARAC_SOFTWARE_REVISION_STRING 0x2A28 129 | #define GATT_CHARAC_MANUFACTURER_NAME_STRING 0x2A29 130 | #define GATT_CHARAC_PNP_ID 0x2A50 131 | 132 | /* GATT Characteristic Descriptors */ 133 | #define GATT_CHARAC_EXT_PROPER_UUID 0x2900 134 | #define GATT_CHARAC_USER_DESC_UUID 0x2901 135 | #define GATT_CLIENT_CHARAC_CFG_UUID 0x2902 136 | #define GATT_SERVER_CHARAC_CFG_UUID 0x2903 137 | #define GATT_CHARAC_FMT_UUID 0x2904 138 | #define GATT_CHARAC_AGREG_FMT_UUID 0x2905 139 | #define GATT_CHARAC_VALID_RANGE_UUID 0x2906 140 | #define GATT_EXTERNAL_REPORT_REFERENCE 0x2907 141 | #define GATT_REPORT_REFERENCE 0x2908 142 | 143 | /* GATT Mesh Services */ 144 | #define MESH_PROV_SVC_UUID "00001827-0000-1000-8000-00805f9b34fb" 145 | #define MESH_PROXY_SVC_UUID "00001828-0000-1000-8000-00805f9b34fb" 146 | 147 | /* GATT Mesh Characteristic Types */ 148 | #define MESH_PROVISIONING_DATA_IN 0x2ADB 149 | #define MESH_PROVISIONING_DATA_OUT 0x2ADC 150 | #define MESH_PROXY_DATA_IN 0x2ADD 151 | #define MESH_PROXY_DATA_OUT 0x2ADE 152 | 153 | typedef struct { 154 | enum { 155 | BT_UUID_UNSPEC = 0, 156 | BT_UUID16 = 16, 157 | BT_UUID32 = 32, 158 | BT_UUID128 = 128, 159 | } type; 160 | union { 161 | uint16_t u16; 162 | uint32_t u32; 163 | uint128_t u128; 164 | } value; 165 | } bt_uuid_t; 166 | 167 | int bt_uuid_strcmp(const void *a, const void *b); 168 | 169 | int bt_uuid16_create(bt_uuid_t *btuuid, uint16_t value); 170 | int bt_uuid32_create(bt_uuid_t *btuuid, uint32_t value); 171 | int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value); 172 | 173 | int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2); 174 | void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst); 175 | 176 | #define MAX_LEN_UUID_STR 37 177 | 178 | int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n); 179 | int bt_string_to_uuid(bt_uuid_t *uuid, const char *string); 180 | 181 | int bt_uuid_to_le(const bt_uuid_t *uuid, void *dst); 182 | 183 | static inline int bt_uuid_len(const bt_uuid_t *uuid) 184 | { 185 | return uuid->type / 8; 186 | } 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | 192 | #endif /* __BLUETOOTH_UUID_H */ 193 | -------------------------------------------------------------------------------- /ble_socket/src/ble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include /* See NOTES */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | //需要编译bluez库,把头文件抠出来,并把.so库移植到板上 17 | #include "bluetooth.h" //BTPROTO_HCI 18 | #include "hci.h" //struct hci_dev_info 19 | #include "hci_lib.h" //hci_devid() 20 | #include "l2cap.h" //l2cap 21 | #include "hidp.h" //hidp 22 | #include "rfcomm.h" //rfcomm协议 23 | 24 | #define NULL ((void *) 0) 25 | 26 | //保存bt的mac地址,在下次开机和异常断开时读取上次连接的bt,自动重连 27 | #define BT_MAC_FILE "/tmp/bt_mac" 28 | 29 | unsigned int epoll_fd_num; 30 | 31 | pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER; 32 | 33 | int BTDevInit() 34 | { 35 | int ctl = -1; 36 | char cmd[100] = {0}; 37 | struct hci_dev_list_req *dl;//本地蓝牙设备表 38 | struct hci_dev_info di; // 其中某个蓝牙设备的信息,我们测试通常只插一个 39 | struct hci_dev_req *dr; 40 | static bdaddr_t locate_bdaddr; 41 | char locate_bt_mac[17] = {0};; 42 | if (!(dl = malloc(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(unsigned short)))) { 43 | perror("Can't allocate memory"); 44 | return -1; 45 | } 46 | dl->dev_num = HCI_MAX_DEV; 47 | dr = dl->dev_req; 48 | // 1.打开一个 HCI socket 49 | if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) { 50 | perror("Can't open HCI socket."); 51 | return -1; 52 | } 53 | // 2. 使用CIGETDEVLIST,得到所有dongle的Device ID。存放在dl中 54 | if (ioctl(ctl, HCIGETDEVLIST, (void *) dl) < 0) { 55 | perror("Can't get device list"); 56 | return -1; 57 | } 58 | printf("Get hci dev num:%d\n",dl->dev_num); 59 | // 3.使用CIGETDEVINFO,得到对应Device ID的Dongle信息,调试一个 60 | //di.dev_id = (dr+i)->dev_id; 61 | di.dev_id = dr->dev_id; 62 | ioctl(ctl, HCIGETDEVINFO, (void *) &di); 63 | close(ctl); 64 | if(strlen(di.name) < 3) { 65 | printf("Can't get hci device.\n"); 66 | return -1; 67 | } 68 | 69 | // 4.打开蓝牙-保留(一般不在代码打开,而是通过启动脚本,【/etc/init.d/bluetooth start】命令方式打开) 70 | /*if(ioctl(ctl, HCIDEVUP, di.dev_id) < 0) { 71 | perror("Can't enable ble device"); 72 | return -1; 73 | }*/ 74 | 75 | memcpy(&locate_bdaddr, &di.bdaddr, sizeof(bdaddr_t)); 76 | ba2str(&di.bdaddr, locate_bt_mac); 77 | printf("Locate bt hci info:\n dev_id: %d\n name: %s\n mac: %s\n", di.dev_id, di.name, locate_bt_mac); 78 | sprintf(cmd, "echo %s > "BT_MAC_FILE" \n", locate_bt_mac); 79 | system(cmd); 80 | system("sync \n"); 81 | return 0; 82 | } 83 | 84 | int BTInitSocket(void) 85 | { 86 | int socket_fd = -1,ret = -1; 87 | struct sockaddr_rc loc_addr = {0}; 88 | if(0 !=BTDevInit()) { 89 | printf("<%s,%d>liangjf: BT hardware init err[%s]\n", __func__,__LINE__, strerror(errno)); 90 | return -1; 91 | } 92 | 93 | printf("<%s,%d>liangjf: Creating socket .\n", __func__,__LINE__); 94 | socket_fd =socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 95 | if(socket_fd<0) { 96 | printf("<%s,%d>liangjf: Create socket error[%s]\n", __func__,__LINE__, strerror(errno)); 97 | return 1; 98 | } 99 | 100 | //设置socket属性,重用port端口。解决ctrl-c结束后再次启动端口复用问题 101 | int on=1; 102 | printf("<%s,%d>liangjf: set socketopt...\n", __func__,__LINE__); 103 | if(setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on))<0) { 104 | printf("<%s,%d>liangjf: set socketopt failed[%s]\n", __func__,__LINE__, strerror(errno)); 105 | return -1; 106 | } 107 | 108 | printf("<%s,%d>liangjf: socket bind...\n", __func__,__LINE__); 109 | loc_addr.rc_family = AF_BLUETOOTH; 110 | loc_addr.rc_bdaddr = *BDADDR_ANY; 111 | loc_addr.rc_channel = 1; 112 | ret = bind(socket_fd,(struct sockaddr *)&loc_addr, sizeof(loc_addr)); 113 | if(ret<0) { 114 | printf("<%s,%d>liangjf: bind socket error:ret=%d[%s]\n", __func__,__LINE__, ret, strerror(errno)); 115 | return -1; 116 | } 117 | 118 | printf("<%s,%d>liangjf: listen... \n", __func__,__LINE__); 119 | ret=listen(socket_fd, 5); 120 | if(ret<0) { 121 | printf("<%s,%d>liangjf: listen error[%s]\n", __func__,__LINE__, strerror(errno)); 122 | return -1; 123 | } 124 | //暂不设置超时,通过select设置 125 | printf("<%s,%d>liangjf: set socket opt .\n", __func__,__LINE__); 126 | struct timeval timeout = {0,10000}; 127 | if (setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval)) != 0) { 128 | printf("<%s,%d>liangjf: set socket opt failed[%s]\n", __func__,__LINE__, strerror(errno)); 129 | return -1; 130 | } 131 | 132 | printf("<%s,%d>liangjf: return socket_fd[%d]...\n", __func__,__LINE__, socket_fd); 133 | return socket_fd; 134 | } 135 | 136 | int setnonBlocking(int fd) 137 | { 138 | int old_opt = fcntl(fd, F_GETFD); 139 | int new_opt = old_opt | O_NONBLOCK; 140 | fcntl(fd, F_SETFD, new_opt); 141 | 142 | return old_opt; 143 | } 144 | 145 | /** 146 | * 在每次调用epoll_ctrl 添加一个fd,自增1. 147 | * 目的是通过一个events数组管理全部fd 148 | */ 149 | static void AddEpollfdNum() 150 | { 151 | pthread_mutex_lock(&fd_mutex); 152 | epoll_fd_num++; 153 | pthread_mutex_unlock(&fd_mutex); 154 | printf("<%s,%d>liangjf: now add one fd to epoll set\n", __func__,__LINE__); 155 | } 156 | 157 | int GetEpollNowfdNum(char *str) 158 | { 159 | int ret_fd_num = 0; 160 | pthread_mutex_lock(&fd_mutex); 161 | ret_fd_num = epoll_fd_num; 162 | pthread_mutex_unlock(&fd_mutex); 163 | printf("<%s,%d>liangjf: %s,now epoll fd num is [%d]\n", __func__,__LINE__, str, ret_fd_num); 164 | return ret_fd_num; 165 | } 166 | 167 | /** 168 | * 添加fd到epoll监听 169 | */ 170 | int epollAddfd(struct epoll_event *event, int epollfd, int fd, int enable_et) 171 | { 172 | int ret = -1; 173 | //获得现有epoll的fd的个数 174 | GetEpollNowfdNum("before add"); 175 | 176 | event->data.fd = fd; 177 | event->events = EPOLLIN | EPOLLOUT; 178 | if(enable_et) { 179 | event->events |= EPOLLET; 180 | } 181 | ret = epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, event); 182 | if ( ret < 0 ) { 183 | printf("<%s,%d>liangjf: epoll_ctl error[%s]\n", __func__,__LINE__, strerror(errno)); 184 | return 1; 185 | } 186 | //epoll的fd的个数+1 187 | AddEpollfdNum(); 188 | //获得现有epoll的fd的个数 189 | GetEpollNowfdNum("after add"); 190 | return 0; 191 | } 192 | 193 | /** 194 | * 修改epoll集合中的fd 195 | */ 196 | int epollModfd(struct epoll_event *event, int epollfd, int fd, int enable_et) 197 | { 198 | int ret = -1; 199 | //获得现有epoll的fd的个数 200 | GetEpollNowfdNum("before modify"); 201 | event->data.fd = fd; 202 | event->events = EPOLLIN | EPOLLOUT; 203 | if(enable_et) { 204 | event->events |= EPOLLET; 205 | } 206 | ret = epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, event); 207 | if ( ret < 0 ) { 208 | printf("<%s,%d>liangjf: epoll_ctl error[%s]\n", __func__,__LINE__, strerror(errno)); 209 | return 1; 210 | } 211 | 212 | //获得现有epoll的fd的个数 213 | GetEpollNowfdNum("after modify"); 214 | return 0; 215 | } 216 | 217 | /** 218 | * 删除epoll集合中的fd 219 | */ 220 | int epollDelfd(struct epoll_event *event, int epollfd, int fd, int enable_et) 221 | { 222 | int ret = -1; 223 | //获得现有epoll的fd的个数 224 | GetEpollNowfdNum("before delete"); 225 | ret = epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, NULL); 226 | if ( ret < 0 ) { 227 | printf("<%s,%d>liangjf: epoll_ctl error[%s]\n", __func__,__LINE__, strerror(errno)); 228 | } 229 | 230 | pthread_mutex_lock(&fd_mutex); 231 | epoll_fd_num--; 232 | pthread_mutex_unlock(&fd_mutex); 233 | GetEpollNowfdNum("after delete"); 234 | 235 | return 0; 236 | } 237 | 238 | /** 239 | * 删除epoll集合中的fd 240 | */ 241 | int RecvBT(int sockfd, char *r_buf, int r_len) 242 | { 243 | int ret = recv(sockfd, r_buf, r_len, 0); 244 | if(ret < 0) { 245 | printf("<%s,%d>liangjf: recv error[%s]\n", __func__,__LINE__, strerror(errno)); 246 | return -1; 247 | } else if(ret == 0) { 248 | printf("<%s,%d>liangjf: recv over[%s]\n", __func__,__LINE__, strerror(errno)); 249 | return -2; 250 | } 251 | else { 252 | printf("<%s,%d>liangjf: recv data %d-%s.\n", __func__,__LINE__, ret, r_buf); 253 | return ret; 254 | } 255 | } 256 | 257 | 258 | int SendBT(int sockfd, char *w_buf, int w_len) 259 | { 260 | int ret = send(sockfd, w_buf, w_len, 0); 261 | if(ret < 0) { 262 | printf("<%s,%d>liangjf: write error[%s]\n", __func__,__LINE__, strerror(errno)); 263 | return -1; 264 | } else if(ret < w_len) { 265 | printf("<%s,%d>liangjf: write less data[%s]\n", __func__,__LINE__, strerror(errno)); 266 | return -2; 267 | } 268 | else if(ret == w_len){ 269 | printf("<%s,%d>liangjf: write data ok %d-%s.\n", __func__,__LINE__, ret, w_buf); 270 | return ret; 271 | } 272 | return -1; 273 | } 274 | 275 | /** 276 | * 真正处理非主socket fd的fd响应 277 | */ 278 | void do_use_fd(int epollfd, struct epoll_event *event) 279 | { 280 | int ret = 0; 281 | char r_buf[1024]; 282 | memset(r_buf, 0, sizeof(r_buf)); 283 | 284 | if(event->events & EPOLLIN){ //异步通知:连接后有数据到来-读 285 | printf("<%s,%d>liangjf: has data read[EPOLLIN].\n", __func__,__LINE__); 286 | ret = RecvBT(event->data.fd, r_buf, sizeof(r_buf)); 287 | 288 | //把读到的内容写文件 289 | 290 | //读文件内容通过蓝牙回传给客户端 291 | if(ret > 0) { 292 | printf("<%s,%d>liangjf: write data[EPOLLOUT]\n", __func__,__LINE__); 293 | SendBT(event->data.fd, r_buf, ret); 294 | } 295 | 296 | //重新修改epoll的里的监听fd,异步处理精髓 297 | epollModfd(event, epollfd, event->data.fd, 1); 298 | } 299 | else if(event->events & EPOLLERR) { 300 | close(event->data.fd); 301 | printf("<%s,%d>liangjf: ble connect error[EPOLLERR]\n", __func__,__LINE__); 302 | epollDelfd(event, epollfd, event->data.fd, 1); 303 | } 304 | else if(event->events & EPOLLHUP) { 305 | close(event->data.fd); 306 | printf("<%s,%d>liangjf: ble hang up[EPOLLHUP]\n", __func__,__LINE__); 307 | epollDelfd(event, epollfd, event->data.fd, 1); 308 | } 309 | } 310 | 311 | /** 312 | *epoll监听fd 313 | */ 314 | int EpollBTorListends(struct epoll_event *event, struct epoll_event *events, int epollfd, int ret_fd_num, int listenfd) 315 | { 316 | int i = 0, ret = -1; 317 | for(i = 0; i < ret_fd_num; i++) { 318 | if(events[i].data.fd == listenfd) { //异步通知:有蓝牙连接 319 | struct sockaddr_in clientaddr; 320 | int len = sizeof(clientaddr); 321 | memset(&clientaddr, 0, sizeof(clientaddr)); 322 | 323 | //listenfd套接字准备好,客户端开始监听连接 324 | int connfd = accept(listenfd, (struct sockaddr *)&clientaddr, (socklen_t *)&len); 325 | if (connfd < 0) { 326 | printf("<%s,%d>liangjf: accept socket error[%s]\n", __func__,__LINE__, strerror(errno)); 327 | return -1; 328 | } else { 329 | printf("<%s,%d>liangjf: accept socket ok[%s]\n", __func__,__LINE__, inet_ntoa(clientaddr.sin_addr)); 330 | } 331 | 332 | ret = epollAddfd(event, epollfd, connfd, 1); //增加connfd被到epollfd监听集合中 333 | if(ret == 0) { 334 | printf("<%s,%d>liangjf: epoll Add fd ok\n", __func__,__LINE__); 335 | } 336 | } else { 337 | do_use_fd(epollfd, &events[i]); 338 | } 339 | } 340 | return 0; 341 | } 342 | -------------------------------------------------------------------------------- /ble_socket/src/bluetooth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 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 | #ifdef HAVE_CONFIG_H 27 | #include 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "bluetooth.h" 40 | #include "hci.h" 41 | 42 | #define NULL ((void *)0) 43 | 44 | void baswap(bdaddr_t *dst, const bdaddr_t *src) 45 | { 46 | register unsigned char *d = (unsigned char *) dst; 47 | register const unsigned char *s = (const unsigned char *) src; 48 | register int i; 49 | 50 | for (i = 0; i < 6; i++) 51 | d[i] = s[5-i]; 52 | } 53 | 54 | char *batostr(const bdaddr_t *ba) 55 | { 56 | char *str = bt_malloc(18); 57 | if (!str) 58 | return NULL; 59 | 60 | sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", 61 | ba->b[0], ba->b[1], ba->b[2], 62 | ba->b[3], ba->b[4], ba->b[5]); 63 | 64 | return str; 65 | } 66 | 67 | bdaddr_t *strtoba(const char *str) 68 | { 69 | bdaddr_t b; 70 | bdaddr_t *ba = bt_malloc(sizeof(*ba)); 71 | 72 | if (ba) { 73 | str2ba(str, &b); 74 | baswap(ba, &b); 75 | } 76 | 77 | return ba; 78 | } 79 | 80 | int ba2str(const bdaddr_t *ba, char *str) 81 | { 82 | return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", 83 | ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]); 84 | } 85 | 86 | int str2ba(const char *str, bdaddr_t *ba) 87 | { 88 | int i; 89 | 90 | if (bachk(str) < 0) { 91 | memset(ba, 0, sizeof(*ba)); 92 | return -1; 93 | } 94 | 95 | for (i = 5; i >= 0; i--, str += 3) 96 | ba->b[i] = strtol(str, NULL, 16); 97 | 98 | return 0; 99 | } 100 | 101 | int ba2oui(const bdaddr_t *ba, char *str) 102 | { 103 | return sprintf(str, "%2.2X-%2.2X-%2.2X", ba->b[5], ba->b[4], ba->b[3]); 104 | } 105 | 106 | int bachk(const char *str) 107 | { 108 | if (!str) 109 | return -1; 110 | 111 | if (strlen(str) != 17) 112 | return -1; 113 | 114 | while (*str) { 115 | if (!isxdigit(*str++)) 116 | return -1; 117 | 118 | if (!isxdigit(*str++)) 119 | return -1; 120 | 121 | if (*str == 0) 122 | break; 123 | 124 | if (*str++ != ':') 125 | return -1; 126 | } 127 | 128 | return 0; 129 | } 130 | 131 | int baprintf(const char *format, ...) 132 | { 133 | va_list ap; 134 | int len; 135 | 136 | va_start(ap, format); 137 | len = vprintf(format, ap); 138 | va_end(ap); 139 | 140 | return len; 141 | } 142 | 143 | int bafprintf(FILE *stream, const char *format, ...) 144 | { 145 | va_list ap; 146 | int len; 147 | 148 | va_start(ap, format); 149 | len = vfprintf(stream, format, ap); 150 | va_end(ap); 151 | 152 | return len; 153 | } 154 | 155 | int basprintf(char *str, const char *format, ...) 156 | { 157 | va_list ap; 158 | int len; 159 | 160 | va_start(ap, format); 161 | len = vsnprintf(str, (~0U) >> 1, format, ap); 162 | va_end(ap); 163 | 164 | return len; 165 | } 166 | 167 | int basnprintf(char *str, size_t size, const char *format, ...) 168 | { 169 | va_list ap; 170 | int len; 171 | 172 | va_start(ap, format); 173 | len = vsnprintf(str, size, format, ap); 174 | va_end(ap); 175 | 176 | return len; 177 | } 178 | 179 | void *bt_malloc(size_t size) 180 | { 181 | return malloc(size); 182 | } 183 | 184 | void bt_free(void *ptr) 185 | { 186 | free(ptr); 187 | } 188 | 189 | /* Bluetooth error codes to Unix errno mapping */ 190 | int bt_error(uint16_t code) 191 | { 192 | switch (code) { 193 | case 0: 194 | return 0; 195 | case HCI_UNKNOWN_COMMAND: 196 | return EBADRQC; 197 | case HCI_NO_CONNECTION: 198 | return ENOTCONN; 199 | case HCI_HARDWARE_FAILURE: 200 | return EIO; 201 | case HCI_PAGE_TIMEOUT: 202 | return EHOSTDOWN; 203 | case HCI_AUTHENTICATION_FAILURE: 204 | return EACCES; 205 | case HCI_PIN_OR_KEY_MISSING: 206 | return EINVAL; 207 | case HCI_MEMORY_FULL: 208 | return ENOMEM; 209 | case HCI_CONNECTION_TIMEOUT: 210 | return ETIMEDOUT; 211 | case HCI_MAX_NUMBER_OF_CONNECTIONS: 212 | case HCI_MAX_NUMBER_OF_SCO_CONNECTIONS: 213 | return EMLINK; 214 | case HCI_ACL_CONNECTION_EXISTS: 215 | return EALREADY; 216 | case HCI_COMMAND_DISALLOWED: 217 | case HCI_TRANSACTION_COLLISION: 218 | case HCI_ROLE_SWITCH_PENDING: 219 | return EBUSY; 220 | case HCI_REJECTED_LIMITED_RESOURCES: 221 | case HCI_REJECTED_PERSONAL: 222 | case HCI_QOS_REJECTED: 223 | return ECONNREFUSED; 224 | case HCI_HOST_TIMEOUT: 225 | return ETIMEDOUT; 226 | case HCI_UNSUPPORTED_FEATURE: 227 | case HCI_QOS_NOT_SUPPORTED: 228 | case HCI_PAIRING_NOT_SUPPORTED: 229 | case HCI_CLASSIFICATION_NOT_SUPPORTED: 230 | case HCI_UNSUPPORTED_LMP_PARAMETER_VALUE: 231 | case HCI_PARAMETER_OUT_OF_RANGE: 232 | case HCI_QOS_UNACCEPTABLE_PARAMETER: 233 | return EOPNOTSUPP; 234 | case HCI_INVALID_PARAMETERS: 235 | case HCI_SLOT_VIOLATION: 236 | return EINVAL; 237 | case HCI_OE_USER_ENDED_CONNECTION: 238 | case HCI_OE_LOW_RESOURCES: 239 | case HCI_OE_POWER_OFF: 240 | return ECONNRESET; 241 | case HCI_CONNECTION_TERMINATED: 242 | return ECONNABORTED; 243 | case HCI_REPEATED_ATTEMPTS: 244 | return ELOOP; 245 | case HCI_REJECTED_SECURITY: 246 | case HCI_PAIRING_NOT_ALLOWED: 247 | case HCI_INSUFFICIENT_SECURITY: 248 | return EACCES; 249 | case HCI_UNSUPPORTED_REMOTE_FEATURE: 250 | return EPROTONOSUPPORT; 251 | case HCI_SCO_OFFSET_REJECTED: 252 | return ECONNREFUSED; 253 | case HCI_UNKNOWN_LMP_PDU: 254 | case HCI_INVALID_LMP_PARAMETERS: 255 | case HCI_LMP_ERROR_TRANSACTION_COLLISION: 256 | case HCI_LMP_PDU_NOT_ALLOWED: 257 | case HCI_ENCRYPTION_MODE_NOT_ACCEPTED: 258 | return EPROTO; 259 | default: 260 | return ENOSYS; 261 | } 262 | } 263 | 264 | const char *bt_compidtostr(int compid) 265 | { 266 | switch (compid) { 267 | case 0: 268 | return "Ericsson Technology Licensing"; 269 | case 1: 270 | return "Nokia Mobile Phones"; 271 | case 2: 272 | return "Intel Corp."; 273 | case 3: 274 | return "IBM Corp."; 275 | case 4: 276 | return "Toshiba Corp."; 277 | case 5: 278 | return "3Com"; 279 | case 6: 280 | return "Microsoft"; 281 | case 7: 282 | return "Lucent"; 283 | case 8: 284 | return "Motorola"; 285 | case 9: 286 | return "Infineon Technologies AG"; 287 | case 10: 288 | return "Cambridge Silicon Radio"; 289 | case 11: 290 | return "Silicon Wave"; 291 | case 12: 292 | return "Digianswer A/S"; 293 | case 13: 294 | return "Texas Instruments Inc."; 295 | case 14: 296 | return "Ceva, Inc. (formerly Parthus Technologies, Inc.)"; 297 | case 15: 298 | return "Broadcom Corporation"; 299 | case 16: 300 | return "Mitel Semiconductor"; 301 | case 17: 302 | return "Widcomm, Inc"; 303 | case 18: 304 | return "Zeevo, Inc."; 305 | case 19: 306 | return "Atmel Corporation"; 307 | case 20: 308 | return "Mitsubishi Electric Corporation"; 309 | case 21: 310 | return "RTX Telecom A/S"; 311 | case 22: 312 | return "KC Technology Inc."; 313 | case 23: 314 | return "NewLogic"; 315 | case 24: 316 | return "Transilica, Inc."; 317 | case 25: 318 | return "Rohde & Schwarz GmbH & Co. KG"; 319 | case 26: 320 | return "TTPCom Limited"; 321 | case 27: 322 | return "Signia Technologies, Inc."; 323 | case 28: 324 | return "Conexant Systems Inc."; 325 | case 29: 326 | return "Qualcomm"; 327 | case 30: 328 | return "Inventel"; 329 | case 31: 330 | return "AVM Berlin"; 331 | case 32: 332 | return "BandSpeed, Inc."; 333 | case 33: 334 | return "Mansella Ltd"; 335 | case 34: 336 | return "NEC Corporation"; 337 | case 35: 338 | return "WavePlus Technology Co., Ltd."; 339 | case 36: 340 | return "Alcatel"; 341 | case 37: 342 | return "NXP Semiconductors (formerly Philips Semiconductors)"; 343 | case 38: 344 | return "C Technologies"; 345 | case 39: 346 | return "Open Interface"; 347 | case 40: 348 | return "R F Micro Devices"; 349 | case 41: 350 | return "Hitachi Ltd"; 351 | case 42: 352 | return "Symbol Technologies, Inc."; 353 | case 43: 354 | return "Tenovis"; 355 | case 44: 356 | return "Macronix International Co. Ltd."; 357 | case 45: 358 | return "GCT Semiconductor"; 359 | case 46: 360 | return "Norwood Systems"; 361 | case 47: 362 | return "MewTel Technology Inc."; 363 | case 48: 364 | return "ST Microelectronics"; 365 | case 49: 366 | return "Synopsys, Inc."; 367 | case 50: 368 | return "Red-M (Communications) Ltd"; 369 | case 51: 370 | return "Commil Ltd"; 371 | case 52: 372 | return "Computer Access Technology Corporation (CATC)"; 373 | case 53: 374 | return "Eclipse (HQ Espana) S.L."; 375 | case 54: 376 | return "Renesas Electronics Corporation"; 377 | case 55: 378 | return "Mobilian Corporation"; 379 | case 56: 380 | return "Terax"; 381 | case 57: 382 | return "Integrated System Solution Corp."; 383 | case 58: 384 | return "Matsushita Electric Industrial Co., Ltd."; 385 | case 59: 386 | return "Gennum Corporation"; 387 | case 60: 388 | return "BlackBerry Limited (formerly Research In Motion)"; 389 | case 61: 390 | return "IPextreme, Inc."; 391 | case 62: 392 | return "Systems and Chips, Inc."; 393 | case 63: 394 | return "Bluetooth SIG, Inc."; 395 | case 64: 396 | return "Seiko Epson Corporation"; 397 | case 65: 398 | return "Integrated Silicon Solution Taiwan, Inc."; 399 | case 66: 400 | return "CONWISE Technology Corporation Ltd"; 401 | case 67: 402 | return "PARROT SA"; 403 | case 68: 404 | return "Socket Mobile"; 405 | case 69: 406 | return "Atheros Communications, Inc."; 407 | case 70: 408 | return "MediaTek, Inc."; 409 | case 71: 410 | return "Bluegiga"; 411 | case 72: 412 | return "Marvell Technology Group Ltd."; 413 | case 73: 414 | return "3DSP Corporation"; 415 | case 74: 416 | return "Accel Semiconductor Ltd."; 417 | case 75: 418 | return "Continental Automotive Systems"; 419 | case 76: 420 | return "Apple, Inc."; 421 | case 77: 422 | return "Staccato Communications, Inc."; 423 | case 78: 424 | return "Avago Technologies"; 425 | case 79: 426 | return "APT Licensing Ltd."; 427 | case 80: 428 | return "SiRF Technology"; 429 | case 81: 430 | return "Tzero Technologies, Inc."; 431 | case 82: 432 | return "J&M Corporation"; 433 | case 83: 434 | return "Free2move AB"; 435 | case 84: 436 | return "3DiJoy Corporation"; 437 | case 85: 438 | return "Plantronics, Inc."; 439 | case 86: 440 | return "Sony Ericsson Mobile Communications"; 441 | case 87: 442 | return "Harman International Industries, Inc."; 443 | case 88: 444 | return "Vizio, Inc."; 445 | case 89: 446 | return "Nordic Semiconductor ASA"; 447 | case 90: 448 | return "EM Microelectronic-Marin SA"; 449 | case 91: 450 | return "Ralink Technology Corporation"; 451 | case 92: 452 | return "Belkin International, Inc."; 453 | case 93: 454 | return "Realtek Semiconductor Corporation"; 455 | case 94: 456 | return "Stonestreet One, LLC"; 457 | case 95: 458 | return "Wicentric, Inc."; 459 | case 96: 460 | return "RivieraWaves S.A.S"; 461 | case 97: 462 | return "RDA Microelectronics"; 463 | case 98: 464 | return "Gibson Guitars"; 465 | case 99: 466 | return "MiCommand Inc."; 467 | case 100: 468 | return "Band XI International, LLC"; 469 | case 101: 470 | return "Hewlett-Packard Company"; 471 | case 102: 472 | return "9Solutions Oy"; 473 | case 103: 474 | return "GN Netcom A/S"; 475 | case 104: 476 | return "General Motors"; 477 | case 105: 478 | return "A&D Engineering, Inc."; 479 | case 106: 480 | return "MindTree Ltd."; 481 | case 107: 482 | return "Polar Electro OY"; 483 | case 108: 484 | return "Beautiful Enterprise Co., Ltd."; 485 | case 109: 486 | return "BriarTek, Inc."; 487 | case 110: 488 | return "Summit Data Communications, Inc."; 489 | case 111: 490 | return "Sound ID"; 491 | case 112: 492 | return "Monster, LLC"; 493 | case 113: 494 | return "connectBlue AB"; 495 | case 114: 496 | return "ShangHai Super Smart Electronics Co. Ltd."; 497 | case 115: 498 | return "Group Sense Ltd."; 499 | case 116: 500 | return "Zomm, LLC"; 501 | case 117: 502 | return "Samsung Electronics Co. Ltd."; 503 | case 118: 504 | return "Creative Technology Ltd."; 505 | case 119: 506 | return "Laird Technologies"; 507 | case 120: 508 | return "Nike, Inc."; 509 | case 121: 510 | return "lesswire AG"; 511 | case 122: 512 | return "MStar Semiconductor, Inc."; 513 | case 123: 514 | return "Hanlynn Technologies"; 515 | case 124: 516 | return "A & R Cambridge"; 517 | case 125: 518 | return "Seers Technology Co. Ltd"; 519 | case 126: 520 | return "Sports Tracking Technologies Ltd."; 521 | case 127: 522 | return "Autonet Mobile"; 523 | case 128: 524 | return "DeLorme Publishing Company, Inc."; 525 | case 129: 526 | return "WuXi Vimicro"; 527 | case 130: 528 | return "Sennheiser Communications A/S"; 529 | case 131: 530 | return "TimeKeeping Systems, Inc."; 531 | case 132: 532 | return "Ludus Helsinki Ltd."; 533 | case 133: 534 | return "BlueRadios, Inc."; 535 | case 134: 536 | return "equinox AG"; 537 | case 135: 538 | return "Garmin International, Inc."; 539 | case 136: 540 | return "Ecotest"; 541 | case 137: 542 | return "GN ReSound A/S"; 543 | case 138: 544 | return "Jawbone"; 545 | case 139: 546 | return "Topcon Positioning Systems, LLC"; 547 | case 140: 548 | return "Gimbal Inc. (formerly Qualcomm Labs, Inc. and Qualcomm Retail Solutions, Inc.)"; 549 | case 141: 550 | return "Zscan Software"; 551 | case 142: 552 | return "Quintic Corp."; 553 | case 143: 554 | return "Telit Wireless Solutions GmbH (Formerly Stollman E+V GmbH)"; 555 | case 144: 556 | return "Funai Electric Co., Ltd."; 557 | case 145: 558 | return "Advanced PANMOBIL Systems GmbH & Co. KG"; 559 | case 146: 560 | return "ThinkOptics, Inc."; 561 | case 147: 562 | return "Universal Electronics, Inc."; 563 | case 148: 564 | return "Airoha Technology Corp."; 565 | case 149: 566 | return "NEC Lighting, Ltd."; 567 | case 150: 568 | return "ODM Technology, Inc."; 569 | case 151: 570 | return "ConnecteDevice Ltd."; 571 | case 152: 572 | return "zer01.tv GmbH"; 573 | case 153: 574 | return "i.Tech Dynamic Global Distribution Ltd."; 575 | case 154: 576 | return "Alpwise"; 577 | case 155: 578 | return "Jiangsu Toppower Automotive Electronics Co., Ltd."; 579 | case 156: 580 | return "Colorfy, Inc."; 581 | case 157: 582 | return "Geoforce Inc."; 583 | case 158: 584 | return "Bose Corporation"; 585 | case 159: 586 | return "Suunto Oy"; 587 | case 160: 588 | return "Kensington Computer Products Group"; 589 | case 161: 590 | return "SR-Medizinelektronik"; 591 | case 162: 592 | return "Vertu Corporation Limited"; 593 | case 163: 594 | return "Meta Watch Ltd."; 595 | case 164: 596 | return "LINAK A/S"; 597 | case 165: 598 | return "OTL Dynamics LLC"; 599 | case 166: 600 | return "Panda Ocean Inc."; 601 | case 167: 602 | return "Visteon Corporation"; 603 | case 168: 604 | return "ARP Devices Limited"; 605 | case 169: 606 | return "Magneti Marelli S.p.A"; 607 | case 170: 608 | return "CAEN RFID srl"; 609 | case 171: 610 | return "Ingenieur-Systemgruppe Zahn GmbH"; 611 | case 172: 612 | return "Green Throttle Games"; 613 | case 173: 614 | return "Peter Systemtechnik GmbH"; 615 | case 174: 616 | return "Omegawave Oy"; 617 | case 175: 618 | return "Cinetix"; 619 | case 176: 620 | return "Passif Semiconductor Corp"; 621 | case 177: 622 | return "Saris Cycling Group, Inc"; 623 | case 178: 624 | return "Bekey A/S"; 625 | case 179: 626 | return "Clarinox Technologies Pty. Ltd."; 627 | case 180: 628 | return "BDE Technology Co., Ltd."; 629 | case 181: 630 | return "Swirl Networks"; 631 | case 182: 632 | return "Meso international"; 633 | case 183: 634 | return "TreLab Ltd"; 635 | case 184: 636 | return "Qualcomm Innovation Center, Inc. (QuIC)"; 637 | case 185: 638 | return "Johnson Controls, Inc."; 639 | case 186: 640 | return "Starkey Laboratories Inc."; 641 | case 187: 642 | return "S-Power Electronics Limited"; 643 | case 188: 644 | return "Ace Sensor Inc"; 645 | case 189: 646 | return "Aplix Corporation"; 647 | case 190: 648 | return "AAMP of America"; 649 | case 191: 650 | return "Stalmart Technology Limited"; 651 | case 192: 652 | return "AMICCOM Electronics Corporation"; 653 | case 193: 654 | return "Shenzhen Excelsecu Data Technology Co.,Ltd"; 655 | case 194: 656 | return "Geneq Inc."; 657 | case 195: 658 | return "adidas AG"; 659 | case 196: 660 | return "LG Electronics"; 661 | case 197: 662 | return "Onset Computer Corporation"; 663 | case 198: 664 | return "Selfly BV"; 665 | case 199: 666 | return "Quuppa Oy."; 667 | case 200: 668 | return "GeLo Inc"; 669 | case 201: 670 | return "Evluma"; 671 | case 202: 672 | return "MC10"; 673 | case 203: 674 | return "Binauric SE"; 675 | case 204: 676 | return "Beats Electronics"; 677 | case 205: 678 | return "Microchip Technology Inc."; 679 | case 206: 680 | return "Elgato Systems GmbH"; 681 | case 207: 682 | return "ARCHOS SA"; 683 | case 208: 684 | return "Dexcom, Inc."; 685 | case 209: 686 | return "Polar Electro Europe B.V."; 687 | case 210: 688 | return "Dialog Semiconductor B.V."; 689 | case 211: 690 | return "Taixingbang Technology (HK) Co,. LTD."; 691 | case 212: 692 | return "Kawantech"; 693 | case 213: 694 | return "Austco Communication Systems"; 695 | case 214: 696 | return "Timex Group USA, Inc."; 697 | case 215: 698 | return "Qualcomm Technologies, Inc."; 699 | case 216: 700 | return "Qualcomm Connected Experiences, Inc."; 701 | case 217: 702 | return "Voyetra Turtle Beach"; 703 | case 218: 704 | return "txtr GmbH"; 705 | case 219: 706 | return "Biosentronics"; 707 | case 220: 708 | return "Procter & Gamble"; 709 | case 221: 710 | return "Hosiden Corporation"; 711 | case 222: 712 | return "Muzik LLC"; 713 | case 223: 714 | return "Misfit Wearables Corp"; 715 | case 224: 716 | return "Google"; 717 | case 225: 718 | return "Danlers Ltd"; 719 | case 226: 720 | return "Semilink Inc"; 721 | case 227: 722 | return "inMusic Brands, Inc"; 723 | case 228: 724 | return "L.S. Research Inc."; 725 | case 229: 726 | return "Eden Software Consultants Ltd."; 727 | case 230: 728 | return "Freshtemp"; 729 | case 231: 730 | return "KS Technologies"; 731 | case 232: 732 | return "ACTS Technologies"; 733 | case 233: 734 | return "Vtrack Systems"; 735 | case 234: 736 | return "Nielsen-Kellerman Company"; 737 | case 235: 738 | return "Server Technology, Inc."; 739 | case 236: 740 | return "BioResearch Associates"; 741 | case 237: 742 | return "Jolly Logic, LLC"; 743 | case 238: 744 | return "Above Average Outcomes, Inc."; 745 | case 239: 746 | return "Bitsplitters GmbH"; 747 | case 240: 748 | return "PayPal, Inc."; 749 | case 241: 750 | return "Witron Technology Limited"; 751 | case 242: 752 | return "Aether Things Inc. (formerly Morse Project Inc.)"; 753 | case 243: 754 | return "Kent Displays Inc."; 755 | case 244: 756 | return "Nautilus Inc."; 757 | case 245: 758 | return "Smartifier Oy"; 759 | case 246: 760 | return "Elcometer Limited"; 761 | case 247: 762 | return "VSN Technologies Inc."; 763 | case 248: 764 | return "AceUni Corp., Ltd."; 765 | case 249: 766 | return "StickNFind"; 767 | case 250: 768 | return "Crystal Code AB"; 769 | case 251: 770 | return "KOUKAAM a.s."; 771 | case 252: 772 | return "Delphi Corporation"; 773 | case 253: 774 | return "ValenceTech Limited"; 775 | case 254: 776 | return "Reserved"; 777 | case 255: 778 | return "Typo Products, LLC"; 779 | case 256: 780 | return "TomTom International BV"; 781 | case 257: 782 | return "Fugoo, Inc"; 783 | case 258: 784 | return "Keiser Corporation"; 785 | case 259: 786 | return "Bang & Olufsen A/S"; 787 | case 260: 788 | return "PLUS Locations Systems Pty Ltd"; 789 | case 261: 790 | return "Ubiquitous Computing Technology Corporation"; 791 | case 262: 792 | return "Innovative Yachtter Solutions"; 793 | case 263: 794 | return "William Demant Holding A/S"; 795 | case 264: 796 | return "Chicony Electronics Co., Ltd."; 797 | case 265: 798 | return "Atus BV"; 799 | case 266: 800 | return "Codegate Ltd."; 801 | case 267: 802 | return "ERi, Inc."; 803 | case 268: 804 | return "Transducers Direct, LLC"; 805 | case 269: 806 | return "Fujitsu Ten Limited"; 807 | case 270: 808 | return "Audi AG"; 809 | case 271: 810 | return "HiSilicon Technologies Co., Ltd."; 811 | case 272: 812 | return "Nippon Seiki Co., Ltd."; 813 | case 273: 814 | return "Steelseries ApS"; 815 | case 274: 816 | return "Visybl Inc."; 817 | case 275: 818 | return "Openbrain Technologies, Co., Ltd."; 819 | case 276: 820 | return "Xensr"; 821 | case 277: 822 | return "e.solutions"; 823 | case 278: 824 | return "1OAK Technologies"; 825 | case 279: 826 | return "Wimoto Technologies Inc"; 827 | case 280: 828 | return "Radius Networks, Inc."; 829 | case 281: 830 | return "Wize Technology Co., Ltd."; 831 | case 282: 832 | return "Qualcomm Labs, Inc."; 833 | case 283: 834 | return "Aruba Networks"; 835 | case 284: 836 | return "Baidu"; 837 | case 285: 838 | return "Arendi AG"; 839 | case 286: 840 | return "Skoda Auto a.s."; 841 | case 287: 842 | return "Volkswagen AG"; 843 | case 288: 844 | return "Porsche AG"; 845 | case 289: 846 | return "Sino Wealth Electronic Ltd."; 847 | case 290: 848 | return "AirTurn, Inc."; 849 | case 291: 850 | return "Kinsa, Inc."; 851 | case 292: 852 | return "HID Global"; 853 | case 293: 854 | return "SEAT es"; 855 | case 294: 856 | return "Promethean Ltd."; 857 | case 295: 858 | return "Salutica Allied Solutions"; 859 | case 296: 860 | return "GPSI Group Pty Ltd"; 861 | case 297: 862 | return "Nimble Devices Oy"; 863 | case 298: 864 | return "Changzhou Yongse Infotech Co., Ltd"; 865 | case 299: 866 | return "SportIQ"; 867 | case 300: 868 | return "TEMEC Instruments B.V."; 869 | case 301: 870 | return "Sony Corporation"; 871 | case 302: 872 | return "ASSA ABLOY"; 873 | case 303: 874 | return "Clarion Co., Ltd."; 875 | case 304: 876 | return "Warehouse Innovations"; 877 | case 305: 878 | return "Cypress Semiconductor Corporation"; 879 | case 306: 880 | return "MADS Inc"; 881 | case 307: 882 | return "Blue Maestro Limited"; 883 | case 308: 884 | return "Resolution Products, Inc."; 885 | case 309: 886 | return "Airewear LLC"; 887 | case 310: 888 | return "Seed Labs, Inc. (formerly ETC sp. z.o.o.)"; 889 | case 311: 890 | return "Prestigio Plaza Ltd."; 891 | case 312: 892 | return "NTEO Inc."; 893 | case 313: 894 | return "Focus Systems Corporation"; 895 | case 314: 896 | return "Tencent Holdings Limited"; 897 | case 315: 898 | return "Allegion"; 899 | case 316: 900 | return "Murata Manufacuring Co., Ltd."; 901 | case 317: 902 | return "WirelessWERX"; 903 | case 318: 904 | return "Nod, Inc."; 905 | case 319: 906 | return "B&B Manufacturing Company"; 907 | case 320: 908 | return "Alpine Electronics (China) Co., Ltd"; 909 | case 321: 910 | return "FedEx Services"; 911 | case 322: 912 | return "Grape Systems Inc."; 913 | case 323: 914 | return "Bkon Connect"; 915 | case 324: 916 | return "Lintech GmbH"; 917 | case 325: 918 | return "Novatel Wireless"; 919 | case 326: 920 | return "Ciright"; 921 | case 327: 922 | return "Mighty Cast, Inc."; 923 | case 328: 924 | return "Ambimat Electronics"; 925 | case 329: 926 | return "Perytons Ltd."; 927 | case 330: 928 | return "Tivoli Audio, LLC"; 929 | case 331: 930 | return "Master Lock"; 931 | case 332: 932 | return "Mesh-Net Ltd"; 933 | case 333: 934 | return "Huizhou Desay SV Automotive CO., LTD."; 935 | case 334: 936 | return "Tangerine, Inc."; 937 | case 335: 938 | return "B&W Group Ltd."; 939 | case 336: 940 | return "Pioneer Corporation"; 941 | case 337: 942 | return "OnBeep"; 943 | case 338: 944 | return "Vernier Software & Technology"; 945 | case 339: 946 | return "ROL Ergo"; 947 | case 340: 948 | return "Pebble Technology"; 949 | case 341: 950 | return "NETATMO"; 951 | case 342: 952 | return "Accumulate AB"; 953 | case 343: 954 | return "Anhui Huami Information Technology Co., Ltd."; 955 | case 344: 956 | return "Inmite s.r.o."; 957 | case 345: 958 | return "ChefSteps, Inc."; 959 | case 346: 960 | return "micas AG"; 961 | case 347: 962 | return "Biomedical Research Ltd."; 963 | case 348: 964 | return "Pitius Tec S.L."; 965 | case 349: 966 | return "Estimote, Inc."; 967 | case 350: 968 | return "Unikey Technologies, Inc."; 969 | case 351: 970 | return "Timer Cap Co."; 971 | case 352: 972 | return "AwoX"; 973 | case 353: 974 | return "yikes"; 975 | case 354: 976 | return "MADSGlobal NZ Ltd."; 977 | case 355: 978 | return "PCH International"; 979 | case 356: 980 | return "Qingdao Yeelink Information Technology Co., Ltd."; 981 | case 357: 982 | return "Milwaukee Tool (formerly Milwaukee Electric Tools)"; 983 | case 358: 984 | return "MISHIK Pte Ltd"; 985 | case 359: 986 | return "Bayer HealthCare"; 987 | case 360: 988 | return "Spicebox LLC"; 989 | case 361: 990 | return "emberlight"; 991 | case 362: 992 | return "Cooper-Atkins Corporation"; 993 | case 363: 994 | return "Qblinks"; 995 | case 364: 996 | return "MYSPHERA"; 997 | case 365: 998 | return "LifeScan Inc"; 999 | case 366: 1000 | return "Volantic AB"; 1001 | case 367: 1002 | return "Podo Labs, Inc"; 1003 | case 368: 1004 | return "F. Hoffmann-La Roche AG"; 1005 | case 369: 1006 | return "Amazon Fulfillment Service"; 1007 | case 370: 1008 | return "Connovate Technology Private Limited"; 1009 | case 371: 1010 | return "Kocomojo, LLC"; 1011 | case 372: 1012 | return "Everykey LLC"; 1013 | case 373: 1014 | return "Dynamic Controls"; 1015 | case 374: 1016 | return "SentriLock"; 1017 | case 375: 1018 | return "I-SYST inc."; 1019 | case 376: 1020 | return "CASIO COMPUTER CO., LTD."; 1021 | case 377: 1022 | return "LAPIS Semiconductor Co., Ltd."; 1023 | case 378: 1024 | return "Telemonitor, Inc."; 1025 | case 379: 1026 | return "taskit GmbH"; 1027 | case 380: 1028 | return "Daimler AG"; 1029 | case 381: 1030 | return "BatAndCat"; 1031 | case 382: 1032 | return "BluDotz Ltd"; 1033 | case 383: 1034 | return "XTel ApS"; 1035 | case 384: 1036 | return "Gigaset Communications GmbH"; 1037 | case 385: 1038 | return "Gecko Health Innovations, Inc."; 1039 | case 386: 1040 | return "HOP Ubiquitous"; 1041 | case 387: 1042 | return "To Be Assigned"; 1043 | case 388: 1044 | return "Nectar"; 1045 | case 389: 1046 | return "bel'apps LLC"; 1047 | case 390: 1048 | return "CORE Lighting Ltd"; 1049 | case 391: 1050 | return "Seraphim Sense Ltd"; 1051 | case 392: 1052 | return "Unico RBC"; 1053 | case 393: 1054 | return "Physical Enterprises Inc."; 1055 | case 394: 1056 | return "Able Trend Technology Limited"; 1057 | case 395: 1058 | return "Konica Minolta, Inc."; 1059 | case 396: 1060 | return "Wilo SE"; 1061 | case 397: 1062 | return "Extron Design Services"; 1063 | case 398: 1064 | return "Fitbit, Inc."; 1065 | case 399: 1066 | return "Fireflies Systems"; 1067 | case 400: 1068 | return "Intelletto Technologies Inc."; 1069 | case 401: 1070 | return "FDK CORPORATION"; 1071 | case 402: 1072 | return "Cloudleaf, Inc"; 1073 | case 403: 1074 | return "Maveric Automation LLC"; 1075 | case 404: 1076 | return "Acoustic Stream Corporation"; 1077 | case 405: 1078 | return "Zuli"; 1079 | case 406: 1080 | return "Paxton Access Ltd"; 1081 | case 407: 1082 | return "WiSilica Inc"; 1083 | case 408: 1084 | return "VENGIT Korl谩tolt Felel艖ss茅g疟 T谩rsas谩g"; 1085 | case 409: 1086 | return "SALTO SYSTEMS S.L."; 1087 | case 410: 1088 | return "TRON Forum (formerly T-Engine Forum)"; 1089 | case 411: 1090 | return "CUBETECH s.r.o."; 1091 | case 412: 1092 | return "Cokiya Incorporated"; 1093 | case 413: 1094 | return "CVS Health"; 1095 | case 414: 1096 | return "Ceruus"; 1097 | case 415: 1098 | return "Strainstall Ltd"; 1099 | case 416: 1100 | return "Channel Enterprises (HK) Ltd."; 1101 | case 417: 1102 | return "FIAMM"; 1103 | case 418: 1104 | return "GIGALANE.CO.,LTD"; 1105 | case 419: 1106 | return "EROAD"; 1107 | case 420: 1108 | return "Mine Safety Appliances"; 1109 | case 421: 1110 | return "Icon Health and Fitness"; 1111 | case 422: 1112 | return "Asandoo GmbH"; 1113 | case 423: 1114 | return "ENERGOUS CORPORATION"; 1115 | case 424: 1116 | return "Taobao"; 1117 | case 425: 1118 | return "Canon Inc."; 1119 | case 426: 1120 | return "Geophysical Technology Inc."; 1121 | case 427: 1122 | return "Facebook, Inc."; 1123 | case 428: 1124 | return "Nipro Diagnostics, Inc."; 1125 | case 429: 1126 | return "FlightSafety International"; 1127 | case 430: 1128 | return "Earlens Corporation"; 1129 | case 431: 1130 | return "Sunrise Micro Devices, Inc."; 1131 | case 432: 1132 | return "Star Micronics Co., Ltd."; 1133 | case 433: 1134 | return "Netizens Sp. z o.o."; 1135 | case 434: 1136 | return "Nymi Inc."; 1137 | case 435: 1138 | return "Nytec, Inc."; 1139 | case 436: 1140 | return "Trineo Sp. z o.o."; 1141 | case 437: 1142 | return "Nest Labs Inc."; 1143 | case 438: 1144 | return "LM Technologies Ltd"; 1145 | case 439: 1146 | return "General Electric Company"; 1147 | case 440: 1148 | return "i+D3 S.L."; 1149 | case 441: 1150 | return "HANA Micron"; 1151 | case 442: 1152 | return "Stages Cycling LLC"; 1153 | case 443: 1154 | return "Cochlear Bone Anchored Solutions AB"; 1155 | case 444: 1156 | return "SenionLab AB"; 1157 | case 445: 1158 | return "Syszone Co., Ltd"; 1159 | case 446: 1160 | return "Pulsate Mobile Ltd."; 1161 | case 447: 1162 | return "Hong Kong HunterSun Electronic Limited"; 1163 | case 448: 1164 | return "pironex GmbH"; 1165 | case 449: 1166 | return "BRADATECH Corp."; 1167 | case 450: 1168 | return "Transenergooil AG"; 1169 | case 451: 1170 | return "Bunch"; 1171 | case 452: 1172 | return "DME Microelectronics"; 1173 | case 453: 1174 | return "Bitcraze AB"; 1175 | case 454: 1176 | return "HASWARE Inc."; 1177 | case 455: 1178 | return "Abiogenix Inc."; 1179 | case 456: 1180 | return "Poly-Control ApS"; 1181 | case 457: 1182 | return "Avi-on"; 1183 | case 458: 1184 | return "Laerdal Medical AS"; 1185 | case 459: 1186 | return "Fetch My Pet"; 1187 | case 460: 1188 | return "Sam Labs Ltd."; 1189 | case 461: 1190 | return "Chengdu Synwing Technology Ltd"; 1191 | case 462: 1192 | return "HOUWA SYSTEM DESIGN, k.k."; 1193 | case 463: 1194 | return "BSH"; 1195 | case 464: 1196 | return "Primus Inter Pares Ltd"; 1197 | case 465: 1198 | return "August"; 1199 | case 466: 1200 | return "Gill Electronics"; 1201 | case 467: 1202 | return "Sky Wave Design"; 1203 | case 468: 1204 | return "Newlab S.r.l."; 1205 | case 469: 1206 | return "ELAD srl"; 1207 | case 470: 1208 | return "G-wearables inc."; 1209 | case 471: 1210 | return "Squadrone Systems Inc."; 1211 | case 472: 1212 | return "Code Corporation"; 1213 | case 473: 1214 | return "Savant Systems LLC"; 1215 | case 474: 1216 | return "Logitech International SA"; 1217 | case 475: 1218 | return "Innblue Consulting"; 1219 | case 476: 1220 | return "iParking Ltd."; 1221 | case 477: 1222 | return "Koninklijke Philips Electronics N.V."; 1223 | case 478: 1224 | return "Minelab Electronics Pty Limited"; 1225 | case 479: 1226 | return "Bison Group Ltd."; 1227 | case 480: 1228 | return "Widex A/S"; 1229 | case 481: 1230 | return "Jolla Ltd"; 1231 | case 482: 1232 | return "Lectronix, Inc."; 1233 | case 483: 1234 | return "Caterpillar Inc"; 1235 | case 484: 1236 | return "Freedom Innovations"; 1237 | case 485: 1238 | return "Dynamic Devices Ltd"; 1239 | case 486: 1240 | return "Technology Solutions (UK) Ltd"; 1241 | case 487: 1242 | return "IPS Group Inc."; 1243 | case 488: 1244 | return "STIR"; 1245 | case 489: 1246 | return "Sano, Inc"; 1247 | case 490: 1248 | return "Advanced Application Design, Inc."; 1249 | case 491: 1250 | return "AutoMap LLC"; 1251 | case 492: 1252 | return "Spreadtrum Communications Shanghai Ltd"; 1253 | case 493: 1254 | return "CuteCircuit LTD"; 1255 | case 494: 1256 | return "Valeo Service"; 1257 | case 495: 1258 | return "Fullpower Technologies, Inc."; 1259 | case 496: 1260 | return "KloudNation"; 1261 | case 497: 1262 | return "Zebra Technologies Corporation"; 1263 | case 498: 1264 | return "Itron, Inc."; 1265 | case 499: 1266 | return "The University of Tokyo"; 1267 | case 500: 1268 | return "UTC Fire and Security"; 1269 | case 501: 1270 | return "Cool Webthings Limited"; 1271 | case 502: 1272 | return "DJO Global"; 1273 | case 503: 1274 | return "Gelliner Limited"; 1275 | case 504: 1276 | return "Anyka (Guangzhou) Microelectronics Technology Co, LTD"; 1277 | case 505: 1278 | return "Medtronic, Inc."; 1279 | case 506: 1280 | return "Gozio, Inc."; 1281 | case 507: 1282 | return "Form Lifting, LLC"; 1283 | case 508: 1284 | return "Wahoo Fitness, LLC"; 1285 | case 509: 1286 | return "Kontakt Micro-Location Sp. z o.o."; 1287 | case 510: 1288 | return "Radio System Corporation"; 1289 | case 511: 1290 | return "Freescale Semiconductor, Inc."; 1291 | case 512: 1292 | return "Verifone Systems PTe Ltd. Taiwan Branch"; 1293 | case 513: 1294 | return "AR Timing"; 1295 | case 514: 1296 | return "Rigado LLC"; 1297 | case 515: 1298 | return "Kemppi Oy"; 1299 | case 516: 1300 | return "Tapcentive Inc."; 1301 | case 517: 1302 | return "Smartbotics Inc."; 1303 | case 518: 1304 | return "Otter Products, LLC"; 1305 | case 519: 1306 | return "STEMP Inc."; 1307 | case 520: 1308 | return "LumiGeek LLC"; 1309 | case 521: 1310 | return "InvisionHeart Inc."; 1311 | case 522: 1312 | return "Macnica Inc."; 1313 | case 523: 1314 | return "Jaguar Land Rover Limited"; 1315 | case 524: 1316 | return "CoroWare Technologies, Inc"; 1317 | case 525: 1318 | return "Simplo Technology Co., LTD"; 1319 | case 526: 1320 | return "Omron Healthcare Co., LTD"; 1321 | case 527: 1322 | return "Comodule GMBH"; 1323 | case 528: 1324 | return "ikeGPS"; 1325 | case 529: 1326 | return "Telink Semiconductor Co. Ltd"; 1327 | case 530: 1328 | return "Interplan Co., Ltd"; 1329 | case 531: 1330 | return "Wyler AG"; 1331 | case 532: 1332 | return "IK Multimedia Production srl"; 1333 | case 533: 1334 | return "Lukoton Experience Oy"; 1335 | case 534: 1336 | return "MTI Ltd"; 1337 | case 535: 1338 | return "Tech4home, Lda"; 1339 | case 536: 1340 | return "Hiotech AB"; 1341 | case 537: 1342 | return "DOTT Limited"; 1343 | case 538: 1344 | return "Blue Speck Labs, LLC"; 1345 | case 539: 1346 | return "Cisco Systems Inc"; 1347 | case 540: 1348 | return "Mobicomm Inc"; 1349 | case 541: 1350 | return "Edamic"; 1351 | case 542: 1352 | return "Goodnet Ltd"; 1353 | case 543: 1354 | return "Luster Leaf Products Inc"; 1355 | case 544: 1356 | return "Manus Machina BV"; 1357 | case 545: 1358 | return "Mobiquity Networks Inc"; 1359 | case 546: 1360 | return "Praxis Dynamics"; 1361 | case 547: 1362 | return "Philip Morris Products S.A."; 1363 | case 548: 1364 | return "Comarch SA"; 1365 | case 549: 1366 | return "Nestl茅 Nespresso S.A."; 1367 | case 550: 1368 | return "Merlinia A/S"; 1369 | case 551: 1370 | return "LifeBEAM Technologies"; 1371 | case 552: 1372 | return "Twocanoes Labs, LLC"; 1373 | case 553: 1374 | return "Muoverti Limited"; 1375 | case 554: 1376 | return "Stamer Musikanlagen GMBH"; 1377 | case 555: 1378 | return "Tesla Motors"; 1379 | case 556: 1380 | return "Pharynks Corporation"; 1381 | case 557: 1382 | return "Lupine"; 1383 | case 558: 1384 | return "Siemens AG"; 1385 | case 559: 1386 | return "Huami (Shanghai) Culture Communication CO., LTD"; 1387 | case 560: 1388 | return "Foster Electric Company, Ltd"; 1389 | case 561: 1390 | return "ETA SA"; 1391 | case 562: 1392 | return "x-Senso Solutions Kft"; 1393 | case 563: 1394 | return "Shenzhen SuLong Communication Ltd"; 1395 | case 564: 1396 | return "FengFan (BeiJing) Technology Co, Ltd"; 1397 | case 565: 1398 | return "Qrio Inc"; 1399 | case 566: 1400 | return "Pitpatpet Ltd"; 1401 | case 567: 1402 | return "MSHeli s.r.l."; 1403 | case 568: 1404 | return "Trakm8 Ltd"; 1405 | case 569: 1406 | return "JIN CO, Ltd"; 1407 | case 570: 1408 | return "Alatech Technology"; 1409 | case 571: 1410 | return "Beijing CarePulse Electronic Technology Co, Ltd"; 1411 | case 572: 1412 | return "Awarepoint"; 1413 | case 573: 1414 | return "ViCentra B.V."; 1415 | case 574: 1416 | return "Raven Industries"; 1417 | case 575: 1418 | return "WaveWare Technologies"; 1419 | case 576: 1420 | return "Argenox Technologies"; 1421 | case 577: 1422 | return "Bragi GmbH"; 1423 | case 578: 1424 | return "16Lab Inc"; 1425 | case 579: 1426 | return "Masimo Corp"; 1427 | case 580: 1428 | return "Iotera Inc."; 1429 | case 581: 1430 | return "Endress+Hauser"; 1431 | case 582: 1432 | return "ACKme Networks, Inc."; 1433 | case 583: 1434 | return "FiftyThree Inc."; 1435 | case 584: 1436 | return "Parker Hannifin Corp"; 1437 | case 585: 1438 | return "Transcranial Ltd"; 1439 | case 586: 1440 | return "Uwatec AG"; 1441 | case 587: 1442 | return "Orlan LLC"; 1443 | case 588: 1444 | return "Blue Clover Devices"; 1445 | case 589: 1446 | return "M-Way Solutions GmbH"; 1447 | case 590: 1448 | return "Microtronics Engineering GmbH"; 1449 | case 591: 1450 | return "Schneider Schreibger盲te GmbH"; 1451 | case 592: 1452 | return "Sapphire Circuits LLC"; 1453 | case 593: 1454 | return "Lumo Bodytech Inc."; 1455 | case 594: 1456 | return "UKC Technosolution"; 1457 | case 595: 1458 | return "Xicato Inc."; 1459 | case 596: 1460 | return "Playbrush"; 1461 | case 597: 1462 | return "Dai Nippon Printing Co., Ltd."; 1463 | case 598: 1464 | return "G24 Power Limited"; 1465 | case 599: 1466 | return "AdBabble Local Commerce Inc."; 1467 | case 600: 1468 | return "Devialet SA"; 1469 | case 601: 1470 | return "ALTYOR"; 1471 | case 602: 1472 | return "University of Applied Sciences Valais/Haute Ecole Valaisanne"; 1473 | case 603: 1474 | return "Five Interactive, LLC dba Zendo"; 1475 | case 604: 1476 | return "NetEase (Hangzhou) Network co.Ltd."; 1477 | case 605: 1478 | return "Lexmark International Inc."; 1479 | case 606: 1480 | return "Fluke Corporation"; 1481 | case 607: 1482 | return "Yardarm Technologies"; 1483 | case 608: 1484 | return "SensaRx"; 1485 | case 609: 1486 | return "SECVRE GmbH"; 1487 | case 610: 1488 | return "Glacial Ridge Technologies"; 1489 | case 611: 1490 | return "Identiv, Inc."; 1491 | case 612: 1492 | return "DDS, Inc."; 1493 | case 613: 1494 | return "SMK Corporation"; 1495 | case 614: 1496 | return "Schawbel Technologies LLC"; 1497 | case 615: 1498 | return "XMI Systems SA"; 1499 | case 616: 1500 | return "Cerevo"; 1501 | case 617: 1502 | return "Torrox GmbH & Co KG"; 1503 | case 618: 1504 | return "Gemalto"; 1505 | case 619: 1506 | return "DEKA Research & Development Corp."; 1507 | case 620: 1508 | return "Domster Tadeusz Szydlowski"; 1509 | case 621: 1510 | return "Technogym SPA"; 1511 | case 622: 1512 | return "FLEURBAEY BVBA"; 1513 | case 623: 1514 | return "Aptcode Solutions"; 1515 | case 624: 1516 | return "LSI ADL Technology"; 1517 | case 625: 1518 | return "Animas Corp"; 1519 | case 626: 1520 | return "Alps Electric Co., Ltd."; 1521 | case 627: 1522 | return "OCEASOFT"; 1523 | case 628: 1524 | return "Motsai Research"; 1525 | case 629: 1526 | return "Geotab"; 1527 | case 630: 1528 | return "E.G.O. Elektro-Ger盲tebau GmbH"; 1529 | case 631: 1530 | return "bewhere inc"; 1531 | case 632: 1532 | return "Johnson Outdoors Inc"; 1533 | case 633: 1534 | return "steute Schaltgerate GmbH & Co. KG"; 1535 | case 634: 1536 | return "Ekomini inc."; 1537 | case 635: 1538 | return "DEFA AS"; 1539 | case 636: 1540 | return "Aseptika Ltd"; 1541 | case 637: 1542 | return "HUAWEI Technologies Co., Ltd. ( 鍗庝负鎶�鏈湁闄愬叕鍙� )"; 1543 | case 638: 1544 | return "HabitAware, LLC"; 1545 | case 639: 1546 | return "ruwido austria gmbh"; 1547 | case 640: 1548 | return "ITEC corporation"; 1549 | case 641: 1550 | return "StoneL"; 1551 | case 642: 1552 | return "Sonova AG"; 1553 | case 643: 1554 | return "Maven Machines, Inc."; 1555 | case 644: 1556 | return "Synapse Electronics"; 1557 | case 645: 1558 | return "Standard Innovation Inc."; 1559 | case 646: 1560 | return "RF Code, Inc."; 1561 | case 647: 1562 | return "Wally Ventures S.L."; 1563 | case 648: 1564 | return "Willowbank Electronics Ltd"; 1565 | case 649: 1566 | return "SK Telecom"; 1567 | case 650: 1568 | return "Jetro AS"; 1569 | case 651: 1570 | return "Code Gears LTD"; 1571 | case 652: 1572 | return "NANOLINK APS"; 1573 | case 653: 1574 | return "IF, LLC"; 1575 | case 654: 1576 | return "RF Digital Corp"; 1577 | case 655: 1578 | return "Church & Dwight Co., Inc"; 1579 | case 656: 1580 | return "Multibit Oy"; 1581 | case 657: 1582 | return "CliniCloud Inc"; 1583 | case 658: 1584 | return "SwiftSensors"; 1585 | case 659: 1586 | return "Blue Bite"; 1587 | case 660: 1588 | return "ELIAS GmbH"; 1589 | case 661: 1590 | return "Sivantos GmbH"; 1591 | case 662: 1592 | return "Petzl"; 1593 | case 663: 1594 | return "storm power ltd"; 1595 | case 664: 1596 | return "EISST Ltd"; 1597 | case 665: 1598 | return "Inexess Technology Simma KG"; 1599 | case 666: 1600 | return "Currant, Inc."; 1601 | case 667: 1602 | return "C2 Development, Inc."; 1603 | case 668: 1604 | return "Blue Sky Scientific, LLC"; 1605 | case 669: 1606 | return "ALOTTAZS LABS, LLC"; 1607 | case 670: 1608 | return "Kupson spol. s r.o."; 1609 | case 671: 1610 | return "Areus Engineering GmbH"; 1611 | case 672: 1612 | return "Impossible Camera GmbH"; 1613 | case 673: 1614 | return "InventureTrack Systems"; 1615 | case 674: 1616 | return "LockedUp"; 1617 | case 675: 1618 | return "Itude"; 1619 | case 676: 1620 | return "Pacific Lock Company"; 1621 | case 677: 1622 | return "Tendyron Corporation ( 澶╁湴铻嶇鎶�鑲′唤鏈夐檺鍏徃 )"; 1623 | case 678: 1624 | return "Robert Bosch GmbH"; 1625 | case 679: 1626 | return "Illuxtron international B.V."; 1627 | case 680: 1628 | return "miSport Ltd."; 1629 | case 681: 1630 | return "Chargelib"; 1631 | case 682: 1632 | return "Doppler Lab"; 1633 | case 683: 1634 | return "BBPOS Limited"; 1635 | case 684: 1636 | return "RTB Elektronik GmbH & Co. KG"; 1637 | case 685: 1638 | return "Rx Networks, Inc."; 1639 | case 686: 1640 | return "WeatherFlow, Inc."; 1641 | case 687: 1642 | return "Technicolor USA Inc."; 1643 | case 688: 1644 | return "Bestechnic(Shanghai),Ltd"; 1645 | case 689: 1646 | return "Raden Inc"; 1647 | case 690: 1648 | return "JouZen Oy"; 1649 | case 691: 1650 | return "CLABER S.P.A."; 1651 | case 692: 1652 | return "Hyginex, Inc."; 1653 | case 693: 1654 | return "HANSHIN ELECTRIC RAILWAY CO.,LTD."; 1655 | case 694: 1656 | return "Schneider Electric"; 1657 | case 695: 1658 | return "Oort Technologies LLC"; 1659 | case 696: 1660 | return "Chrono Therapeutics"; 1661 | case 697: 1662 | return "Rinnai Corporation"; 1663 | case 698: 1664 | return "Swissprime Technologies AG"; 1665 | case 699: 1666 | return "Koha.,Co.Ltd"; 1667 | case 700: 1668 | return "Genevac Ltd"; 1669 | case 701: 1670 | return "Chemtronics"; 1671 | case 702: 1672 | return "Seguro Technology Sp. z o.o."; 1673 | case 703: 1674 | return "Redbird Flight Simulations"; 1675 | case 704: 1676 | return "Dash Robotics"; 1677 | case 705: 1678 | return "LINE Corporation"; 1679 | case 706: 1680 | return "Guillemot Corporation"; 1681 | case 707: 1682 | return "Techtronic Power Tools Technology Limited"; 1683 | case 708: 1684 | return "Wilson Sporting Goods"; 1685 | case 709: 1686 | return "Lenovo (Singapore) Pte Ltd. ( 鑱旀兂锛堟柊鍔犲潯锛� )"; 1687 | case 710: 1688 | return "Ayatan Sensors"; 1689 | case 711: 1690 | return "Electronics Tomorrow Limited"; 1691 | case 712: 1692 | return "VASCO Data Security International, Inc."; 1693 | case 713: 1694 | return "PayRange Inc."; 1695 | case 714: 1696 | return "ABOV Semiconductor"; 1697 | case 715: 1698 | return "AINA-Wireless Inc."; 1699 | case 716: 1700 | return "Eijkelkamp Soil & Water"; 1701 | case 717: 1702 | return "BMA ergonomics b.v."; 1703 | case 718: 1704 | return "Teva Branded Pharmaceutical Products R&D, Inc."; 1705 | case 719: 1706 | return "Anima"; 1707 | case 720: 1708 | return "3M"; 1709 | case 721: 1710 | return "Empatica Srl"; 1711 | case 722: 1712 | return "Afero, Inc."; 1713 | case 723: 1714 | return "Powercast Corporation"; 1715 | case 724: 1716 | return "Secuyou ApS"; 1717 | case 725: 1718 | return "OMRON Corporation"; 1719 | case 726: 1720 | return "Send Solutions"; 1721 | case 727: 1722 | return "NIPPON SYSTEMWARE CO.,LTD."; 1723 | case 728: 1724 | return "Neosfar"; 1725 | case 729: 1726 | return "Fliegl Agrartechnik GmbH"; 1727 | case 730: 1728 | return "Gilvader"; 1729 | case 731: 1730 | return "Digi International Inc (R)"; 1731 | case 732: 1732 | return "DeWalch Technologies, Inc."; 1733 | case 733: 1734 | return "Flint Rehabilitation Devices, LLC"; 1735 | case 734: 1736 | return "Samsung SDS Co., Ltd."; 1737 | case 735: 1738 | return "Blur Product Development"; 1739 | case 736: 1740 | return "University of Michigan"; 1741 | case 737: 1742 | return "Victron Energy BV"; 1743 | case 738: 1744 | return "NTT docomo"; 1745 | case 739: 1746 | return "Carmanah Technologies Corp."; 1747 | case 740: 1748 | return "Bytestorm Ltd."; 1749 | case 741: 1750 | return "Espressif Incorporated ( 涔愰懌淇℃伅绉戞妧(涓婃捣)鏈夐檺鍏徃 )"; 1751 | case 742: 1752 | return "Unwire"; 1753 | case 743: 1754 | return "Connected Yard, Inc."; 1755 | case 744: 1756 | return "American Music Environments"; 1757 | case 745: 1758 | return "Sensogram Technologies, Inc."; 1759 | case 746: 1760 | return "Fujitsu Limited"; 1761 | case 747: 1762 | return "Ardic Technology"; 1763 | case 748: 1764 | return "Delta Systems, Inc"; 1765 | case 749: 1766 | return "HTC Corporation"; 1767 | case 750: 1768 | return "Citizen Holdings Co., Ltd."; 1769 | case 751: 1770 | return "SMART-INNOVATION.inc"; 1771 | case 752: 1772 | return "Blackrat Software"; 1773 | case 753: 1774 | return "The Idea Cave, LLC"; 1775 | case 754: 1776 | return "GoPro, Inc."; 1777 | case 755: 1778 | return "AuthAir, Inc"; 1779 | case 756: 1780 | return "Vensi, Inc."; 1781 | case 757: 1782 | return "Indagem Tech LLC"; 1783 | case 758: 1784 | return "Intemo Technologies"; 1785 | case 759: 1786 | return "DreamVisions co., Ltd."; 1787 | case 760: 1788 | return "Runteq Oy Ltd"; 1789 | case 761: 1790 | return "IMAGINATION TECHNOLOGIES LTD"; 1791 | case 762: 1792 | return "CoSTAR Technologies"; 1793 | case 763: 1794 | return "Clarius Mobile Health Corp."; 1795 | case 764: 1796 | return "Shanghai Frequen Microelectronics Co., Ltd."; 1797 | case 765: 1798 | return "Uwanna, Inc."; 1799 | case 766: 1800 | return "Lierda Science & Technology Group Co., Ltd."; 1801 | case 767: 1802 | return "Silicon Laboratories"; 1803 | case 768: 1804 | return "World Moto Inc."; 1805 | case 769: 1806 | return "Giatec Scientific Inc."; 1807 | case 770: 1808 | return "Loop Devices, Inc"; 1809 | case 771: 1810 | return "IACA electronique"; 1811 | case 772: 1812 | return "Martians Inc"; 1813 | case 773: 1814 | return "Swipp ApS"; 1815 | case 774: 1816 | return "Life Laboratory Inc."; 1817 | case 775: 1818 | return "FUJI INDUSTRIAL CO.,LTD."; 1819 | case 776: 1820 | return "Surefire, LLC"; 1821 | case 777: 1822 | return "Dolby Labs"; 1823 | case 778: 1824 | return "Ellisys"; 1825 | case 779: 1826 | return "Magnitude Lighting Converters"; 1827 | case 780: 1828 | return "Hilti AG"; 1829 | case 781: 1830 | return "Devdata S.r.l."; 1831 | case 782: 1832 | return "Deviceworx"; 1833 | case 783: 1834 | return "Shortcut Labs"; 1835 | case 784: 1836 | return "SGL Italia S.r.l."; 1837 | case 785: 1838 | return "PEEQ DATA"; 1839 | case 786: 1840 | return "Ducere Technologies Pvt Ltd"; 1841 | case 787: 1842 | return "DiveNav, Inc."; 1843 | case 788: 1844 | return "RIIG AI Sp. z o.o."; 1845 | case 789: 1846 | return "Thermo Fisher Scientific"; 1847 | case 790: 1848 | return "AG Measurematics Pvt. Ltd."; 1849 | case 791: 1850 | return "CHUO Electronics CO., LTD."; 1851 | case 792: 1852 | return "Aspenta International"; 1853 | case 793: 1854 | return "Eugster Frismag AG"; 1855 | case 794: 1856 | return "Amber wireless GmbH"; 1857 | case 795: 1858 | return "HQ Inc"; 1859 | case 796: 1860 | return "Lab Sensor Solutions"; 1861 | case 797: 1862 | return "Enterlab ApS"; 1863 | case 798: 1864 | return "Eyefi, Inc."; 1865 | case 799: 1866 | return "MetaSystem S.p.A"; 1867 | case 800: 1868 | return "SONO ELECTRONICS. CO., LTD"; 1869 | case 801: 1870 | return "Jewelbots"; 1871 | case 802: 1872 | return "Compumedics Limited"; 1873 | case 803: 1874 | return "Rotor Bike Components"; 1875 | case 804: 1876 | return "Astro, Inc."; 1877 | case 805: 1878 | return "Amotus Solutions"; 1879 | case 806: 1880 | return "Healthwear Technologies (Changzhou)Ltd"; 1881 | case 807: 1882 | return "Essex Electronics"; 1883 | case 808: 1884 | return "Grundfos A/S"; 1885 | case 809: 1886 | return "Eargo, Inc."; 1887 | case 810: 1888 | return "Electronic Design Lab"; 1889 | case 811: 1890 | return "ESYLUX"; 1891 | case 812: 1892 | return "NIPPON SMT.CO.,Ltd"; 1893 | case 813: 1894 | return "BM innovations GmbH"; 1895 | case 814: 1896 | return "indoormap"; 1897 | case 815: 1898 | return "OttoQ Inc"; 1899 | case 816: 1900 | return "North Pole Engineering"; 1901 | case 817: 1902 | return "3flares Technologies Inc."; 1903 | case 818: 1904 | return "Electrocompaniet A.S."; 1905 | case 819: 1906 | return "Mul-T-Lock"; 1907 | case 820: 1908 | return "Corentium AS"; 1909 | case 821: 1910 | return "Enlighted Inc"; 1911 | case 822: 1912 | return "GISTIC"; 1913 | case 823: 1914 | return "AJP2 Holdings, LLC"; 1915 | case 824: 1916 | return "COBI GmbH"; 1917 | case 825: 1918 | return "Blue Sky Scientific, LLC"; 1919 | case 826: 1920 | return "Appception, Inc."; 1921 | case 827: 1922 | return "Courtney Thorne Limited"; 1923 | case 828: 1924 | return "Virtuosys"; 1925 | case 829: 1926 | return "TPV Technology Limited"; 1927 | case 830: 1928 | return "Monitra SA"; 1929 | case 831: 1930 | return "Automation Components, Inc."; 1931 | case 832: 1932 | return "Letsense s.r.l."; 1933 | case 833: 1934 | return "Etesian Technologies LLC"; 1935 | case 834: 1936 | return "GERTEC BRASIL LTDA."; 1937 | case 835: 1938 | return "Drekker Development Pty. Ltd."; 1939 | case 836: 1940 | return "Whirl Inc"; 1941 | case 837: 1942 | return "Locus Positioning"; 1943 | case 838: 1944 | return "Acuity Brands Lighting, Inc"; 1945 | case 839: 1946 | return "Prevent Biometrics"; 1947 | case 840: 1948 | return "Arioneo"; 1949 | case 841: 1950 | return "VersaMe"; 1951 | case 842: 1952 | return "Vaddio"; 1953 | case 843: 1954 | return "Libratone A/S"; 1955 | case 844: 1956 | return "HM Electronics, Inc."; 1957 | case 845: 1958 | return "TASER International, Inc."; 1959 | case 846: 1960 | return "Safe Trust Inc."; 1961 | case 847: 1962 | return "Heartland Payment Systems"; 1963 | case 848: 1964 | return "Bitstrata Systems Inc."; 1965 | case 849: 1966 | return "Pieps GmbH"; 1967 | case 850: 1968 | return "iRiding(Xiamen)Technology Co.,Ltd."; 1969 | case 851: 1970 | return "Alpha Audiotronics, Inc."; 1971 | case 852: 1972 | return "TOPPAN FORMS CO.,LTD."; 1973 | case 853: 1974 | return "Sigma Designs, Inc."; 1975 | case 854: 1976 | return "Spectrum Brands, Inc."; 1977 | case 855: 1978 | return "Polymap Wireless"; 1979 | case 856: 1980 | return "MagniWare Ltd."; 1981 | case 857: 1982 | return "Novotec Medical GmbH"; 1983 | case 858: 1984 | return "Medicom Innovation Partner a/s"; 1985 | case 859: 1986 | return "Matrix Inc."; 1987 | case 860: 1988 | return "Eaton Corporation"; 1989 | case 861: 1990 | return "KYS"; 1991 | case 862: 1992 | return "Naya Health, Inc."; 1993 | case 863: 1994 | return "Acromag"; 1995 | case 864: 1996 | return "Insulet Corporation"; 1997 | case 865: 1998 | return "Wellinks Inc."; 1999 | case 866: 2000 | return "ON Semiconductor"; 2001 | case 867: 2002 | return "FREELAP SA"; 2003 | case 868: 2004 | return "Favero Electronics Srl"; 2005 | case 869: 2006 | return "BioMech Sensor LLC"; 2007 | case 870: 2008 | return "BOLTT Sports technologies Private limited"; 2009 | case 871: 2010 | return "Saphe International"; 2011 | case 872: 2012 | return "Metormote AB"; 2013 | case 873: 2014 | return "littleBits"; 2015 | case 874: 2016 | return "SetPoint Medical"; 2017 | case 875: 2018 | return "BRControls Products BV"; 2019 | case 876: 2020 | return "Zipcar"; 2021 | case 877: 2022 | return "AirBolt Pty Ltd"; 2023 | case 878: 2024 | return "KeepTruckin Inc"; 2025 | case 879: 2026 | return "Motiv, Inc."; 2027 | case 880: 2028 | return "Wazombi Labs O脺"; 2029 | case 881: 2030 | return "ORBCOMM"; 2031 | case 882: 2032 | return "Nixie Labs, Inc."; 2033 | case 883: 2034 | return "AppNearMe Ltd"; 2035 | case 884: 2036 | return "Holman Industries"; 2037 | case 885: 2038 | return "Expain AS"; 2039 | case 886: 2040 | return "Electronic Temperature Instruments Ltd"; 2041 | case 887: 2042 | return "Plejd AB"; 2043 | case 888: 2044 | return "Propeller Health"; 2045 | case 889: 2046 | return "Shenzhen iMCO Electronic Technology Co.,Ltd"; 2047 | case 890: 2048 | return "Algoria"; 2049 | case 891: 2050 | return "Apption Labs Inc."; 2051 | case 892: 2052 | return "Cronologics Corporation"; 2053 | case 893: 2054 | return "MICRODIA Ltd."; 2055 | case 894: 2056 | return "lulabytes S.L."; 2057 | case 895: 2058 | return "Nestec S.A."; 2059 | case 896: 2060 | return "LLC \"MEGA-F service\""; 2061 | case 897: 2062 | return "Sharp Corporation"; 2063 | case 898: 2064 | return "Precision Outcomes Ltd"; 2065 | case 899: 2066 | return "Kronos Incorporated"; 2067 | case 900: 2068 | return "OCOSMOS Co., Ltd."; 2069 | case 901: 2070 | return "Embedded Electronic Solutions Ltd. dba e2Solutions"; 2071 | case 902: 2072 | return "Aterica Inc."; 2073 | case 903: 2074 | return "BluStor PMC, Inc."; 2075 | case 904: 2076 | return "Kapsch TrafficCom AB"; 2077 | case 905: 2078 | return "ActiveBlu Corporation"; 2079 | case 906: 2080 | return "Kohler Mira Limited"; 2081 | case 907: 2082 | return "Noke"; 2083 | case 908: 2084 | return "Appion Inc."; 2085 | case 909: 2086 | return "Resmed Ltd"; 2087 | case 910: 2088 | return "Crownstone B.V."; 2089 | case 911: 2090 | return "Xiaomi Inc."; 2091 | case 912: 2092 | return "INFOTECH s.r.o."; 2093 | case 913: 2094 | return "Thingsquare AB"; 2095 | case 914: 2096 | return "T&D"; 2097 | case 915: 2098 | return "LAVAZZA S.p.A."; 2099 | case 916: 2100 | return "Netclearance Systems, Inc."; 2101 | case 917: 2102 | return "SDATAWAY"; 2103 | case 918: 2104 | return "BLOKS GmbH"; 2105 | case 919: 2106 | return "LEGO System A/S"; 2107 | case 920: 2108 | return "Thetatronics Ltd"; 2109 | case 921: 2110 | return "Nikon Corporation"; 2111 | case 922: 2112 | return "NeST"; 2113 | case 923: 2114 | return "South Silicon Valley Microelectronics"; 2115 | case 924: 2116 | return "ALE International"; 2117 | case 925: 2118 | return "CareView Communications, Inc."; 2119 | case 926: 2120 | return "SchoolBoard Limited"; 2121 | case 927: 2122 | return "Molex Corporation"; 2123 | case 928: 2124 | return "IVT Wireless Limited"; 2125 | case 929: 2126 | return "Alpine Labs LLC"; 2127 | case 930: 2128 | return "Candura Instruments"; 2129 | case 931: 2130 | return "SmartMovt Technology Co., Ltd"; 2131 | case 932: 2132 | return "Token Zero Ltd"; 2133 | case 933: 2134 | return "ACE CAD Enterprise Co., Ltd. (ACECAD)"; 2135 | case 934: 2136 | return "Medela, Inc"; 2137 | case 935: 2138 | return "AeroScout"; 2139 | case 936: 2140 | return "Esrille Inc."; 2141 | case 937: 2142 | return "THINKERLY SRL"; 2143 | case 938: 2144 | return "Exon Sp. z o.o."; 2145 | case 939: 2146 | return "Meizu Technology Co., Ltd."; 2147 | case 940: 2148 | return "Smablo LTD"; 2149 | case 941: 2150 | return "XiQ"; 2151 | case 942: 2152 | return "Allswell Inc."; 2153 | case 943: 2154 | return "Comm-N-Sense Corp DBA Verigo"; 2155 | case 944: 2156 | return "VIBRADORM GmbH"; 2157 | case 945: 2158 | return "Otodata Wireless Network Inc."; 2159 | case 946: 2160 | return "Propagation Systems Limited"; 2161 | case 947: 2162 | return "Midwest Instruments & Controls"; 2163 | case 948: 2164 | return "Alpha Nodus, inc."; 2165 | case 949: 2166 | return "petPOMM, Inc"; 2167 | case 950: 2168 | return "Mattel"; 2169 | case 951: 2170 | return "Airbly Inc."; 2171 | case 952: 2172 | return "A-Safe Limited"; 2173 | case 953: 2174 | return "FREDERIQUE CONSTANT SA"; 2175 | case 954: 2176 | return "Maxscend Microelectronics Company Limited"; 2177 | case 955: 2178 | return "Abbott Diabetes Care"; 2179 | case 956: 2180 | return "ASB Bank Ltd"; 2181 | case 957: 2182 | return "amadas"; 2183 | case 958: 2184 | return "Applied Science, Inc."; 2185 | case 959: 2186 | return "iLumi Solutions Inc."; 2187 | case 960: 2188 | return "Arch Systems Inc."; 2189 | case 961: 2190 | return "Ember Technologies, Inc."; 2191 | case 962: 2192 | return "Snapchat Inc"; 2193 | case 963: 2194 | return "Casambi Technologies Oy"; 2195 | case 964: 2196 | return "Pico Technology Inc."; 2197 | case 965: 2198 | return "St. Jude Medical, Inc."; 2199 | case 966: 2200 | return "Intricon"; 2201 | case 967: 2202 | return "Structural Health Systems, Inc."; 2203 | case 968: 2204 | return "Avvel International"; 2205 | case 969: 2206 | return "Gallagher Group"; 2207 | case 970: 2208 | return "In2things Automation Pvt. Ltd."; 2209 | case 971: 2210 | return "SYSDEV Srl"; 2211 | case 972: 2212 | return "Vonkil Technologies Ltd"; 2213 | case 973: 2214 | return "Wynd Technologies, Inc."; 2215 | case 974: 2216 | return "CONTRINEX S.A."; 2217 | case 975: 2218 | return "MIRA, Inc."; 2219 | case 976: 2220 | return "Watteam Ltd"; 2221 | case 977: 2222 | return "Density Inc."; 2223 | case 978: 2224 | return "IOT Pot India Private Limited"; 2225 | case 979: 2226 | return "Sigma Connectivity AB"; 2227 | case 980: 2228 | return "PEG PEREGO SPA"; 2229 | case 981: 2230 | return "Wyzelink Systems Inc."; 2231 | case 982: 2232 | return "Yota Devices LTD"; 2233 | case 983: 2234 | return "FINSECUR"; 2235 | case 984: 2236 | return "Zen-Me Labs Ltd"; 2237 | case 985: 2238 | return "3IWare Co., Ltd."; 2239 | case 986: 2240 | return "EnOcean GmbH"; 2241 | case 987: 2242 | return "Instabeat, Inc"; 2243 | case 988: 2244 | return "Nima Labs"; 2245 | case 989: 2246 | return "Andreas Stihl AG & Co. KG"; 2247 | case 990: 2248 | return "Nathan Rhoades LLC"; 2249 | case 991: 2250 | return "Grob Technologies, LLC"; 2251 | case 992: 2252 | return "Actions (Zhuhai) Technology Co., Limited"; 2253 | case 993: 2254 | return "SPD Development Company Ltd"; 2255 | case 994: 2256 | return "Sensoan Oy"; 2257 | case 995: 2258 | return "Qualcomm Life Inc"; 2259 | case 996: 2260 | return "Chip-ing AG"; 2261 | case 997: 2262 | return "ffly4u"; 2263 | case 998: 2264 | return "IoT Instruments Oy"; 2265 | case 999: 2266 | return "TRUE Fitness Technology"; 2267 | case 1000: 2268 | return "Reiner Kartengeraete GmbH & Co. KG."; 2269 | case 1001: 2270 | return "SHENZHEN LEMONJOY TECHNOLOGY CO., LTD."; 2271 | case 1002: 2272 | return "Hello Inc."; 2273 | case 1003: 2274 | return "Evollve Inc."; 2275 | case 1004: 2276 | return "Jigowatts Inc."; 2277 | case 1005: 2278 | return "BASIC MICRO.COM,INC."; 2279 | case 1006: 2280 | return "CUBE TECHNOLOGIES"; 2281 | case 1007: 2282 | return "foolography GmbH"; 2283 | case 1008: 2284 | return "CLINK"; 2285 | case 1009: 2286 | return "Hestan Smart Cooking Inc."; 2287 | case 1010: 2288 | return "WindowMaster A/S"; 2289 | case 1011: 2290 | return "Flowscape AB"; 2291 | case 1012: 2292 | return "PAL Technologies Ltd"; 2293 | case 1013: 2294 | return "WHERE, Inc."; 2295 | case 1014: 2296 | return "Iton Technology Corp."; 2297 | case 1015: 2298 | return "Owl Labs Inc."; 2299 | case 1016: 2300 | return "Rockford Corp."; 2301 | case 1017: 2302 | return "Becon Technologies Co.,Ltd."; 2303 | case 1018: 2304 | return "Vyassoft Technologies Inc"; 2305 | case 1019: 2306 | return "Nox Medical"; 2307 | case 1020: 2308 | return "Kimberly-Clark"; 2309 | case 1021: 2310 | return "Trimble Navigation Ltd."; 2311 | case 1022: 2312 | return "Littelfuse"; 2313 | case 1023: 2314 | return "Withings"; 2315 | case 1024: 2316 | return "i-developer IT Beratung UG"; 2317 | case 1025: 2318 | return "銉儸銉笺偡銉с兂銈烘牚寮忎細绀�"; 2319 | case 1026: 2320 | return "Sears Holdings Corporation"; 2321 | case 1027: 2322 | return "Gantner Electronic GmbH"; 2323 | case 1028: 2324 | return "Authomate Inc"; 2325 | case 1029: 2326 | return "Vertex International, Inc."; 2327 | case 1030: 2328 | return "Airtago"; 2329 | case 1031: 2330 | return "Swiss Audio SA"; 2331 | case 1032: 2332 | return "ToGetHome Inc."; 2333 | case 1033: 2334 | return "AXIS"; 2335 | case 1034: 2336 | return "Openmatics"; 2337 | case 1035: 2338 | return "Jana Care Inc."; 2339 | case 1036: 2340 | return "Senix Corporation"; 2341 | case 1037: 2342 | return "NorthStar Battery Company, LLC"; 2343 | case 65535: 2344 | return "internal use"; 2345 | default: 2346 | return "not assigned"; 2347 | } 2348 | } 2349 | -------------------------------------------------------------------------------- /ble_socket/src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangjfblue/bluezTest/4ae45c07490268724baac6055f46d259dce360fb/ble_socket/src/main.c -------------------------------------------------------------------------------- /ble_socket/src/uuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2011 Nokia Corporation 6 | * Copyright (C) 2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "bluetooth.h" 34 | #include "uuid.h" 35 | 36 | static uint128_t bluetooth_base_uuid = { 37 | .data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 38 | 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB } 39 | }; 40 | 41 | #define BASE_UUID16_OFFSET 2 42 | #define BASE_UUID32_OFFSET 0 43 | 44 | #define NULL ((void *)0) 45 | 46 | static void bt_uuid16_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst) 47 | { 48 | uint16_t be16; 49 | 50 | dst->value.u128 = bluetooth_base_uuid; 51 | dst->type = BT_UUID128; 52 | 53 | /* 54 | * No matter the system: 128-bit UUIDs should be stored 55 | * as big-endian. 16-bit UUIDs are stored on host order. 56 | */ 57 | 58 | be16 = htons(src->value.u16); 59 | memcpy(&dst->value.u128.data[BASE_UUID16_OFFSET], &be16, sizeof(be16)); 60 | } 61 | 62 | static void bt_uuid32_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst) 63 | { 64 | uint32_t be32; 65 | 66 | dst->value.u128 = bluetooth_base_uuid; 67 | dst->type = BT_UUID128; 68 | 69 | /* 70 | * No matter the system: 128-bit UUIDs should be stored 71 | * as big-endian. 32-bit UUIDs are stored on host order. 72 | */ 73 | 74 | be32 = htonl(src->value.u32); 75 | memcpy(&dst->value.u128.data[BASE_UUID32_OFFSET], &be32, sizeof(be32)); 76 | } 77 | 78 | void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst) 79 | { 80 | switch (src->type) { 81 | case BT_UUID128: 82 | *dst = *src; 83 | break; 84 | case BT_UUID32: 85 | bt_uuid32_to_uuid128(src, dst); 86 | break; 87 | case BT_UUID16: 88 | bt_uuid16_to_uuid128(src, dst); 89 | break; 90 | case BT_UUID_UNSPEC: 91 | default: 92 | break; 93 | } 94 | } 95 | 96 | static int bt_uuid128_cmp(const bt_uuid_t *u1, const bt_uuid_t *u2) 97 | { 98 | return memcmp(&u1->value.u128, &u2->value.u128, sizeof(uint128_t)); 99 | } 100 | 101 | int bt_uuid16_create(bt_uuid_t *btuuid, uint16_t value) 102 | { 103 | memset(btuuid, 0, sizeof(bt_uuid_t)); 104 | btuuid->type = BT_UUID16; 105 | btuuid->value.u16 = value; 106 | 107 | return 0; 108 | } 109 | 110 | int bt_uuid32_create(bt_uuid_t *btuuid, uint32_t value) 111 | { 112 | memset(btuuid, 0, sizeof(bt_uuid_t)); 113 | btuuid->type = BT_UUID32; 114 | btuuid->value.u32 = value; 115 | 116 | return 0; 117 | } 118 | 119 | int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value) 120 | { 121 | memset(btuuid, 0, sizeof(bt_uuid_t)); 122 | btuuid->type = BT_UUID128; 123 | btuuid->value.u128 = value; 124 | 125 | return 0; 126 | } 127 | 128 | int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2) 129 | { 130 | bt_uuid_t u1, u2; 131 | 132 | bt_uuid_to_uuid128(uuid1, &u1); 133 | bt_uuid_to_uuid128(uuid2, &u2); 134 | 135 | return bt_uuid128_cmp(&u1, &u2); 136 | } 137 | 138 | /* 139 | * convert the UUID to string, copying a maximum of n characters. 140 | */ 141 | int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n) 142 | { 143 | bt_uuid_t tmp; 144 | unsigned int data0; 145 | unsigned short data1; 146 | unsigned short data2; 147 | unsigned short data3; 148 | unsigned int data4; 149 | unsigned short data5; 150 | const uint8_t *data; 151 | 152 | if (!uuid || uuid->type == BT_UUID_UNSPEC) { 153 | snprintf(str, n, "NULL"); 154 | return -EINVAL; 155 | } 156 | 157 | /* Convert to 128 Bit format */ 158 | bt_uuid_to_uuid128(uuid, &tmp); 159 | data = (uint8_t *) &tmp.value.u128; 160 | 161 | memcpy(&data0, &data[0], 4); 162 | memcpy(&data1, &data[4], 2); 163 | memcpy(&data2, &data[6], 2); 164 | memcpy(&data3, &data[8], 2); 165 | memcpy(&data4, &data[10], 4); 166 | memcpy(&data5, &data[14], 2); 167 | 168 | snprintf(str, n, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", 169 | ntohl(data0), ntohs(data1), 170 | ntohs(data2), ntohs(data3), 171 | ntohl(data4), ntohs(data5)); 172 | 173 | return 0; 174 | } 175 | 176 | static inline int is_uuid128(const char *string) 177 | { 178 | return (strlen(string) == 36 && 179 | string[8] == '-' && 180 | string[13] == '-' && 181 | string[18] == '-' && 182 | string[23] == '-'); 183 | } 184 | 185 | static inline int is_base_uuid128(const char *string) 186 | { 187 | uint16_t uuid; 188 | char dummy[2]; 189 | 190 | if (!is_uuid128(string)) 191 | return 0; 192 | 193 | return sscanf(string, 194 | "0000%04hx-0000-1000-8000-00805%1[fF]9%1[bB]34%1[fF]%1[bB]", 195 | &uuid, dummy, dummy, dummy, dummy) == 5; 196 | } 197 | 198 | static inline int is_uuid32(const char *string) 199 | { 200 | return (strlen(string) == 8 || strlen(string) == 10); 201 | } 202 | 203 | static inline int is_uuid16(const char *string) 204 | { 205 | return (strlen(string) == 4 || strlen(string) == 6); 206 | } 207 | 208 | static int bt_string_to_uuid16(bt_uuid_t *uuid, const char *string) 209 | { 210 | uint16_t u16; 211 | char *endptr = NULL; 212 | 213 | u16 = strtol(string, &endptr, 16); 214 | if (endptr && (*endptr == '\0' || *endptr == '-')) { 215 | bt_uuid16_create(uuid, u16); 216 | return 0; 217 | } 218 | 219 | return -EINVAL; 220 | } 221 | 222 | static int bt_string_to_uuid32(bt_uuid_t *uuid, const char *string) 223 | { 224 | uint32_t u32; 225 | char *endptr = NULL; 226 | 227 | u32 = strtol(string, &endptr, 16); 228 | if (endptr && *endptr == '\0') { 229 | bt_uuid32_create(uuid, u32); 230 | return 0; 231 | } 232 | 233 | return -EINVAL; 234 | } 235 | 236 | static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string) 237 | { 238 | uint32_t data0, data4; 239 | uint16_t data1, data2, data3, data5; 240 | uint128_t u128; 241 | uint8_t *val = (uint8_t *) &u128; 242 | 243 | if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", 244 | &data0, &data1, &data2, 245 | &data3, &data4, &data5) != 6) 246 | return -EINVAL; 247 | 248 | data0 = htonl(data0); 249 | data1 = htons(data1); 250 | data2 = htons(data2); 251 | data3 = htons(data3); 252 | data4 = htonl(data4); 253 | data5 = htons(data5); 254 | 255 | memcpy(&val[0], &data0, 4); 256 | memcpy(&val[4], &data1, 2); 257 | memcpy(&val[6], &data2, 2); 258 | memcpy(&val[8], &data3, 2); 259 | memcpy(&val[10], &data4, 4); 260 | memcpy(&val[14], &data5, 2); 261 | 262 | bt_uuid128_create(uuid, u128); 263 | 264 | return 0; 265 | } 266 | 267 | int bt_string_to_uuid(bt_uuid_t *uuid, const char *string) 268 | { 269 | if (is_base_uuid128(string)) 270 | return bt_string_to_uuid16(uuid, string + 4); 271 | else if (is_uuid128(string)) 272 | return bt_string_to_uuid128(uuid, string); 273 | else if (is_uuid32(string)) 274 | return bt_string_to_uuid32(uuid, string); 275 | else if (is_uuid16(string)) 276 | return bt_string_to_uuid16(uuid, string); 277 | 278 | return -EINVAL; 279 | } 280 | 281 | int bt_uuid_strcmp(const void *a, const void *b) 282 | { 283 | bt_uuid_t u1, u2; 284 | 285 | if (bt_string_to_uuid(&u1, a) < 0) 286 | return -EINVAL; 287 | 288 | if (bt_string_to_uuid(&u2, b) < 0) 289 | return -EINVAL; 290 | 291 | return bt_uuid_cmp(&u1, &u2); 292 | } 293 | 294 | int bt_uuid_to_le(const bt_uuid_t *src, void *dst) 295 | { 296 | bt_uuid_t uuid; 297 | 298 | switch (src->type) { 299 | case BT_UUID16: 300 | bt_put_le16(src->value.u16, dst); 301 | return 0; 302 | case BT_UUID32: 303 | bt_uuid32_to_uuid128(src, &uuid); 304 | src = &uuid; 305 | return 0; 306 | /* Fallthrough */ 307 | case BT_UUID128: 308 | /* Convert from 128-bit BE to LE */ 309 | bswap_128(&src->value.u128, dst); 310 | return 0; 311 | case BT_UUID_UNSPEC: 312 | default: 313 | return -EINVAL; 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /start_bluetooth: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export PATH="$PATH:/mnt/platform/bin:/mnt/platform/sbin" 3 | export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/mnt/platform/lib" 4 | 5 | for i in $(seq 3) 6 | do 7 | if test -e /mnt/tmp/hciname 8 | then 9 | sync 10 | read hciname < /mnt/tmp/hciname 11 | if [ $? -eq 0 ] 12 | then 13 | echo "bluetooth name has been write" 14 | break 15 | else 16 | echo "/mnt/tmp/hciname has been found,but not write" 17 | sync 18 | fi 19 | else 20 | echo "/mnt/tmp/hciname has not been found, so find it again" 21 | sync 22 | fi 23 | done 24 | 25 | #init and enable to switch the bluetooth device gpio 26 | dev_up () { 27 | echo 1 > /sys/class/gpio/pioA7/value 28 | usleep 110000 29 | hciattach /dev/ttyS2 texas 30 | 31 | } 32 | 33 | #unenable to switch the bluetooth device gpio,and kill the hciattach process 34 | dev_down () { 35 | killall -q hciattach 36 | echo 0 > /sys/class/gpio/pioA7/value 37 | } 38 | 39 | #run the bluetoothd process,and set the agent 40 | main_up () { 41 | bluetoothd #the Bluetooth daemon 42 | usleep 50000 43 | usleep 50000 44 | 45 | agent --path /org/bluez/agent 1234 & 46 | } 47 | 48 | #kill the bluetoothd and agent process 49 | main_down () { 50 | killall -q agent 51 | killall -q bluetoothd 52 | } 53 | 54 | #open and set the bluetooth services 55 | srv_up () { 56 | pand -s -r NAP -M -u /etc/init.d/bnep_up.sh 57 | sdptool add SP 58 | usleep 10 59 | hciconfig hci0 piscan auth sspmode 1 60 | } 61 | 62 | #stop and kill the bluetooth services 63 | srv_down () { 64 | killall -q pand 65 | killall -q rfcomm 66 | } 67 | 68 | 69 | #accorfing to the commond params to switch start/stop/restart 70 | case $1 in 71 | start) 72 | $0 stop 73 | dev_up #使能硬件gpio,开启蓝牙功能 74 | main_up #开启蓝牙守护进程,并设置配对信息 75 | srv_up #开启蓝牙服务 76 | hciconfig Set name $hciname #设置本机蓝牙名字 77 | hciconfig hci0 up 78 | hciconfig hci0 noauth #设置禁用身份验证 79 | hciconfig hci0 down 80 | hciconfig hci0 up 81 | echo "bluetooth start ok" 82 | ;; 83 | stop) 84 | srv_down 85 | main_down 86 | dev_down 87 | ;; 88 | restart) 89 | $0 stop 90 | sleep 1 91 | $0 start 92 | ;; 93 | *) 94 | echo "Usage: $0 start|stop|restart" 95 | esac 96 | --------------------------------------------------------------------------------