#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
+/* Mesh Profile 1.0 Section 6.6:
+ * "The timeout for the SAR transfer is 20 seconds. When the timeout
+ * expires, the Proxy Server shall disconnect."
+ */
+#define PROXY_SAR_TIMEOUT K_SECONDS(20)
+
#define SAR_COMPLETE 0x00
#define SAR_FIRST 0x01
#define SAR_CONT 0x02
static bool prov_fast_adv;
#endif
-enum {
- SAR_TIMER_START, /* Timer for SAR transfer has been started */
- NUM_FLAGS,
-};
-
-#define PROXY_SAR_TRANS_TIMEOUT K_SECONDS(20)
-
static struct bt_mesh_proxy_client {
struct bt_mesh_conn *conn;
u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE];
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
struct k_work send_beacons;
#endif
+ struct k_delayed_work sar_timer;
struct net_buf_simple buf;
- /* Proxy Server: 20s timeout for each segmented proxy pdu */
- BLE_MESH_ATOMIC_DEFINE(flags, NUM_FLAGS);
- struct k_delayed_work sar_timer;
} clients[BLE_MESH_MAX_CONN] = {
[0 ... (BLE_MESH_MAX_CONN - 1)] = {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
return NULL;
}
+static void proxy_sar_timeout(struct k_work *work)
+{
+ struct bt_mesh_proxy_client *client = NULL;
+
+ BT_WARN("Proxy SAR timeout");
+
+ client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work);
+ if (!client || !client->conn) {
+ BT_ERR("%s, Invalid proxy client parameter", __func__);
+ return;
+ }
+
+ net_buf_simple_reset(&client->buf);
+ bt_mesh_gatts_disconnect(client->conn, 0x13);
+}
+
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
/* Next subnet in queue to be advertised */
static int next_idx;
return -EINVAL;
}
- if (!bt_mesh_atomic_test_and_set_bit(client->flags, SAR_TIMER_START)) {
- k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TRANS_TIMEOUT);
- }
-
+ k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
client->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
break;
return -EINVAL;
}
+ k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
break;
return -EINVAL;
}
- if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) {
- k_delayed_work_cancel(&client->sar_timer);
- }
-
+ k_delayed_work_cancel(&client->sar_timer);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
proxy_complete_pdu(client);
break;
bt_mesh_pb_gatt_close(conn);
}
- if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) {
- k_delayed_work_cancel(&client->sar_timer);
- }
-
+ k_delayed_work_cancel(&client->sar_timer);
bt_mesh_conn_unref(client->conn);
client->conn = NULL;
break;
.disconnected = proxy_disconnected,
};
-static void proxy_recv_timeout(struct k_work *work)
-{
- struct bt_mesh_proxy_client *client = NULL;
-
- BT_DBG("%s", __func__);
-
- client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work);
- if (!client || !client->conn) {
- BT_ERR("%s, Invalid proxy client parameter", __func__);
- return;
- }
-
- bt_mesh_atomic_clear_bit(client->flags, SAR_TIMER_START);
- net_buf_simple_reset(&client->buf);
- bt_mesh_gatts_disconnect(client->conn, 0x13);
-}
-
int bt_mesh_proxy_init(void)
{
int i;
client->buf.size = CLIENT_BUF_SIZE;
client->buf.__buf = client_buf_data + (i * CLIENT_BUF_SIZE);
- k_delayed_work_init(&client->sar_timer, proxy_recv_timeout);
+
+ k_delayed_work_init(&client->sar_timer, proxy_sar_timeout);
}
bt_mesh_gatts_conn_cb_register(&conn_callbacks);