Lines Matching refs:srv

89 } srv = {  variable
97 return srv.refresh.procedure; in bt_mesh_node_refresh_get()
104 for (i = 0; i < srv.scan.max_devs; ++i) { in unprov_get()
106 if ((srv.scan.devs[i].flags & BT_MESH_RPR_UNPROV_ACTIVE) && in unprov_get()
107 !memcmp(srv.scan.devs[i].uuid, uuid, 16)) { in unprov_get()
108 return &srv.scan.devs[i]; in unprov_get()
110 } else if (!(srv.scan.devs[i].flags & BT_MESH_RPR_UNPROV_ACTIVE)) { in unprov_get()
111 return &srv.scan.devs[i]; in unprov_get()
134 srv.scan.cli.addr = BT_MESH_ADDR_UNASSIGNED; in cli_scan_clear()
135 srv.scan.cli.net_idx = BT_MESH_KEY_UNUSED; in cli_scan_clear()
140 srv.link.cli.addr = BT_MESH_ADDR_UNASSIGNED; in cli_link_clear()
141 srv.link.cli.net_idx = BT_MESH_KEY_UNUSED; in cli_link_clear()
149 if (atomic_test_bit(srv.flags, SCANNING)) { in scan_status_send()
151 k_work_delayable_remaining_get(&srv.scan.timeout)) / in scan_status_send()
158 net_buf_simple_add_u8(&rsp, srv.scan.state); in scan_status_send()
159 net_buf_simple_add_u8(&rsp, srv.scan.max_devs); in scan_status_send()
162 bt_mesh_model_send(srv.mod, ctx, &rsp, NULL, NULL); in scan_status_send()
171 net_buf_simple_add_u8(&buf, srv.link.state); in link_status_send()
173 bt_mesh_model_send(srv.mod, ctx, &buf, NULL, NULL); in link_status_send()
178 struct bt_mesh_msg_ctx ctx = LINK_CTX(&srv.link.cli, true); in link_report_send()
182 net_buf_simple_add_u8(&buf, srv.link.status); in link_report_send()
183 net_buf_simple_add_u8(&buf, srv.link.state); in link_report_send()
184 if (srv.link.status == BT_MESH_RPR_ERR_LINK_CLOSED_BY_SERVER || in link_report_send()
185 srv.link.status == BT_MESH_RPR_ERR_LINK_CLOSED_BY_DEVICE) { in link_report_send()
186 net_buf_simple_add_u8(&buf, srv.link.close_reason); in link_report_send()
189 LOG_DBG("%u %u", srv.link.status, srv.link.state); in link_report_send()
191 bt_mesh_model_send(srv.mod, &ctx, &buf, NULL, NULL); in link_report_send()
198 if (k_work_delayable_remaining_get(&srv.scan.report) || in scan_report_schedule()
199 atomic_test_bit(srv.flags, SCAN_REPORT_PENDING)) { in scan_report_schedule()
206 k_work_reschedule(&srv.scan.report, K_MSEC(delay)); in scan_report_schedule()
211 atomic_clear_bit(srv.flags, SCAN_REPORT_PENDING); in scan_report_sent()
212 k_work_reschedule(&srv.scan.report, K_NO_WAIT); in scan_report_sent()
221 struct bt_mesh_msg_ctx ctx = LINK_CTX(&srv.scan.cli, true); in scan_report_send()
224 if (atomic_test_bit(srv.flags, SCAN_REPORT_PENDING)) { in scan_report_send()
228 for (i = 0; i < srv.scan.max_devs; ++i) { in scan_report_send()
229 struct bt_mesh_rpr_unprov *dev = &srv.scan.devs[i]; in scan_report_send()
245 atomic_set_bit(srv.flags, SCAN_REPORT_PENDING); in scan_report_send()
247 err = bt_mesh_model_send(srv.mod, &ctx, &buf, &report_cb, NULL); in scan_report_send()
249 atomic_clear_bit(srv.flags, SCAN_REPORT_PENDING); in scan_report_send()
262 struct bt_mesh_msg_ctx ctx = LINK_CTX(&srv.scan.cli, true); in scan_ext_report_send()
269 net_buf_simple_add_mem(&buf, srv.scan.dev->uuid, 16); in scan_ext_report_send()
271 if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_FOUND) { in scan_ext_report_send()
272 net_buf_simple_add_le16(&buf, srv.scan.dev->oob); in scan_ext_report_send()
278 if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_EXT_ADV_RXD) { in scan_ext_report_send()
279 net_buf_simple_add_mem(&buf, srv.scan.adv_data->data, in scan_ext_report_send()
280 srv.scan.adv_data->len); in scan_ext_report_send()
282 bt_hex(srv.scan.adv_data->data, srv.scan.adv_data->len)); in scan_ext_report_send()
285 srv.scan.dev->flags &= ~BT_MESH_RPR_UNPROV_EXT_ADV_RXD; in scan_ext_report_send()
287 err = bt_mesh_model_send(srv.mod, &ctx, &buf, NULL, NULL); in scan_ext_report_send()
289 srv.scan.dev->flags |= BT_MESH_RPR_UNPROV_REPORTED; in scan_ext_report_send()
297 k_work_cancel_delayable(&srv.scan.report); in scan_stop()
298 k_work_cancel_delayable(&srv.scan.timeout); in scan_stop()
299 srv.scan.state = BT_MESH_RPR_SCAN_IDLE; in scan_stop()
301 atomic_clear_bit(srv.flags, SCANNING); in scan_stop()
311 atomic_clear_bit(srv.flags, URI_MATCHED); in scan_ext_stop()
312 atomic_clear_bit(srv.flags, URI_REQUESTED); in scan_ext_stop()
314 if ((remaining_time + srv.scan.additional_time) && in scan_ext_stop()
315 srv.scan.state != BT_MESH_RPR_SCAN_IDLE) { in scan_ext_stop()
317 &srv.scan.timeout, in scan_ext_stop()
318 K_MSEC(remaining_time + srv.scan.additional_time)); in scan_ext_stop()
319 } else if (srv.scan.state == BT_MESH_RPR_SCAN_MULTI) { in scan_ext_stop()
322 } else if (srv.scan.state != BT_MESH_RPR_SCAN_IDLE) { in scan_ext_stop()
326 atomic_clear_bit(srv.flags, SCANNING); in scan_ext_stop()
329 if (!(srv.scan.dev->flags & BT_MESH_RPR_UNPROV_REPORTED)) { in scan_ext_stop()
334 srv.scan.dev = NULL; in scan_ext_stop()
342 LOG_DBG("%s", (srv.scan.dev ? "Extended scanning" : "Normal scanning")); in scan_timeout()
344 if (srv.scan.dev) { in scan_timeout()
355 srv.link.status = status; in link_close()
356 srv.link.close_reason = reason; in link_close()
357 srv.link.state = BT_MESH_RPR_LINK_CLOSING; in link_close()
361 if (atomic_test_and_clear_bit(srv.flags, NODE_REFRESH)) { in link_close()
363 srv.link.state = BT_MESH_RPR_LINK_IDLE; in link_close()
365 srv.refresh.cb->link_closed(&pb_remote_srv, srv.refresh.cb_data, in link_close()
366 srv.link.close_reason); in link_close()
376 struct bt_mesh_msg_ctx ctx = LINK_CTX(&srv.link.cli, true); in outbound_pdu_report_send()
380 net_buf_simple_add_u8(&buf, srv.link.tx_pdu); in outbound_pdu_report_send()
382 LOG_DBG("%u", srv.link.tx_pdu); in outbound_pdu_report_send()
384 bt_mesh_model_send(srv.mod, &ctx, &buf, NULL, NULL); in outbound_pdu_report_send()
392 } else if (srv.link.state == BT_MESH_RPR_LINK_SENDING) { in pdu_send_complete()
393 srv.link.state = BT_MESH_RPR_LINK_ACTIVE; in pdu_send_complete()
394 srv.link.tx_pdu++; in pdu_send_complete()
402 struct bt_mesh_msg_ctx ctx = LINK_CTX(&srv.link.cli, true); in inbound_pdu_send()
406 net_buf_simple_add_u8(&msg, srv.link.rx_pdu); in inbound_pdu_send()
409 return bt_mesh_model_send(srv.mod, &ctx, &msg, cb, NULL); in inbound_pdu_send()
415 if (!srv.mod || evt != BT_MESH_KEY_DELETED) { in subnet_evt_handler()
421 if (srv.link.state != BT_MESH_RPR_LINK_IDLE && in subnet_evt_handler()
422 subnet->net_idx == srv.link.cli.net_idx) { in subnet_evt_handler()
428 srv.link.state = BT_MESH_RPR_LINK_IDLE; in subnet_evt_handler()
429 } else if (atomic_test_bit(srv.flags, SCANNING) && in subnet_evt_handler()
430 subnet->net_idx == srv.scan.cli.net_idx) { in subnet_evt_handler()
446 srv.link.state = BT_MESH_RPR_LINK_ACTIVE; in pb_link_opened()
447 srv.link.status = BT_MESH_RPR_SUCCESS; in pb_link_opened()
460 if (srv.link.state == BT_MESH_RPR_LINK_IDLE) { in pb_link_closed()
466 if (srv.link.state == BT_MESH_RPR_LINK_OPENING) { in pb_link_closed()
467 srv.link.status = BT_MESH_RPR_ERR_LINK_OPEN_FAILED; in pb_link_closed()
469 if (srv.link.state == BT_MESH_RPR_LINK_SENDING) { in pb_link_closed()
470 srv.link.status = in pb_link_closed()
473 srv.link.status = BT_MESH_RPR_ERR_LINK_CLOSED_BY_SERVER; in pb_link_closed()
476 srv.link.status != BT_MESH_RPR_ERR_LINK_CLOSED_BY_CLIENT && in pb_link_closed()
477 srv.link.status != BT_MESH_RPR_ERR_LINK_CLOSED_BY_SERVER) { in pb_link_closed()
478 srv.link.status = BT_MESH_RPR_ERR_LINK_CLOSED_BY_DEVICE; in pb_link_closed()
482 srv.link.close_reason = PROV_BEARER_LINK_STATUS_SUCCESS; in pb_link_closed()
484 srv.link.close_reason = PROV_BEARER_LINK_STATUS_FAIL; in pb_link_closed()
487 srv.link.state = BT_MESH_RPR_LINK_IDLE; in pb_link_closed()
488 k_work_submit(&srv.link.report); in pb_link_closed()
494 if (srv.link.state == BT_MESH_RPR_LINK_IDLE) { in pb_error()
499 srv.link.close_reason = err; in pb_error()
500 srv.link.state = BT_MESH_RPR_LINK_IDLE; in pb_error()
501 srv.link.status = BT_MESH_RPR_ERR_LINK_CLOSED_AS_CANNOT_RECEIVE_PDU; in pb_error()
511 if (srv.link.state != BT_MESH_RPR_LINK_ACTIVE && in pb_rx()
512 srv.link.state != BT_MESH_RPR_LINK_SENDING) { in pb_rx()
516 srv.link.rx_pdu++; in pb_rx()
547 bt_mesh_model_send(srv.mod, ctx, &rsp, NULL, NULL); in handle_scan_caps_get()
590 if (srv.scan.state != BT_MESH_RPR_SCAN_IDLE && in handle_scan_start()
591 !rpr_node_equal(&cli, &srv.scan.cli)) { in handle_scan_start()
596 for (i = 0; i < ARRAY_SIZE(srv.scan.devs); ++i) { in handle_scan_start()
597 srv.scan.devs[i].flags = 0; in handle_scan_start()
601 srv.scan.state = BT_MESH_RPR_SCAN_SINGLE; in handle_scan_start()
603 srv.scan.devs[0].flags = BT_MESH_RPR_UNPROV_ACTIVE; in handle_scan_start()
604 memcpy(srv.scan.devs[0].uuid, uuid, 16); in handle_scan_start()
606 srv.scan.state = BT_MESH_RPR_SCAN_MULTI; in handle_scan_start()
609 srv.scan.max_devs = in handle_scan_start()
612 srv.scan.cli = cli; in handle_scan_start()
615 atomic_set_bit(srv.flags, SCANNING); in handle_scan_start()
616 k_work_reschedule(&srv.scan.timeout, K_SECONDS(timeout)); in handle_scan_start()
721 if (srv.link.state != BT_MESH_RPR_LINK_IDLE) { in handle_extended_scan_start()
726 if (srv.scan.dev && (memcmp(srv.scan.dev->uuid, uuid, 16) || in handle_extended_scan_start()
727 !rpr_node_equal(&srv.scan.cli, &cli))) { in handle_extended_scan_start()
733 if (srv.scan.state == BT_MESH_RPR_SCAN_IDLE) { in handle_extended_scan_start()
734 srv.scan.max_devs = 1; in handle_extended_scan_start()
735 srv.scan.devs[0].flags = 0; in handle_extended_scan_start()
738 srv.scan.dev = unprov_get(uuid); in handle_extended_scan_start()
739 if (!srv.scan.dev) { in handle_extended_scan_start()
740 srv.scan.dev = unprov_get(NULL); in handle_extended_scan_start()
741 if (!srv.scan.dev) { in handle_extended_scan_start()
747 memcpy(srv.scan.dev->uuid, uuid, 16); in handle_extended_scan_start()
748 srv.scan.dev->oob = 0; in handle_extended_scan_start()
749 srv.scan.dev->flags = 0; in handle_extended_scan_start()
752 memcpy(srv.scan.ad, ad, ad_count); in handle_extended_scan_start()
753 srv.scan.ad_count = ad_count; in handle_extended_scan_start()
754 net_buf_simple_reset(srv.scan.adv_data); in handle_extended_scan_start()
756 atomic_set_bit(srv.flags, SCANNING); in handle_extended_scan_start()
757 atomic_clear_bit(srv.flags, SCAN_EXT_HAS_ADDR); in handle_extended_scan_start()
758 srv.scan.dev->flags &= ~BT_MESH_RPR_UNPROV_REPORTED; in handle_extended_scan_start()
759 srv.scan.dev->flags |= BT_MESH_RPR_UNPROV_ACTIVE | BT_MESH_RPR_UNPROV_EXT; in handle_extended_scan_start()
761 if (srv.scan.state == BT_MESH_RPR_SCAN_IDLE) { in handle_extended_scan_start()
762 srv.scan.additional_time = 0; in handle_extended_scan_start()
763 srv.scan.cli = cli; in handle_extended_scan_start()
765 k_work_delayable_remaining_get(&srv.scan.timeout)) < in handle_extended_scan_start()
767 srv.scan.additional_time = 0; in handle_extended_scan_start()
769 srv.scan.additional_time = in handle_extended_scan_start()
770 k_ticks_to_ms_floor32(k_work_delayable_remaining_get(&srv.scan.timeout)) - in handle_extended_scan_start()
775 k_work_reschedule(&srv.scan.timeout, K_SECONDS(timeout)); in handle_extended_scan_start()
790 if (atomic_test_bit(srv.flags, SCANNING)) { in handle_scan_stop()
825 if (srv.link.state == BT_MESH_RPR_LINK_CLOSING || in handle_link_open()
826 srv.link.state == BT_MESH_RPR_LINK_SENDING) { in handle_link_open()
828 LOG_ERR("Invalid state: %u", srv.link.state); in handle_link_open()
832 if (srv.link.state == BT_MESH_RPR_LINK_OPENING || in handle_link_open()
833 srv.link.state == BT_MESH_RPR_LINK_ACTIVE) { in handle_link_open()
835 if (!rpr_node_equal(&cli, &srv.link.cli)) { in handle_link_open()
842 if (!atomic_test_bit(srv.flags, NODE_REFRESH) || in handle_link_open()
843 srv.refresh.procedure != refresh) { in handle_link_open()
852 if (atomic_test_bit(srv.flags, NODE_REFRESH)) { in handle_link_open()
859 if (memcmp(uuid, srv.link.dev->uuid, 16)) { in handle_link_open()
886 atomic_set_bit(srv.flags, NODE_REFRESH); in handle_link_open()
887 srv.refresh.procedure = refresh; in handle_link_open()
888 srv.link.cli = cli; in handle_link_open()
889 srv.link.rx_pdu = 0; in handle_link_open()
890 srv.link.tx_pdu = 0; in handle_link_open()
891 srv.link.state = BT_MESH_RPR_LINK_ACTIVE; in handle_link_open()
892 srv.link.status = BT_MESH_RPR_SUCCESS; in handle_link_open()
893 srv.refresh.cb->link_opened(&pb_remote_srv, &srv); in handle_link_open()
914 srv.link.dev = unprov_get(uuid); in handle_link_open()
915 if (!srv.link.dev) { in handle_link_open()
916 srv.link.dev = &srv.scan.devs[0]; in handle_link_open()
917 memcpy(srv.link.dev->uuid, uuid, 16); in handle_link_open()
918 srv.link.dev->flags = 0; in handle_link_open()
921 err = bt_mesh_pb_adv.link_open(uuid, timeout, &prov_bearer_cb, &srv); in handle_link_open()
927 srv.link.cli = cli; in handle_link_open()
928 srv.link.rx_pdu = 0; in handle_link_open()
929 srv.link.tx_pdu = 0; in handle_link_open()
930 srv.link.state = BT_MESH_RPR_LINK_OPENING; in handle_link_open()
931 srv.link.status = BT_MESH_RPR_SUCCESS; in handle_link_open()
932 srv.link.dev->flags |= BT_MESH_RPR_UNPROV_HAS_LINK; in handle_link_open()
955 if (srv.link.state == BT_MESH_RPR_LINK_IDLE || in handle_link_close()
956 srv.link.state == BT_MESH_RPR_LINK_CLOSING) { in handle_link_close()
961 if (!rpr_node_equal(&cli, &srv.link.cli)) { in handle_link_close()
966 srv.link.state = BT_MESH_RPR_LINK_CLOSING; in handle_link_close()
993 if (srv.link.state != BT_MESH_RPR_LINK_ACTIVE) { in handle_pdu_send()
994 LOG_WRN("Sending PDU while busy (state %u)", srv.link.state); in handle_pdu_send()
998 if (!rpr_node_equal(&cli, &srv.link.cli)) { in handle_pdu_send()
1003 if (pdu_num != srv.link.tx_pdu + 1) { in handle_pdu_send()
1005 srv.link.tx_pdu + 1); in handle_pdu_send()
1012 if (atomic_test_bit(srv.flags, NODE_REFRESH)) { in handle_pdu_send()
1013 srv.link.tx_pdu++; in handle_pdu_send()
1015 srv.refresh.cb->recv(&pb_remote_srv, srv.refresh.cb_data, buf); in handle_pdu_send()
1017 srv.link.state = BT_MESH_RPR_LINK_SENDING; in handle_pdu_send()
1018 err = bt_mesh_pb_adv.send(buf, pdu_send_complete, &srv); in handle_pdu_send()
1058 if (srv.scan.state != BT_MESH_RPR_SCAN_MULTI) { in adv_handle_beacon()
1084 LOG_DBG("Unprov #%u: %s OOB: 0x%04x %s", dev - &srv.scan.devs[0], in adv_handle_beacon()
1089 if (dev != srv.scan.dev && !(dev->flags & BT_MESH_RPR_UNPROV_REPORTED)) { in adv_handle_beacon()
1125 if (atomic_test_bit(srv.flags, SCAN_EXT_HAS_ADDR) && in adv_handle_ext_scan()
1126 !bt_addr_le_cmp(&srv.scan.addr, info->addr)) { in adv_handle_ext_scan()
1127 dev = srv.scan.dev; in adv_handle_ext_scan()
1145 (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_HASH)) { in adv_handle_ext_scan()
1149 memcmp(hash, &srv.scan.dev->hash, 4)) { in adv_handle_ext_scan()
1155 dev = srv.scan.dev; in adv_handle_ext_scan()
1156 srv.scan.dev->flags |= BT_MESH_RPR_UNPROV_EXT_ADV_RXD; in adv_handle_ext_scan()
1161 atomic_set_bit(srv.flags, URI_MATCHED); in adv_handle_ext_scan()
1173 srv.scan.addr = *info->addr; in adv_handle_ext_scan()
1174 atomic_set_bit(srv.flags, SCAN_EXT_HAS_ADDR); in adv_handle_ext_scan()
1190 if (srv.scan.ad_count == 1 && in adv_handle_ext_scan()
1191 get_ad_type(srv.scan.ad, 1, BT_DATA_URI) && in adv_handle_ext_scan()
1196 while (srv.scan.ad_count && pull_ad_data(buf, &ad)) { in adv_handle_ext_scan()
1199 ad_entry = get_ad_type(srv.scan.ad, srv.scan.ad_count, ad.type); in adv_handle_ext_scan()
1207 atomic_set_bit(srv.flags, URI_REQUESTED); in adv_handle_ext_scan()
1211 net_buf_simple_tailroom(srv.scan.adv_data)) { in adv_handle_ext_scan()
1216 net_buf_simple_add_u8(srv.scan.adv_data, ad.data_len + 1); in adv_handle_ext_scan()
1217 net_buf_simple_add_u8(srv.scan.adv_data, ad.type); in adv_handle_ext_scan()
1218 net_buf_simple_add_mem(srv.scan.adv_data, ad.data, ad.data_len); in adv_handle_ext_scan()
1220 *ad_entry = srv.scan.ad[--srv.scan.ad_count]; in adv_handle_ext_scan()
1234 if (!srv.scan.ad_count) { in adv_handle_ext_scan()
1261 if (atomic_get(srv.flags) & URI_REQUESTED && in adv_handle_ext_scan()
1262 (atomic_get(srv.flags) & URI_MATCHED || in adv_handle_ext_scan()
1270 srv.scan.additional_time = 0; in adv_handle_ext_scan()
1271 if (srv.scan.state != BT_MESH_RPR_SCAN_MULTI) { in adv_handle_ext_scan()
1272 k_work_cancel_delayable(&srv.scan.timeout); in adv_handle_ext_scan()
1297 if (!atomic_test_bit(srv.flags, SCANNING)) { in scan_packet_recv()
1301 if (srv.scan.dev) { in scan_packet_recv()
1314 if (mod->rt->elem_idx || srv.mod) { in rpr_srv_init()
1320 srv.mod = mod; in rpr_srv_init()
1322 net_buf_simple_init(srv.scan.adv_data, 0); in rpr_srv_init()
1324 k_work_init_delayable(&srv.scan.timeout, scan_timeout); in rpr_srv_init()
1325 k_work_init_delayable(&srv.scan.report, scan_report_timeout); in rpr_srv_init()
1326 k_work_init(&srv.link.report, link_report_send_and_clear); in rpr_srv_init()
1338 srv.scan.state = BT_MESH_RPR_SCAN_IDLE; in rpr_srv_reset()
1339 srv.link.state = BT_MESH_RPR_LINK_IDLE; in rpr_srv_reset()
1340 k_work_cancel_delayable(&srv.scan.timeout); in rpr_srv_reset()
1341 k_work_cancel_delayable(&srv.scan.report); in rpr_srv_reset()
1342 net_buf_simple_init(srv.scan.adv_data, 0); in rpr_srv_reset()
1343 atomic_clear(srv.flags); in rpr_srv_reset()
1344 srv.link.dev = NULL; in rpr_srv_reset()
1345 srv.scan.dev = NULL; in rpr_srv_reset()
1356 srv.refresh.cb = cb; in node_refresh_link_accept()
1357 srv.refresh.cb_data = cb_data; in node_refresh_link_accept()
1370 if (srv.refresh.tx.cb) { in node_refresh_tx_complete()
1371 srv.refresh.tx.cb(err, srv.refresh.tx.cb_data); in node_refresh_tx_complete()
1383 if (!atomic_test_bit(srv.flags, NODE_REFRESH)) { in node_refresh_buf_send()
1387 srv.refresh.tx.cb = cb; in node_refresh_buf_send()
1388 srv.refresh.tx.cb_data = cb_data; in node_refresh_buf_send()
1389 srv.link.rx_pdu++; in node_refresh_buf_send()
1391 LOG_DBG("%u", srv.link.rx_pdu); in node_refresh_buf_send()