return false;
}
+static bool set_discoverable(uint8_t mode, uint16_t timeout)
+{
+ struct mgmt_cp_set_discoverable cp;
+
+ memset(&cp, 0, sizeof(cp));
+ cp.val = mode;
+ cp.timeout = htobs(timeout);
+
+ DBG("mode %u timeout %u", mode, timeout);
+
+ if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DISCOVERABLE,
+ adapter->index, sizeof(cp), &cp,
+ set_mode_complete, adapter, NULL) > 0)
+ return true;
+
+ error("Failed to set mode discoverable");
+
+ return false;
+}
+
static void send_adapter_name(void)
{
struct hal_ev_adapter_props_changed *ev;
}
}
+static uint8_t set_scan_mode(void *buf, uint16_t len)
+{
+ uint8_t *mode = buf;
+ bool conn, disc, cur_conn, cur_disc;
+
+ cur_conn = adapter->current_settings & MGMT_SETTING_CONNECTABLE;
+ cur_disc = adapter->current_settings & MGMT_SETTING_DISCOVERABLE;
+
+ DBG("connectable %u discoverable %d mode %u", cur_conn, cur_disc,
+ *mode);
+
+ switch (*mode) {
+ case HAL_ADAPTER_SCAN_MODE_NONE:
+ if (!cur_conn && !cur_disc)
+ return HAL_STATUS_DONE;
+
+ conn = false;
+ disc = false;
+ break;
+ case HAL_ADAPTER_SCAN_MODE_CONN:
+ if (cur_conn && !cur_disc)
+ return HAL_STATUS_DONE;
+
+ conn = true;
+ disc = false;
+ break;
+ case HAL_ADAPTER_SCAN_MODE_CONN_DISC:
+ if (cur_conn && cur_disc)
+ return HAL_STATUS_DONE;
+
+ conn = true;
+ disc = true;
+ break;
+ default:
+ return HAL_STATUS_FAILED;
+ }
+
+ if (cur_conn != conn) {
+ if (!set_mode(MGMT_OP_SET_CONNECTABLE, conn ? 0x01 : 0x00))
+ return HAL_STATUS_FAILED;
+ }
+
+ if (cur_disc != disc) {
+ if (!set_discoverable(disc ? 0x01 : 0x00, 0))
+ return HAL_STATUS_FAILED;
+ }
+
+ return HAL_STATUS_SUCCESS;
+}
+
static uint8_t set_property(void *buf, uint16_t len)
{
struct hal_cmd_set_adapter_prop *cmd = buf;
switch (cmd->type) {
- case HAL_PROP_ADAPTER_NAME:
case HAL_PROP_ADAPTER_SCAN_MODE:
+ return set_scan_mode(cmd->val, cmd->len);
+ case HAL_PROP_ADAPTER_NAME:
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
default:
DBG("Unhandled property type 0x%x", cmd->type);