From aae8b515c5b769a99bfabad01b922f33399a761a Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 8 Dec 2014 17:47:07 +0100 Subject: [PATCH] android/socket: Add support for dynamic MAP record Android 5.0 uses service name (sic!) for defining instance ID and supported message types. Name passed is in format of "XXYYname" where XX is hex coded instance and YY is hex coded message types mask. This patch adds new mode for Socket HAL in which daemon tries to extract instance ID and message types from service name. --- android/hal-bluetooth.c | 7 ++++++- android/hal-msg.h | 3 +++ android/socket.c | 29 +++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c index 28289d306..e24f7d2af 100644 --- a/android/hal-bluetooth.c +++ b/android/hal-bluetooth.c @@ -554,9 +554,14 @@ static int init(bt_callbacks_t *callbacks) } cmd.service_id = HAL_SERVICE_ID_SOCKET; - cmd.mode = HAL_MODE_DEFAULT; cmd.max_clients = 1; +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0) + cmd.mode = HAL_MODE_SOCKET_DYNAMIC_MAP; +#else + cmd.mode = HAL_MODE_DEFAULT; +#endif + status = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE, sizeof(cmd), &cmd, NULL, NULL, NULL); if (status != BT_STATUS_SUCCESS) { diff --git a/android/hal-msg.h b/android/hal-msg.h index 9d38a9f13..88b0c52c1 100644 --- a/android/hal-msg.h +++ b/android/hal-msg.h @@ -267,6 +267,9 @@ struct hal_rsp_get_connection_state { /* Bluetooth Socket HAL api */ +#define HAL_MODE_SOCKET_DEFAULT HAL_MODE_DEFAULT +#define HAL_MODE_SOCKET_DYNAMIC_MAP 0x01 + #define HAL_SOCK_RFCOMM 0x01 #define HAL_SOCK_SCO 0x02 #define HAL_SOCK_L2CAP 0x03 diff --git a/android/socket.c b/android/socket.c index 2b836e922..ec78dcd7e 100644 --- a/android/socket.c +++ b/android/socket.c @@ -89,6 +89,8 @@ struct rfcomm_channel { static bdaddr_t adapter_addr; +static uint8_t hal_mode = HAL_MODE_SOCKET_DEFAULT; + static const uint8_t zero_uuid[16] = { 0 }; /* Simple list of RFCOMM connected sockets */ @@ -313,10 +315,31 @@ static sdp_record_t *create_mas_record(uint8_t chan, const char *svc_name) { sdp_list_t *seq; sdp_profile_desc_t profile[1]; - uint8_t minst = DEFAULT_MAS_INSTANCE; - uint8_t mtype = DEFAULT_MAS_MSG_TYPE; + uint8_t minst, mtype; sdp_record_t *record; uuid_t uuid; + int cnt, ret; + + switch (hal_mode) { + case HAL_MODE_SOCKET_DYNAMIC_MAP: + /* + * Service name for MAP is passed as XXYYname + * XX - instance + * YY - message type + */ + ret = sscanf(svc_name, "%02hhx%02hhx%n", &minst, &mtype, &cnt); + if (ret != 2 || cnt != 4) + return NULL; + + svc_name += 4; + break; + case HAL_MODE_SOCKET_DEFAULT: + minst = DEFAULT_MAS_INSTANCE; + mtype = DEFAULT_MAS_MSG_TYPE; + break; + default: + return NULL; + } sdp_uuid16_create(&uuid, MAP_MSE_SVCLASS_ID); @@ -1147,6 +1170,8 @@ void bt_socket_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) DBG(""); + hal_mode = mode; + /* * make sure channels assigned for profiles are reserved and not used * for app services -- 2.47.3