diff --git a/android/gatt.c b/android/gatt.c
index 2ddbf29..31558d0 100644
--- a/android/gatt.c
+++ b/android/gatt.c
return sec_level;
}
-static bool set_security(struct gatt_device *device, int auth_type)
+static bool set_security(struct gatt_device *device, int req_sec_level)
{
- int req_sec_level, sec_level;
+ int sec_level;
GError *gerr = NULL;
GIOChannel *io;
- switch (auth_type) {
- case HAL_GATT_AUTHENTICATION_MITM:
- req_sec_level = BT_SECURITY_HIGH;
- break;
- case HAL_GATT_AUTHENTICATION_NO_MITM:
- req_sec_level = BT_SECURITY_MEDIUM;
- break;
- case HAL_GATT_AUTHENTICATION_NONE:
- req_sec_level = BT_SECURITY_LOW;
- break;
- default:
- error("gatt: Invalid auth_type value: %d", auth_type);
- return false;
- }
-
sec_level = get_sec_level(device);
if (sec_level < 0)
return false;
return true;
}
+static bool set_auth_type(struct gatt_device *device, int auth_type)
+{
+ int sec_level;
+
+ switch (auth_type) {
+ case HAL_GATT_AUTHENTICATION_MITM:
+ sec_level = BT_SECURITY_HIGH;
+ break;
+ case HAL_GATT_AUTHENTICATION_NO_MITM:
+ sec_level = BT_SECURITY_MEDIUM;
+ break;
+ case HAL_GATT_AUTHENTICATION_NONE:
+ sec_level = BT_SECURITY_LOW;
+ break;
+ default:
+ error("gatt: Invalid auth_type value: %d", auth_type);
+ return false;
+ }
+
+ return set_security(device, sec_level);
+}
+
static void handle_client_read_characteristic(const void *buf, uint16_t len)
{
const struct hal_cmd_gatt_client_read_characteristic *cmd = buf;
goto failed;
}
- if (!set_security(conn->device, cmd->auth_req)) {
+ if (!set_auth_type(conn->device, cmd->auth_req)) {
error("gatt: Failed to set security %d", cmd->auth_req);
status = HAL_STATUS_FAILED;
free(cb_data);
}
}
- if (!set_security(conn->device, cmd->auth_req)) {
+ if (!set_auth_type(conn->device, cmd->auth_req)) {
error("gatt: Failed to set security %d", cmd->auth_req);
status = HAL_STATUS_FAILED;
goto failed;
goto failed;
}
- if (!set_security(conn->device, cmd->auth_req)) {
+ if (!set_auth_type(conn->device, cmd->auth_req)) {
error("gatt: Failed to set security %d", cmd->auth_req);
status = HAL_STATUS_FAILED;
free(cb_data);
}
}
- if (!set_security(conn->device, cmd->auth_req)) {
+ if (!set_auth_type(conn->device, cmd->auth_req)) {
error("gatt: Failed to set security %d", cmd->auth_req);
status = HAL_STATUS_FAILED;
goto failed;
if (!device)
return HAL_STATUS_FAILED;
- if (!set_security(device, u1))
+ if (!set_auth_type(device, u1))
return HAL_STATUS_FAILED;
return HAL_STATUS_SUCCESS;