Lines Matching full:ctx

118 static void lp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx);
119 static void lp_comm_terminate_invalid_pdu(struct ll_conn *conn, struct proc_ctx *ctx);
155 static void lp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) in lp_comm_tx() argument
161 tx = llcp_tx_alloc(conn, ctx); in lp_comm_tx()
167 switch (ctx->proc) { in lp_comm_tx()
171 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_PING_RSP; in lp_comm_tx()
176 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_FEATURE_RSP; in lp_comm_tx()
180 llcp_pdu_encode_min_used_chans_ind(ctx, pdu); in lp_comm_tx()
181 ctx->node_ref.tx_ack = tx; in lp_comm_tx()
182 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; in lp_comm_tx()
187 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_VERSION_IND; in lp_comm_tx()
190 llcp_pdu_encode_terminate_ind(ctx, pdu); in lp_comm_tx()
191 ctx->node_ref.tx_ack = tx; in lp_comm_tx()
192 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; in lp_comm_tx()
196 llcp_pdu_encode_cis_terminate_ind(ctx, pdu); in lp_comm_tx()
197 ctx->node_ref.tx_ack = tx; in lp_comm_tx()
198 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; in lp_comm_tx()
204 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_RSP; in lp_comm_tx()
209 llcp_pdu_encode_cte_req(ctx, pdu); in lp_comm_tx()
210 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_CTE_RSP; in lp_comm_tx()
215 llcp_pdu_encode_clock_accuracy_req(ctx, pdu); in lp_comm_tx()
216 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_CLOCK_ACCURACY_RSP; in lp_comm_tx()
224 ctx->tx_opcode = pdu->llctrl.opcode; in lp_comm_tx()
230 if (ctx->proc != PROC_TERMINATE) { in lp_comm_tx()
246 static void lp_comm_ntf_feature_exchange(struct ll_conn *conn, struct proc_ctx *ctx, in lp_comm_ntf_feature_exchange() argument
249 switch (ctx->response_opcode) { in lp_comm_ntf_feature_exchange()
254 llcp_ntf_encode_unknown_rsp(ctx, pdu); in lp_comm_ntf_feature_exchange()
262 static void lp_comm_ntf_version_ind(struct ll_conn *conn, struct proc_ctx *ctx, in lp_comm_ntf_version_ind() argument
265 switch (ctx->response_opcode) { in lp_comm_ntf_version_ind()
276 static void lp_comm_ntf_length_change(struct ll_conn *conn, struct proc_ctx *ctx, in lp_comm_ntf_length_change() argument
291 static void lp_comm_ntf_cte_req(struct ll_conn *conn, struct proc_ctx *ctx, struct pdu_data *pdu) in lp_comm_ntf_cte_req() argument
293 switch (ctx->response_opcode) { in lp_comm_ntf_cte_req()
296 if (!ctx->data.cte_remote_rsp.has_cte) { in lp_comm_ntf_cte_req()
301 llcp_ntf_encode_unknown_rsp(ctx, pdu); in lp_comm_ntf_cte_req()
304 llcp_ntf_encode_reject_ext_ind(ctx, pdu); in lp_comm_ntf_cte_req()
312 static void lp_comm_ntf_cte_req_tx(struct ll_conn *conn, struct proc_ctx *ctx) in lp_comm_ntf_cte_req_tx() argument
314 lp_comm_ntf(conn, ctx); in lp_comm_ntf_cte_req_tx()
316 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_ntf_cte_req_tx()
319 static void lp_comm_complete_cte_req(struct ll_conn *conn, struct proc_ctx *ctx) in lp_comm_complete_cte_req() argument
322 if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_CTE_RSP) { in lp_comm_complete_cte_req()
323 if (ctx->data.cte_remote_rsp.has_cte) { in lp_comm_complete_cte_req()
333 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete_cte_req()
335 lp_comm_ntf_cte_req_tx(conn, ctx); in lp_comm_complete_cte_req()
337 } else if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND && in lp_comm_complete_cte_req()
338 ctx->reject_ext_ind.reject_opcode == PDU_DATA_LLCTRL_TYPE_CTE_REQ) { in lp_comm_complete_cte_req()
339 lp_comm_ntf_cte_req_tx(conn, ctx); in lp_comm_complete_cte_req()
340 } else if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP && in lp_comm_complete_cte_req()
341 ctx->unknown_response.type == PDU_DATA_LLCTRL_TYPE_CTE_REQ) { in lp_comm_complete_cte_req()
346 lp_comm_ntf_cte_req_tx(conn, ctx); in lp_comm_complete_cte_req()
347 } else if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNUSED) { in lp_comm_complete_cte_req()
354 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete_cte_req()
359 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete_cte_req()
365 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete_cte_req()
368 if (ctx->state == LP_COMMON_STATE_IDLE) { in lp_comm_complete_cte_req()
375 static void lp_comm_ntf_sca(struct node_rx_pdu *ntf, struct proc_ctx *ctx, struct pdu_data *pdu) in lp_comm_ntf_sca() argument
380 pdu_sca->status = ctx->data.sca_update.error_code; in lp_comm_ntf_sca()
381 pdu_sca->sca = ctx->data.sca_update.sca; in lp_comm_ntf_sca()
385 static void lp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx) in lp_comm_ntf() argument
391 ntf = ctx->node_ref.rx; in lp_comm_ntf()
392 ctx->node_ref.rx = NULL; in lp_comm_ntf()
404 switch (ctx->proc) { in lp_comm_ntf()
406 lp_comm_ntf_feature_exchange(conn, ctx, pdu); in lp_comm_ntf()
409 lp_comm_ntf_version_ind(conn, ctx, pdu); in lp_comm_ntf()
413 lp_comm_ntf_length_change(conn, ctx, pdu); in lp_comm_ntf()
418 lp_comm_ntf_cte_req(conn, ctx, pdu); in lp_comm_ntf()
423 lp_comm_ntf_sca(ntf, ctx, pdu); in lp_comm_ntf()
441 static void lp_comm_terminate_invalid_pdu(struct ll_conn *conn, struct proc_ctx *ctx) in lp_comm_terminate_invalid_pdu() argument
447 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_terminate_invalid_pdu()
450 static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) in lp_comm_complete() argument
452 switch (ctx->proc) { in lp_comm_complete()
455 if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP || in lp_comm_complete()
456 ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_PING_RSP) { in lp_comm_complete()
458 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
461 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete()
466 if ((ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP || in lp_comm_complete()
467 ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_FEATURE_RSP)) { in lp_comm_complete()
468 if (ctx->data.fex.host_initiated) { in lp_comm_complete()
469 lp_comm_ntf(conn, ctx); in lp_comm_complete()
472 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
475 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete()
481 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
485 if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_VERSION_IND) { in lp_comm_complete()
486 if (ctx->node_ref.rx || llcp_ntf_alloc_is_available()) { in lp_comm_complete()
488 lp_comm_ntf(conn, ctx); in lp_comm_complete()
490 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
498 ctx->state = LP_COMMON_STATE_WAIT_NTF_AVAIL; in lp_comm_complete()
502 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete()
508 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
517 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
522 if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_LENGTH_RSP) { in lp_comm_complete()
527 lp_comm_ntf(conn, ctx); in lp_comm_complete()
530 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
531 } else if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP) { in lp_comm_complete()
536 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
539 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete()
553 lp_comm_complete_cte_req(conn, ctx); in lp_comm_complete()
558 switch (ctx->response_opcode) { in lp_comm_complete()
562 ctx->data.sca_update.error_code = BT_HCI_ERR_UNSUPP_FEATURE_PARAM_VAL; in lp_comm_complete()
567 !ctx->data.sca_update.error_code && in lp_comm_complete()
568 conn->periph.sca != ctx->data.sca_update.sca) { in lp_comm_complete()
569 conn->periph.sca = ctx->data.sca_update.sca; in lp_comm_complete()
576 lp_comm_ntf(conn, ctx); in lp_comm_complete()
578 ctx->state = LP_COMMON_STATE_IDLE; in lp_comm_complete()
582 lp_comm_terminate_invalid_pdu(conn, ctx); in lp_comm_complete()
599 static bool lp_comm_tx_proxy(struct ll_conn *conn, struct proc_ctx *ctx, const bool extra_cond) in lp_comm_tx_proxy() argument
601 if (extra_cond || llcp_lr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) { in lp_comm_tx_proxy()
602 ctx->state = LP_COMMON_STATE_WAIT_TX; in lp_comm_tx_proxy()
604 lp_comm_tx(conn, ctx); in lp_comm_tx_proxy()
607 ctx->state = ctx->node_ref.tx_ack ? in lp_comm_tx_proxy()
614 static void lp_comm_send_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
616 switch (ctx->proc) {
619 lp_comm_tx_proxy(conn, ctx, false);
623 lp_comm_tx_proxy(conn, ctx, false);
627 lp_comm_tx_proxy(conn, ctx, false);
635 if (lp_comm_tx_proxy(conn, ctx, false)) {
639 ctx->response_opcode = PDU_DATA_LLCTRL_TYPE_VERSION_IND;
641 ctx->node_ref.rx = NULL;
642 lp_comm_complete(conn, ctx, evt, param);
646 if (!llcp_tx_alloc_peek(conn, ctx)) {
647 ctx->state = LP_COMMON_STATE_WAIT_TX;
649 lp_comm_tx(conn, ctx);
650 ctx->data.term.error_code = BT_HCI_ERR_LOCALHOST_TERM_CONN;
651 ctx->state = LP_COMMON_STATE_WAIT_TX_ACK;
656 lp_comm_tx_proxy(conn, ctx, !lp_cis_terminated(conn));
662 if (llcp_lr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) {
663 ctx->state = LP_COMMON_STATE_WAIT_TX;
670 lp_comm_tx(conn, ctx);
671 ctx->state = LP_COMMON_STATE_WAIT_RX;
683 ctx->state = LP_COMMON_STATE_IDLE;
695 lp_comm_tx_proxy(conn, ctx,
706 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
707 ctx->state = LP_COMMON_STATE_IDLE;
714 lp_comm_tx_proxy(conn, ctx, false);
723 static void lp_comm_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
728 if (ctx->proc == PROC_CIS_TERMINATE) {
734 llcp_cis_stop_by_id(ctx->data.cis_term.cig_id, ctx->data.cis_term.cis_id,
738 lp_comm_send_req(conn, ctx, evt, param);
746 static void lp_comm_st_wait_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
751 lp_comm_send_req(conn, ctx, evt, param);
759 static void lp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
764 switch (ctx->proc) {
767 lp_comm_complete(conn, ctx, evt, param);
771 lp_comm_complete(conn, ctx, evt, param);
775 lp_comm_complete(conn, ctx, evt, param);
789 static void lp_comm_rx_decode(struct ll_conn *conn, struct proc_ctx *ctx, struct pdu_data *pdu) argument
791 ctx->response_opcode = pdu->llctrl.opcode;
818 llcp_pdu_decode_unknown_rsp(ctx, pdu);
831 llcp_pdu_decode_cte_rsp(ctx, pdu);
836 llcp_pdu_decode_clock_accuracy_rsp(ctx, pdu);
840 llcp_pdu_decode_reject_ext_ind(ctx, pdu);
851 static void lp_comm_st_wait_rx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
856 lp_comm_rx_decode(conn, ctx, (struct pdu_data *)param);
857 lp_comm_complete(conn, ctx, evt, param);
865 static void lp_comm_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
870 switch (ctx->proc) {
882 lp_comm_ntf(conn, ctx);
884 ctx->state = LP_COMMON_STATE_IDLE;
901 static void lp_comm_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
904 switch (ctx->state) {
906 lp_comm_st_idle(conn, ctx, evt, param);
909 lp_comm_st_wait_tx(conn, ctx, evt, param);
912 lp_comm_st_wait_tx_ack(conn, ctx, evt, param);
915 lp_comm_st_wait_rx(conn, ctx, evt, param);
918 lp_comm_st_wait_ntf_avail(conn, ctx, evt, param);
926 void llcp_lp_comm_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx *tx) argument
928 lp_comm_execute_fsm(conn, ctx, LP_COMMON_EVT_ACK, tx->pdu);
931 void llcp_lp_comm_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx) argument
933 lp_comm_execute_fsm(conn, ctx, LP_COMMON_EVT_RESPONSE, rx->pdu);
936 void llcp_lp_comm_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param) argument
938 lp_comm_execute_fsm(conn, ctx, LP_COMMON_EVT_RUN, param);
942 static void rp_comm_terminate(struct ll_conn *conn, struct proc_ctx *ctx) argument
945 ctx->state = RP_COMMON_STATE_IDLE;
948 conn->llcp_terminate.reason_final = ctx->data.term.error_code;
952 static void rp_comm_stop_cis(struct proc_ctx *ctx) argument
954 llcp_cis_stop_by_id(ctx->data.cis_term.cig_id, ctx->data.cis_term.cis_id,
955 ctx->data.cis_term.error_code);
962 static void rp_comm_rx_decode(struct ll_conn *conn, struct proc_ctx *ctx, struct pdu_data *pdu) argument
964 ctx->response_opcode = pdu->llctrl.opcode;
999 llcp_pdu_decode_terminate_ind(ctx, pdu);
1005 llcp_pdu_decode_cis_terminate_ind(ctx, pdu);
1007 rp_comm_stop_cis(ctx);
1019 ctx->data.dle.ntf_dle = ull_dle_update_eff_rx(conn);
1022 llcp_rx_node_retain(ctx);
1027 llcp_pdu_decode_cte_req(ctx, pdu);
1032 llcp_pdu_decode_clock_accuracy_req(ctx, pdu);
1041 static void rp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) argument
1047 tx = llcp_tx_alloc(conn, ctx);
1053 switch (ctx->proc) {
1057 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1062 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1066 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1071 ctx->node_ref.tx_ack = tx;
1072 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1091 if (!(conn->llcp.cte_rsp.cte_types & BIT(ctx->data.cte_remote_req.cte_type)) ||
1092 conn->llcp.cte_rsp.max_cte_len < ctx->data.cte_remote_req.min_cte_len) {
1097 llcp_pdu_encode_cte_rsp(ctx, pdu);
1098 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1101 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1104 ctx->node_ref.tx_ack = tx;
1111 llcp_pdu_encode_clock_accuracy_rsp(ctx, pdu);
1112 ctx->node_ref.tx_ack = tx;
1113 ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
1121 ctx->tx_opcode = pdu->llctrl.opcode;
1130 static void rp_comm_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
1134 ctx->state = RP_COMMON_STATE_WAIT_RX;
1142 static void rp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t generate_ntf) argument
1148 ntf = ctx->node_ref.rx;
1149 ctx->node_ref.rx = NULL;
1162 LL_ASSERT(ctx->proc == PROC_DATA_LENGTH_UPDATE);
1171 static bool rp_comm_tx_proxy(struct ll_conn *conn, struct proc_ctx *ctx, const bool complete) argument
1173 if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) {
1174 ctx->state = RP_COMMON_STATE_WAIT_TX;
1178 rp_comm_tx(conn, ctx);
1179 ctx->state = RP_COMMON_STATE_WAIT_TX_ACK;
1182 ctx->state = RP_COMMON_STATE_IDLE;
1188 static void rp_comm_send_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
1190 switch (ctx->proc) {
1194 rp_comm_tx_proxy(conn, ctx, true);
1199 rp_comm_tx_proxy(conn, ctx, true);
1209 if (rp_comm_tx_proxy(conn, ctx, true)) {
1218 ctx->state = RP_COMMON_STATE_IDLE;
1242 ctx->state = RP_COMMON_STATE_IDLE;
1251 ctx->state = RP_COMMON_STATE_POSTPONE_TERMINATE;
1257 rp_comm_terminate(conn, ctx);
1264 ctx->state = RP_COMMON_STATE_IDLE;
1270 rp_comm_tx_proxy(conn, ctx, false);
1276 !llcp_tx_alloc_peek(conn, ctx) ||
1278 ctx->state = RP_COMMON_STATE_WAIT_TX;
1281 rp_comm_tx(conn, ctx);
1282 ctx->state = RP_COMMON_STATE_WAIT_TX_ACK;
1289 rp_comm_tx_proxy(conn, ctx, false);
1298 static void rp_comm_st_wait_rx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
1302 rp_comm_rx_decode(conn, ctx, (struct pdu_data *)param);
1303 rp_comm_send_rsp(conn, ctx, evt, param);
1311 static void rp_comm_st_postpone_terminate(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
1316 LL_ASSERT(ctx->proc == PROC_TERMINATE);
1322 rp_comm_terminate(conn, ctx);
1331 static void rp_comm_st_wait_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) argument
1335 rp_comm_send_rsp(conn, ctx, evt, param);
1343 static void rp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
1348 switch (ctx->proc) {
1354 dle_changed |= ctx->data.dle.ntf_dle;
1357 rp_comm_ntf(conn, ctx, dle_changed);
1359 ctx->state = RP_COMMON_STATE_IDLE;
1368 ctx->state = RP_COMMON_STATE_IDLE;
1375 conn->periph.sca = ctx->data.sca_update.sca;
1383 ctx->state = RP_COMMON_STATE_IDLE;
1397 static void rp_comm_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, argument
1400 switch (ctx->state) {
1402 rp_comm_st_idle(conn, ctx, evt, param);
1405 rp_comm_st_wait_rx(conn, ctx, evt, param);
1408 rp_comm_st_postpone_terminate(conn, ctx, evt, param);
1411 rp_comm_st_wait_tx(conn, ctx, evt, param);
1414 rp_comm_st_wait_tx_ack(conn, ctx, evt, param);
1422 void llcp_rp_comm_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx) argument
1424 rp_comm_execute_fsm(conn, ctx, RP_COMMON_EVT_REQUEST, rx->pdu);
1427 void llcp_rp_comm_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx *tx) argument
1429 rp_comm_execute_fsm(conn, ctx, RP_COMMON_EVT_ACK, tx->pdu);
1432 void llcp_rp_comm_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param) argument
1434 rp_comm_execute_fsm(conn, ctx, RP_COMMON_EVT_RUN, param);