Lines Matching refs:ag

35 typedef int (*bt_hfp_ag_parse_command_t)(struct bt_hfp_ag *ag, struct net_buf *buf);
57 typedef void (*bt_hfp_ag_tx_cb_t)(struct bt_hfp_ag *ag, void *user_data);
62 struct bt_hfp_ag *ag; member
125 static void hfp_ag_lock(struct bt_hfp_ag *ag) in hfp_ag_lock() argument
127 k_sem_take(&ag->lock, K_FOREVER); in hfp_ag_lock()
130 static void hfp_ag_unlock(struct bt_hfp_ag *ag) in hfp_ag_unlock() argument
132 k_sem_give(&ag->lock); in hfp_ag_unlock()
135 static void bt_hfp_ag_set_state(struct bt_hfp_ag *ag, bt_hfp_state_t state) in bt_hfp_ag_set_state() argument
137 LOG_DBG("update state %p, old %d -> new %d", ag, ag->state, state); in bt_hfp_ag_set_state()
139 hfp_ag_lock(ag); in bt_hfp_ag_set_state()
140 ag->state = state; in bt_hfp_ag_set_state()
141 hfp_ag_unlock(ag); in bt_hfp_ag_set_state()
146 bt_ag->disconnected(ag); in bt_hfp_ag_set_state()
155 bt_ag->connected(ag); in bt_hfp_ag_set_state()
166 static void bt_hfp_ag_set_call_state(struct bt_hfp_ag *ag, bt_hfp_call_state_t call_state) in bt_hfp_ag_set_call_state() argument
170 LOG_DBG("update call state %p, old %d -> new %d", ag, ag->call_state, call_state); in bt_hfp_ag_set_call_state()
172 hfp_ag_lock(ag); in bt_hfp_ag_set_call_state()
173 ag->call_state = call_state; in bt_hfp_ag_set_call_state()
174 state = ag->state; in bt_hfp_ag_set_call_state()
175 hfp_ag_unlock(ag); in bt_hfp_ag_set_call_state()
179 atomic_clear(ag->flags); in bt_hfp_ag_set_call_state()
180 k_work_cancel_delayable(&ag->deferred_work); in bt_hfp_ag_set_call_state()
183 k_work_reschedule(&ag->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_OUTGOING_TIMEOUT)); in bt_hfp_ag_set_call_state()
186 k_work_reschedule(&ag->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_INCOMING_TIMEOUT)); in bt_hfp_ag_set_call_state()
189 k_work_reschedule(&ag->ringing_work, K_NO_WAIT); in bt_hfp_ag_set_call_state()
190 k_work_reschedule(&ag->deferred_work, K_SECONDS(CONFIG_BT_HFP_AG_ALERTING_TIMEOUT)); in bt_hfp_ag_set_call_state()
193 k_work_cancel_delayable(&ag->ringing_work); in bt_hfp_ag_set_call_state()
194 k_work_cancel_delayable(&ag->deferred_work); in bt_hfp_ag_set_call_state()
204 int err = bt_rfcomm_dlc_disconnect(&ag->rfcomm_dlc); in bt_hfp_ag_set_call_state()
207 LOG_ERR("Fail to disconnect DLC %p", &ag->rfcomm_dlc); in bt_hfp_ag_set_call_state()
244 static int hfp_ag_next_step(struct bt_hfp_ag *ag, bt_hfp_ag_tx_cb_t cb, void *user_data) in hfp_ag_next_step() argument
258 tx->ag = ag; in hfp_ag_next_step()
269 static int hfp_ag_send(struct bt_hfp_ag *ag, struct bt_ag_tx *tx) in hfp_ag_send() argument
271 int err = bt_rfcomm_dlc_send(&ag->rfcomm_dlc, tx->buf); in hfp_ag_send()
283 struct bt_hfp_ag *ag = CONTAINER_OF(dwork, struct bt_hfp_ag, tx_work); in bt_ag_tx_work() local
288 hfp_ag_lock(ag); in bt_ag_tx_work()
289 state = ag->state; in bt_ag_tx_work()
291 LOG_ERR("AG %p is not connected", ag); in bt_ag_tx_work()
295 node = sys_slist_peek_head(&ag->tx_pending); in bt_ag_tx_work()
303 if (!atomic_test_and_set_bit(ag->flags, BT_HFP_AG_TX_ONGOING)) { in bt_ag_tx_work()
304 LOG_DBG("AG %p sending tx %p", ag, tx); in bt_ag_tx_work()
305 int err = hfp_ag_send(ag, tx); in bt_ag_tx_work()
309 sys_slist_find_and_remove(&ag->tx_pending, &tx->node); in bt_ag_tx_work()
313 if (!atomic_test_and_clear_bit(ag->flags, BT_HFP_AG_TX_ONGOING)) { in bt_ag_tx_work()
317 k_work_reschedule(&ag->tx_work, K_NO_WAIT); in bt_ag_tx_work()
322 hfp_ag_unlock(ag); in bt_ag_tx_work()
325 static int hfp_ag_send_data(struct bt_hfp_ag *ag, bt_hfp_ag_tx_cb_t cb, void *user_data, in hfp_ag_send_data() argument
334 LOG_DBG("AG %p sending data cb %p user_data %p", ag, cb, user_data); in hfp_ag_send_data()
336 hfp_ag_lock(ag); in hfp_ag_send_data()
337 state = ag->state; in hfp_ag_send_data()
338 hfp_ag_unlock(ag); in hfp_ag_send_data()
340 LOG_ERR("AG %p is not connected", ag); in hfp_ag_send_data()
359 tx->ag = ag; in hfp_ag_send_data()
379 hfp_ag_lock(ag); in hfp_ag_send_data()
380 sys_slist_append(&ag->tx_pending, &tx->node); in hfp_ag_send_data()
381 hfp_ag_unlock(ag); in hfp_ag_send_data()
384 k_work_reschedule(&ag->tx_work, K_NO_WAIT); in hfp_ag_send_data()
433 static int bt_hfp_ag_brsf_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_brsf_handler() argument
451 hfp_ag_lock(ag); in bt_hfp_ag_brsf_handler()
452 ag->hf_features = hf_features; in bt_hfp_ag_brsf_handler()
453 hfp_ag_unlock(ag); in bt_hfp_ag_brsf_handler()
455 return hfp_ag_send_data(ag, NULL, NULL, "\r\n+BRSF:%d\r\n", ag->ag_features); in bt_hfp_ag_brsf_handler()
458 static int bt_hfp_ag_bac_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bac_handler() argument
468 hfp_ag_lock(ag); in bt_hfp_ag_bac_handler()
469 if (!(ag->hf_features & BT_HFP_HF_FEATURE_CODEC_NEG) || in bt_hfp_ag_bac_handler()
470 !(ag->ag_features & BT_HFP_AG_FEATURE_CODEC_NEG)) { in bt_hfp_ag_bac_handler()
471 hfp_ag_unlock(ag); in bt_hfp_ag_bac_handler()
474 hfp_ag_unlock(ag); in bt_hfp_ag_bac_handler()
493 hfp_ag_lock(ag); in bt_hfp_ag_bac_handler()
494 ag->hf_codec_ids = codec_ids; in bt_hfp_ag_bac_handler()
495 hfp_ag_unlock(ag); in bt_hfp_ag_bac_handler()
498 bt_ag->codec(ag, ag->hf_codec_ids); in bt_hfp_ag_bac_handler()
504 static int bt_hfp_ag_cind_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_cind_handler() argument
523 ag, NULL, NULL, in bt_hfp_ag_cind_handler()
543 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+CIND:%d,%d,%d,%d,%d,%d,%d\r\n", in bt_hfp_ag_cind_handler()
544 ag->indicator_value[BT_HFP_AG_SERVICE_IND], in bt_hfp_ag_cind_handler()
545 ag->indicator_value[BT_HFP_AG_CALL_IND], in bt_hfp_ag_cind_handler()
546 ag->indicator_value[BT_HFP_AG_CALL_SETUP_IND], in bt_hfp_ag_cind_handler()
547 ag->indicator_value[BT_HFP_AG_CALL_HELD_IND], in bt_hfp_ag_cind_handler()
548 ag->indicator_value[BT_HFP_AG_SIGNAL_IND], in bt_hfp_ag_cind_handler()
549 ag->indicator_value[BT_HFP_AG_ROAM_IND], in bt_hfp_ag_cind_handler()
550 ag->indicator_value[BT_HFP_AG_BATTERY_IND]); in bt_hfp_ag_cind_handler()
556 static void bt_hfp_ag_set_in_band_ring(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_set_in_band_ring() argument
560 hfp_ag_lock(ag); in bt_hfp_ag_set_in_band_ring()
561 is_inband_ringtone = (ag->ag_features & BT_HFP_AG_FEATURE_INBAND_RINGTONE) ? true : false; in bt_hfp_ag_set_in_band_ring()
562 hfp_ag_unlock(ag); in bt_hfp_ag_set_in_band_ring()
565 int err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BSIR:1\r\n"); in bt_hfp_ag_set_in_band_ring()
567 atomic_set_bit_to(ag->flags, BT_HFP_AG_INBAND_RING, err == 0); in bt_hfp_ag_set_in_band_ring()
571 static int bt_hfp_ag_cmer_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_cmer_handler() argument
606 atomic_set_bit(ag->flags, BT_HFP_AG_CMER_ENABLE); in bt_hfp_ag_cmer_handler()
607 bt_hfp_ag_set_state(ag, BT_HFP_CONNECTED); in bt_hfp_ag_cmer_handler()
608 err = hfp_ag_next_step(ag, bt_hfp_ag_set_in_band_ring, NULL); in bt_hfp_ag_cmer_handler()
611 atomic_clear_bit(ag->flags, BT_HFP_AG_CMER_ENABLE); in bt_hfp_ag_cmer_handler()
619 static int bt_hfp_ag_chld_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_chld_handler() argument
624 static int bt_hfp_ag_bind_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bind_handler() argument
632 hfp_ag_lock(ag); in bt_hfp_ag_bind_handler()
633 if (!((ag->ag_features & BT_HFP_AG_FEATURE_HF_IND) && in bt_hfp_ag_bind_handler()
634 (ag->hf_features & BT_HFP_HF_FEATURE_HF_IND))) { in bt_hfp_ag_bind_handler()
635 hfp_ag_unlock(ag); in bt_hfp_ag_bind_handler()
638 hfp_ag_unlock(ag); in bt_hfp_ag_bind_handler()
645 hfp_ag_lock(ag); in bt_hfp_ag_bind_handler()
646 hf_indicators = ag->hf_indicators_of_hf & ag->hf_indicators_of_ag; in bt_hfp_ag_bind_handler()
647 hfp_ag_unlock(ag); in bt_hfp_ag_bind_handler()
652 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BIND:%d,%d\r\n", i, 1); in bt_hfp_ag_bind_handler()
654 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BIND:%d,%d\r\n", i, 0); in bt_hfp_ag_bind_handler()
675 data = &ag->buffer[0]; in bt_hfp_ag_bind_handler()
678 hfp_ag_lock(ag); in bt_hfp_ag_bind_handler()
679 hf_indicators = ag->hf_indicators_of_ag; in bt_hfp_ag_bind_handler()
680 hfp_ag_unlock(ag); in bt_hfp_ag_bind_handler()
686 data, (char *)&ag->buffer[HF_MAX_BUF_LEN - 1] - data - 3, in bt_hfp_ag_bind_handler()
703 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BIND:%s\r\n", &ag->buffer[0]); in bt_hfp_ag_bind_handler()
724 hfp_ag_lock(ag); in bt_hfp_ag_bind_handler()
725 ag->hf_indicators_of_hf = hf_indicators; in bt_hfp_ag_bind_handler()
726 hfp_ag_unlock(ag); in bt_hfp_ag_bind_handler()
731 static int bt_hfp_ag_cmee_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_cmee_handler() argument
753 atomic_set_bit_to(ag->flags, BT_HFP_AG_CMEE_ENABLE, cmee == 1); in bt_hfp_ag_cmee_handler()
758 static int hfp_ag_update_indicator(struct bt_hfp_ag *ag, enum bt_hfp_ag_indicator index, in hfp_ag_update_indicator() argument
764 hfp_ag_lock(ag); in hfp_ag_update_indicator()
765 old_value = ag->indicator_value[index]; in hfp_ag_update_indicator()
769 hfp_ag_unlock(ag); in hfp_ag_update_indicator()
773 ag->indicator_value[index] = value; in hfp_ag_update_indicator()
774 hfp_ag_unlock(ag); in hfp_ag_update_indicator()
778 err = hfp_ag_send_data(ag, cb, user_data, "\r\n+CIEV:%d,%d\r\n", (uint8_t)index + 1, value); in hfp_ag_update_indicator()
780 hfp_ag_lock(ag); in hfp_ag_update_indicator()
781 ag->indicator_value[index] = old_value; in hfp_ag_update_indicator()
782 hfp_ag_unlock(ag); in hfp_ag_update_indicator()
789 static void hfp_ag_close_sco(struct bt_hfp_ag *ag) in hfp_ag_close_sco() argument
795 hfp_ag_lock(ag); in hfp_ag_close_sco()
796 sco = ag->sco_chan.sco; in hfp_ag_close_sco()
797 ag->sco_chan.sco = NULL; in hfp_ag_close_sco()
798 hfp_ag_unlock(ag); in hfp_ag_close_sco()
805 static void bt_hfp_ag_reject_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_reject_cb() argument
807 hfp_ag_close_sco(ag); in bt_hfp_ag_reject_cb()
808 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_TERMINATE); in bt_hfp_ag_reject_cb()
811 bt_ag->reject(ag); in bt_hfp_ag_reject_cb()
815 static void bt_hfp_ag_call_reject(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_call_reject() argument
817 int err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_call_reject()
824 static void bt_hfp_ag_terminate_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_terminate_cb() argument
826 hfp_ag_close_sco(ag); in bt_hfp_ag_terminate_cb()
827 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_TERMINATE); in bt_hfp_ag_terminate_cb()
830 bt_ag->terminate(ag); in bt_hfp_ag_terminate_cb()
834 static void bt_hfp_ag_unit_call_terminate(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_unit_call_terminate() argument
836 int err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, bt_hfp_ag_terminate_cb, in bt_hfp_ag_unit_call_terminate()
843 static int bt_hfp_ag_chup_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_chup_handler() argument
852 hfp_ag_lock(ag); in bt_hfp_ag_chup_handler()
853 call_state = ag->call_state; in bt_hfp_ag_chup_handler()
854 hfp_ag_unlock(ag); in bt_hfp_ag_chup_handler()
857 if (!atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_chup_handler()
860 err = hfp_ag_next_step(ag, bt_hfp_ag_call_reject, NULL); in bt_hfp_ag_chup_handler()
862 err = hfp_ag_next_step(ag, bt_hfp_ag_unit_call_terminate, NULL); in bt_hfp_ag_chup_handler()
869 static uint8_t bt_hfp_get_call_state(struct bt_hfp_ag *ag) in bt_hfp_get_call_state() argument
873 hfp_ag_lock(ag); in bt_hfp_get_call_state()
874 switch (ag->call_state) { in bt_hfp_get_call_state()
884 if (atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_get_call_state()
899 hfp_ag_unlock(ag); in bt_hfp_get_call_state()
904 static int bt_hfp_ag_clcc_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_clcc_handler() argument
916 hfp_ag_lock(ag); in bt_hfp_ag_clcc_handler()
917 if (ag->call_state == BT_HFP_CALL_TERMINATE) { in bt_hfp_ag_clcc_handler()
919 hfp_ag_unlock(ag); in bt_hfp_ag_clcc_handler()
922 hfp_ag_unlock(ag); in bt_hfp_ag_clcc_handler()
924 dir = atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL) ? 1 : 0; in bt_hfp_ag_clcc_handler()
925 status = bt_hfp_get_call_state(ag); in bt_hfp_ag_clcc_handler()
928 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+CLCC:%d,%d,%d,%d,%d\r\n", 1, dir, status, mode, in bt_hfp_ag_clcc_handler()
938 static int bt_hfp_ag_bia_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bia_handler() argument
949 hfp_ag_lock(ag); in bt_hfp_ag_bia_handler()
950 indicator = ag->indicator; in bt_hfp_ag_bia_handler()
951 hfp_ag_unlock(ag); in bt_hfp_ag_bia_handler()
980 hfp_ag_lock(ag); in bt_hfp_ag_bia_handler()
981 ag->indicator = indicator; in bt_hfp_ag_bia_handler()
982 hfp_ag_unlock(ag); in bt_hfp_ag_bia_handler()
987 static void bt_hfp_ag_accept_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_accept_cb() argument
989 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_ACTIVE); in bt_hfp_ag_accept_cb()
992 bt_ag->accept(ag); in bt_hfp_ag_accept_cb()
996 static void bt_hfp_ag_call_ringing_cb(struct bt_hfp_ag *ag, bool in_bond) in bt_hfp_ag_call_ringing_cb() argument
999 bt_ag->ringing(ag, in_bond); in bt_hfp_ag_call_ringing_cb()
1005 struct bt_hfp_ag *ag = CONTAINER_OF(chan, struct bt_hfp_ag, sco_chan); in hfp_ag_sco_connected() local
1008 hfp_ag_lock(ag); in hfp_ag_sco_connected()
1009 call_state = ag->call_state; in hfp_ag_sco_connected()
1010 hfp_ag_unlock(ag); in hfp_ag_sco_connected()
1012 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_ALERTING); in hfp_ag_sco_connected()
1013 bt_hfp_ag_call_ringing_cb(ag, true); in hfp_ag_sco_connected()
1017 bt_ag->sco_connected(ag, chan->sco); in hfp_ag_sco_connected()
1023 struct bt_hfp_ag *ag = CONTAINER_OF(chan, struct bt_hfp_ag, sco_chan); in hfp_ag_sco_disconnected() local
1027 bt_ag->sco_disconnected(ag); in hfp_ag_sco_disconnected()
1030 hfp_ag_lock(ag); in hfp_ag_sco_disconnected()
1031 call_state = ag->call_state; in hfp_ag_sco_disconnected()
1032 hfp_ag_unlock(ag); in hfp_ag_sco_disconnected()
1034 bt_hfp_ag_call_reject(ag, NULL); in hfp_ag_sco_disconnected()
1038 static struct bt_conn *bt_hfp_ag_create_sco(struct bt_hfp_ag *ag) in bt_hfp_ag_create_sco() argument
1049 if (ag->sco_chan.sco == NULL) { in bt_hfp_ag_create_sco()
1050 ag->sco_chan.ops = &ops; in bt_hfp_ag_create_sco()
1053 sco_conn = bt_conn_create_sco(&ag->acl_conn->br.dst, &ag->sco_chan); in bt_hfp_ag_create_sco()
1059 sco_conn = ag->sco_chan.sco; in bt_hfp_ag_create_sco()
1065 static int hfp_ag_open_sco(struct bt_hfp_ag *ag) in hfp_ag_open_sco() argument
1069 if (atomic_test_bit(ag->flags, BT_HFP_AG_CREATING_SCO)) { in hfp_ag_open_sco()
1074 hfp_ag_lock(ag); in hfp_ag_open_sco()
1075 create_sco = (ag->sco_chan.sco == NULL) ? true : false; in hfp_ag_open_sco()
1077 atomic_set_bit(ag->flags, BT_HFP_AG_CREATING_SCO); in hfp_ag_open_sco()
1079 hfp_ag_unlock(ag); in hfp_ag_open_sco()
1082 struct bt_conn *sco_conn = bt_hfp_ag_create_sco(ag); in hfp_ag_open_sco()
1084 atomic_clear_bit(ag->flags, BT_HFP_AG_CREATING_SCO); in hfp_ag_open_sco()
1097 static int bt_hfp_ag_codec_select(struct bt_hfp_ag *ag) in bt_hfp_ag_codec_select() argument
1103 hfp_ag_lock(ag); in bt_hfp_ag_codec_select()
1104 if (ag->selected_codec_id == 0) { in bt_hfp_ag_codec_select()
1106 hfp_ag_unlock(ag); in bt_hfp_ag_codec_select()
1110 if (!(ag->hf_codec_ids & BIT(ag->selected_codec_id))) { in bt_hfp_ag_codec_select()
1111 LOG_ERR("Codec is unsupported (codec id %d)", ag->selected_codec_id); in bt_hfp_ag_codec_select()
1112 hfp_ag_unlock(ag); in bt_hfp_ag_codec_select()
1115 hfp_ag_unlock(ag); in bt_hfp_ag_codec_select()
1117 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BCS:%d\r\n", ag->selected_codec_id); in bt_hfp_ag_codec_select()
1124 static int bt_hfp_ag_create_audio_connection(struct bt_hfp_ag *ag) in bt_hfp_ag_create_audio_connection() argument
1129 hfp_ag_lock(ag); in bt_hfp_ag_create_audio_connection()
1130 hf_codec_ids = ag->hf_codec_ids; in bt_hfp_ag_create_audio_connection()
1131 hfp_ag_unlock(ag); in bt_hfp_ag_create_audio_connection()
1133 if ((hf_codec_ids != 0) && atomic_test_bit(ag->flags, BT_HFP_AG_CODEC_CHANGED)) { in bt_hfp_ag_create_audio_connection()
1134 atomic_set_bit(ag->flags, BT_HFP_AG_CODEC_CONN); in bt_hfp_ag_create_audio_connection()
1135 err = bt_hfp_ag_codec_select(ag); in bt_hfp_ag_create_audio_connection()
1137 err = hfp_ag_open_sco(ag); in bt_hfp_ag_create_audio_connection()
1143 static void bt_hfp_ag_audio_connection(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_audio_connection() argument
1147 err = bt_hfp_ag_create_audio_connection(ag); in bt_hfp_ag_audio_connection()
1149 bt_hfp_ag_unit_call_terminate(ag, user_data); in bt_hfp_ag_audio_connection()
1153 static void bt_hfp_ag_unit_call_accept(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_unit_call_accept() argument
1157 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 1, bt_hfp_ag_accept_cb, user_data); in bt_hfp_ag_unit_call_accept()
1162 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_unit_call_accept()
1169 static int bt_hfp_ag_ata_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_ata_handler() argument
1177 hfp_ag_lock(ag); in bt_hfp_ag_ata_handler()
1178 if (ag->call_state != BT_HFP_CALL_ALERTING) { in bt_hfp_ag_ata_handler()
1179 hfp_ag_unlock(ag); in bt_hfp_ag_ata_handler()
1182 hfp_ag_unlock(ag); in bt_hfp_ag_ata_handler()
1184 if (!atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_ata_handler()
1188 err = hfp_ag_next_step(ag, bt_hfp_ag_unit_call_accept, NULL); in bt_hfp_ag_ata_handler()
1193 static int bt_hfp_ag_cops_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_cops_handler() argument
1218 atomic_set_bit(ag->flags, BT_HFP_AG_COPS_SET); in bt_hfp_ag_cops_handler()
1222 if (!atomic_test_bit(ag->flags, BT_HFP_AG_COPS_SET)) { in bt_hfp_ag_cops_handler()
1234 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+COPS:%d,%d,\"%s\"\r\n", 0, 0, ag->operator); in bt_hfp_ag_cops_handler()
1242 static int bt_hfp_ag_bcc_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bcc_handler() argument
1250 hfp_ag_lock(ag); in bt_hfp_ag_bcc_handler()
1251 if ((ag->selected_codec_id == 0) || in bt_hfp_ag_bcc_handler()
1252 (!(ag->hf_codec_ids & BIT(ag->selected_codec_id))) || in bt_hfp_ag_bcc_handler()
1253 (ag->call_state == BT_HFP_CALL_TERMINATE) || in bt_hfp_ag_bcc_handler()
1254 (ag->sco_chan.sco != NULL)) { in bt_hfp_ag_bcc_handler()
1255 hfp_ag_unlock(ag); in bt_hfp_ag_bcc_handler()
1258 hfp_ag_unlock(ag); in bt_hfp_ag_bcc_handler()
1260 err = hfp_ag_next_step(ag, bt_hfp_ag_audio_connection, NULL); in bt_hfp_ag_bcc_handler()
1265 static void bt_hfp_ag_unit_codec_conn_setup(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_unit_codec_conn_setup() argument
1267 int err = hfp_ag_open_sco(ag); in bt_hfp_ag_unit_codec_conn_setup()
1270 bt_hfp_ag_call_reject(ag, user_data); in bt_hfp_ag_unit_codec_conn_setup()
1274 static int bt_hfp_ag_bcs_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bcs_handler() argument
1292 if (!atomic_test_bit(ag->flags, BT_HFP_AG_CODEC_CONN)) { in bt_hfp_ag_bcs_handler()
1296 hfp_ag_lock(ag); in bt_hfp_ag_bcs_handler()
1297 if (ag->selected_codec_id != number) { in bt_hfp_ag_bcs_handler()
1299 number, ag->selected_codec_id); in bt_hfp_ag_bcs_handler()
1301 } else if (!(ag->hf_codec_ids & BIT(ag->selected_codec_id))) { in bt_hfp_ag_bcs_handler()
1303 ag->selected_codec_id, ag->hf_codec_ids); in bt_hfp_ag_bcs_handler()
1306 hfp_ag_unlock(ag); in bt_hfp_ag_bcs_handler()
1308 atomic_clear_bit(ag->flags, BT_HFP_AG_CODEC_CONN); in bt_hfp_ag_bcs_handler()
1309 atomic_clear_bit(ag->flags, BT_HFP_AG_CODEC_CHANGED); in bt_hfp_ag_bcs_handler()
1312 err = hfp_ag_next_step(ag, bt_hfp_ag_unit_codec_conn_setup, NULL); in bt_hfp_ag_bcs_handler()
1316 hfp_ag_lock(ag); in bt_hfp_ag_bcs_handler()
1317 call_state = ag->call_state; in bt_hfp_ag_bcs_handler()
1318 hfp_ag_unlock(ag); in bt_hfp_ag_bcs_handler()
1320 (void)hfp_ag_next_step(ag, bt_hfp_ag_unit_call_terminate, NULL); in bt_hfp_ag_bcs_handler()
1327 static void bt_hfp_ag_unit_call_outgoing(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_unit_call_outgoing() argument
1329 int err = bt_hfp_ag_outgoing(ag, ag->number); in bt_hfp_ag_unit_call_outgoing()
1336 static int bt_hfp_ag_atd_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_atd_handler() argument
1359 err = bt_ag->memory_dial(ag, &buf->data[0], &number); in bt_hfp_ag_atd_handler()
1379 hfp_ag_lock(ag); in bt_hfp_ag_atd_handler()
1380 if (ag->call_state != BT_HFP_CALL_TERMINATE) { in bt_hfp_ag_atd_handler()
1381 hfp_ag_unlock(ag); in bt_hfp_ag_atd_handler()
1386 memcpy(ag->number, number, len + 1); in bt_hfp_ag_atd_handler()
1387 hfp_ag_unlock(ag); in bt_hfp_ag_atd_handler()
1389 err = hfp_ag_next_step(ag, bt_hfp_ag_unit_call_outgoing, NULL); in bt_hfp_ag_atd_handler()
1394 static int bt_hfp_ag_bldn_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_bldn_handler() argument
1402 hfp_ag_lock(ag); in bt_hfp_ag_bldn_handler()
1403 if (strlen(ag->number) == 0) { in bt_hfp_ag_bldn_handler()
1404 hfp_ag_unlock(ag); in bt_hfp_ag_bldn_handler()
1408 if (ag->call_state != BT_HFP_CALL_TERMINATE) { in bt_hfp_ag_bldn_handler()
1409 hfp_ag_unlock(ag); in bt_hfp_ag_bldn_handler()
1412 hfp_ag_unlock(ag); in bt_hfp_ag_bldn_handler()
1414 err = hfp_ag_next_step(ag, bt_hfp_ag_unit_call_outgoing, NULL); in bt_hfp_ag_bldn_handler()
1419 static int bt_hfp_ag_clip_handler(struct bt_hfp_ag *ag, struct net_buf *buf) in bt_hfp_ag_clip_handler() argument
1437 atomic_set_bit_to(ag->flags, BT_HFP_AG_CLIP_ENABLE, clip == 1); in bt_hfp_ag_clip_handler()
1456 struct bt_hfp_ag *ag = CONTAINER_OF(dlc, struct bt_hfp_ag, rfcomm_dlc); in hfp_ag_connected() local
1458 bt_hfp_ag_set_state(ag, BT_HFP_CONFIG); in hfp_ag_connected()
1460 LOG_DBG("AG %p", ag); in hfp_ag_connected()
1465 struct bt_hfp_ag *ag = CONTAINER_OF(dlc, struct bt_hfp_ag, rfcomm_dlc); in hfp_ag_disconnected() local
1470 k_work_cancel_delayable(&ag->tx_work); in hfp_ag_disconnected()
1472 hfp_ag_lock(ag); in hfp_ag_disconnected()
1473 node = sys_slist_get(&ag->tx_pending); in hfp_ag_disconnected()
1474 hfp_ag_unlock(ag); in hfp_ag_disconnected()
1477 if (tx->buf && !atomic_test_and_clear_bit(ag->flags, BT_HFP_AG_TX_ONGOING)) { in hfp_ag_disconnected()
1482 hfp_ag_lock(ag); in hfp_ag_disconnected()
1483 node = sys_slist_get(&ag->tx_pending); in hfp_ag_disconnected()
1484 hfp_ag_unlock(ag); in hfp_ag_disconnected()
1488 bt_hfp_ag_set_state(ag, BT_HFP_DISCONNECTED); in hfp_ag_disconnected()
1490 hfp_ag_lock(ag); in hfp_ag_disconnected()
1491 call_state = ag->call_state; in hfp_ag_disconnected()
1492 hfp_ag_unlock(ag); in hfp_ag_disconnected()
1495 bt_hfp_ag_terminate_cb(ag, NULL); in hfp_ag_disconnected()
1498 LOG_DBG("AG %p", ag); in hfp_ag_disconnected()
1503 struct bt_hfp_ag *ag = CONTAINER_OF(dlc, struct bt_hfp_ag, rfcomm_dlc); in hfp_ag_recv() local
1521 err = cmd_handlers[index].handler(ag, buf); in hfp_ag_recv()
1527 if ((err != 0) && atomic_test_bit(ag->flags, BT_HFP_AG_CMEE_ENABLE)) { in hfp_ag_recv()
1529 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+CME ERROR:%d\r\n", (uint32_t)cme_err); in hfp_ag_recv()
1531 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n%s\r\n", (err == 0) ? "OK" : "ERROR"); in hfp_ag_recv()
1543 struct bt_hfp_ag *ag; in bt_hfp_ag_thread() local
1556 ag = tx->ag; in bt_hfp_ag_thread()
1563 hfp_ag_lock(ag); in bt_hfp_ag_thread()
1564 state = ag->state; in bt_hfp_ag_thread()
1565 hfp_ag_unlock(ag); in bt_hfp_ag_thread()
1567 bt_hfp_ag_set_state(ag, BT_HFP_DISCONNECTING); in bt_hfp_ag_thread()
1568 bt_rfcomm_dlc_disconnect(&ag->rfcomm_dlc); in bt_hfp_ag_thread()
1573 cb(ag, user_data); in bt_hfp_ag_thread()
1580 struct bt_hfp_ag *ag = CONTAINER_OF(dlc, struct bt_hfp_ag, rfcomm_dlc); in hfp_ag_sent() local
1584 hfp_ag_lock(ag); in hfp_ag_sent()
1586 if (!atomic_test_and_clear_bit(ag->flags, BT_HFP_AG_TX_ONGOING)) { in hfp_ag_sent()
1588 hfp_ag_unlock(ag); in hfp_ag_sent()
1592 node = sys_slist_get(&ag->tx_pending); in hfp_ag_sent()
1593 hfp_ag_unlock(ag); in hfp_ag_sent()
1603 k_work_reschedule(&ag->tx_work, K_NO_WAIT); in hfp_ag_sent()
1609 static void bt_ag_deferred_work_cb(struct bt_hfp_ag *ag, void *user_data) in bt_ag_deferred_work_cb() argument
1616 hfp_ag_lock(ag); in bt_ag_deferred_work_cb()
1617 call_state = ag->call_state; in bt_ag_deferred_work_cb()
1618 hfp_ag_unlock(ag); in bt_ag_deferred_work_cb()
1634 if (ag->indicator_value[BT_HFP_AG_CALL_SETUP_IND] && in bt_ag_deferred_work_cb()
1635 ag->indicator_value[BT_HFP_AG_CALL_IND]) { in bt_ag_deferred_work_cb()
1636 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, in bt_ag_deferred_work_cb()
1640 bt_hfp_ag_terminate_cb(ag, NULL); in bt_ag_deferred_work_cb()
1642 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, in bt_ag_deferred_work_cb()
1646 bt_hfp_ag_terminate_cb(ag, NULL); in bt_ag_deferred_work_cb()
1649 } else if (ag->indicator_value[BT_HFP_AG_CALL_SETUP_IND]) { in bt_ag_deferred_work_cb()
1650 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, in bt_ag_deferred_work_cb()
1655 bt_hfp_ag_terminate_cb(ag, NULL); in bt_ag_deferred_work_cb()
1657 } else if (ag->indicator_value[BT_HFP_AG_CALL_IND]) { in bt_ag_deferred_work_cb()
1658 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, in bt_ag_deferred_work_cb()
1662 bt_hfp_ag_terminate_cb(ag, NULL); in bt_ag_deferred_work_cb()
1672 struct bt_hfp_ag *ag = CONTAINER_OF(dwork, struct bt_hfp_ag, deferred_work); in bt_ag_deferred_work() local
1674 (void)hfp_ag_next_step(ag, bt_ag_deferred_work_cb, NULL); in bt_ag_deferred_work()
1677 static void bt_ag_ringing_work_cb(struct bt_hfp_ag *ag, void *user_data) in bt_ag_ringing_work_cb() argument
1684 hfp_ag_lock(ag); in bt_ag_ringing_work_cb()
1685 call_state = ag->call_state; in bt_ag_ringing_work_cb()
1686 hfp_ag_unlock(ag); in bt_ag_ringing_work_cb()
1689 if (!atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_ag_ringing_work_cb()
1693 k_work_reschedule(&ag->ringing_work, in bt_ag_ringing_work_cb()
1696 err = hfp_ag_send_data(ag, NULL, NULL, "\r\nRING\r\n"); in bt_ag_ringing_work_cb()
1700 if (atomic_test_bit(ag->flags, BT_HFP_AG_CLIP_ENABLE)) { in bt_ag_ringing_work_cb()
1701 err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+CLIP:\"%s\",%d\r\n", in bt_ag_ringing_work_cb()
1702 ag->number, 0); in bt_ag_ringing_work_cb()
1714 struct bt_hfp_ag *ag = CONTAINER_OF(dwork, struct bt_hfp_ag, ringing_work); in bt_ag_ringing_work() local
1716 (void)hfp_ag_next_step(ag, bt_ag_ringing_work_cb, NULL); in bt_ag_ringing_work()
1719 int bt_hfp_ag_connect(struct bt_conn *conn, struct bt_hfp_ag **ag, uint8_t channel) in bt_hfp_ag_connect() argument
1733 if (ag == NULL) { in bt_hfp_ag_connect()
1737 *ag = NULL; in bt_hfp_ag_connect()
1817 *ag = _ag; in bt_hfp_ag_connect()
1820 if (*ag == NULL) { in bt_hfp_ag_connect()
1824 err = bt_rfcomm_dlc_connect(conn, &(*ag)->rfcomm_dlc, channel); in bt_hfp_ag_connect()
1826 (void)memset(*ag, 0, sizeof(struct bt_hfp_ag)); in bt_hfp_ag_connect()
1827 *ag = NULL; in bt_hfp_ag_connect()
1829 bt_hfp_ag_set_state(*ag, BT_HFP_CONNECTING); in bt_hfp_ag_connect()
1835 int bt_hfp_ag_disconnect(struct bt_hfp_ag *ag) in bt_hfp_ag_disconnect() argument
1842 if (ag == NULL) { in bt_hfp_ag_disconnect()
1846 hfp_ag_lock(ag); in bt_hfp_ag_disconnect()
1847 call_state = ag->call_state; in bt_hfp_ag_disconnect()
1848 hfp_ag_unlock(ag); in bt_hfp_ag_disconnect()
1850 bt_hfp_ag_set_state(ag, BT_HFP_DISCONNECTING); in bt_hfp_ag_disconnect()
1853 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, bt_hfp_ag_terminate_cb, in bt_hfp_ag_disconnect()
1860 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_disconnect()
1868 return bt_rfcomm_dlc_disconnect(&ag->rfcomm_dlc); in bt_hfp_ag_disconnect()
1886 static void bt_hfp_ag_incoming_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_incoming_cb() argument
1888 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_INCOMING); in bt_hfp_ag_incoming_cb()
1891 bt_ag->incoming(ag, ag->number); in bt_hfp_ag_incoming_cb()
1894 if (atomic_test_bit(ag->flags, BT_HFP_AG_INBAND_RING)) { in bt_hfp_ag_incoming_cb()
1897 err = bt_hfp_ag_create_audio_connection(ag); in bt_hfp_ag_incoming_cb()
1899 bt_hfp_ag_call_reject(ag, NULL); in bt_hfp_ag_incoming_cb()
1902 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_ALERTING); in bt_hfp_ag_incoming_cb()
1903 bt_hfp_ag_call_ringing_cb(ag, false); in bt_hfp_ag_incoming_cb()
1907 int bt_hfp_ag_remote_incoming(struct bt_hfp_ag *ag, const char *number) in bt_hfp_ag_remote_incoming() argument
1914 if (ag == NULL) { in bt_hfp_ag_remote_incoming()
1918 hfp_ag_lock(ag); in bt_hfp_ag_remote_incoming()
1919 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_remote_incoming()
1920 hfp_ag_unlock(ag); in bt_hfp_ag_remote_incoming()
1924 if (ag->call_state != BT_HFP_CALL_TERMINATE) { in bt_hfp_ag_remote_incoming()
1925 hfp_ag_unlock(ag); in bt_hfp_ag_remote_incoming()
1928 hfp_ag_unlock(ag); in bt_hfp_ag_remote_incoming()
1935 hfp_ag_lock(ag); in bt_hfp_ag_remote_incoming()
1937 memcpy(ag->number, number, len + 1); in bt_hfp_ag_remote_incoming()
1938 hfp_ag_unlock(ag); in bt_hfp_ag_remote_incoming()
1940 atomic_set_bit(ag->flags, BT_HFP_AG_INCOMING_CALL); in bt_hfp_ag_remote_incoming()
1942 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_INCOMING, in bt_hfp_ag_remote_incoming()
1945 atomic_clear_bit(ag->flags, BT_HFP_AG_INCOMING_CALL); in bt_hfp_ag_remote_incoming()
1951 int bt_hfp_ag_reject(struct bt_hfp_ag *ag) in bt_hfp_ag_reject() argument
1957 if (ag == NULL) { in bt_hfp_ag_reject()
1961 hfp_ag_lock(ag); in bt_hfp_ag_reject()
1962 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_reject()
1963 hfp_ag_unlock(ag); in bt_hfp_ag_reject()
1967 if ((ag->call_state != BT_HFP_CALL_ALERTING) && (ag->call_state != BT_HFP_CALL_INCOMING)) { in bt_hfp_ag_reject()
1968 hfp_ag_unlock(ag); in bt_hfp_ag_reject()
1971 hfp_ag_unlock(ag); in bt_hfp_ag_reject()
1973 if (!atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_reject()
1977 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_reject()
1983 int bt_hfp_ag_accept(struct bt_hfp_ag *ag) in bt_hfp_ag_accept() argument
1989 if (ag == NULL) { in bt_hfp_ag_accept()
1993 hfp_ag_lock(ag); in bt_hfp_ag_accept()
1994 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_accept()
1995 hfp_ag_unlock(ag); in bt_hfp_ag_accept()
1999 if (ag->call_state != BT_HFP_CALL_ALERTING) { in bt_hfp_ag_accept()
2000 hfp_ag_unlock(ag); in bt_hfp_ag_accept()
2003 hfp_ag_unlock(ag); in bt_hfp_ag_accept()
2005 if (!atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_accept()
2009 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 1, bt_hfp_ag_accept_cb, NULL); in bt_hfp_ag_accept()
2014 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_accept()
2023 int bt_hfp_ag_terminate(struct bt_hfp_ag *ag) in bt_hfp_ag_terminate() argument
2029 if (ag == NULL) { in bt_hfp_ag_terminate()
2033 hfp_ag_lock(ag); in bt_hfp_ag_terminate()
2034 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_terminate()
2035 hfp_ag_unlock(ag); in bt_hfp_ag_terminate()
2039 if ((ag->call_state != BT_HFP_CALL_ACTIVE) && (ag->call_state != BT_HFP_CALL_HOLD)) { in bt_hfp_ag_terminate()
2040 hfp_ag_unlock(ag); in bt_hfp_ag_terminate()
2043 hfp_ag_unlock(ag); in bt_hfp_ag_terminate()
2045 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, bt_hfp_ag_terminate_cb, NULL); in bt_hfp_ag_terminate()
2050 static void bt_hfp_ag_outgoing_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_outgoing_cb() argument
2052 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_OUTGOING); in bt_hfp_ag_outgoing_cb()
2055 bt_ag->outgoing(ag, ag->number); in bt_hfp_ag_outgoing_cb()
2058 if (atomic_test_bit(ag->flags, BT_HFP_AG_INBAND_RING)) { in bt_hfp_ag_outgoing_cb()
2061 err = bt_hfp_ag_create_audio_connection(ag); in bt_hfp_ag_outgoing_cb()
2063 bt_hfp_ag_call_reject(ag, NULL); in bt_hfp_ag_outgoing_cb()
2068 int bt_hfp_ag_outgoing(struct bt_hfp_ag *ag, const char *number) in bt_hfp_ag_outgoing() argument
2075 if (ag == NULL) { in bt_hfp_ag_outgoing()
2079 hfp_ag_lock(ag); in bt_hfp_ag_outgoing()
2080 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_outgoing()
2081 hfp_ag_unlock(ag); in bt_hfp_ag_outgoing()
2085 if (ag->call_state != BT_HFP_CALL_TERMINATE) { in bt_hfp_ag_outgoing()
2086 hfp_ag_unlock(ag); in bt_hfp_ag_outgoing()
2089 hfp_ag_unlock(ag); in bt_hfp_ag_outgoing()
2096 hfp_ag_lock(ag); in bt_hfp_ag_outgoing()
2098 memcpy(ag->number, number, len + 1); in bt_hfp_ag_outgoing()
2099 hfp_ag_unlock(ag); in bt_hfp_ag_outgoing()
2101 atomic_clear_bit(ag->flags, BT_HFP_AG_INCOMING_CALL); in bt_hfp_ag_outgoing()
2103 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_OUTGOING, in bt_hfp_ag_outgoing()
2109 static void bt_hfp_ag_ringing_cb(struct bt_hfp_ag *ag, void *user_data) in bt_hfp_ag_ringing_cb() argument
2111 bt_hfp_ag_set_call_state(ag, BT_HFP_CALL_ALERTING); in bt_hfp_ag_ringing_cb()
2113 if (atomic_test_bit(ag->flags, BT_HFP_AG_INBAND_RING)) { in bt_hfp_ag_ringing_cb()
2114 bt_hfp_ag_call_ringing_cb(ag, true); in bt_hfp_ag_ringing_cb()
2116 bt_hfp_ag_call_ringing_cb(ag, false); in bt_hfp_ag_ringing_cb()
2120 int bt_hfp_ag_remote_ringing(struct bt_hfp_ag *ag) in bt_hfp_ag_remote_ringing() argument
2126 if (ag == NULL) { in bt_hfp_ag_remote_ringing()
2130 hfp_ag_lock(ag); in bt_hfp_ag_remote_ringing()
2131 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_remote_ringing()
2132 hfp_ag_unlock(ag); in bt_hfp_ag_remote_ringing()
2136 if (ag->call_state != BT_HFP_CALL_OUTGOING) { in bt_hfp_ag_remote_ringing()
2137 hfp_ag_unlock(ag); in bt_hfp_ag_remote_ringing()
2141 if (atomic_test_bit(ag->flags, BT_HFP_AG_INBAND_RING)) { in bt_hfp_ag_remote_ringing()
2142 if (ag->sco_chan.sco == NULL) { in bt_hfp_ag_remote_ringing()
2143 hfp_ag_unlock(ag); in bt_hfp_ag_remote_ringing()
2147 hfp_ag_unlock(ag); in bt_hfp_ag_remote_ringing()
2149 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, in bt_hfp_ag_remote_ringing()
2156 int bt_hfp_ag_remote_reject(struct bt_hfp_ag *ag) in bt_hfp_ag_remote_reject() argument
2162 if (ag == NULL) { in bt_hfp_ag_remote_reject()
2166 hfp_ag_lock(ag); in bt_hfp_ag_remote_reject()
2167 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_remote_reject()
2168 hfp_ag_unlock(ag); in bt_hfp_ag_remote_reject()
2172 if ((ag->call_state != BT_HFP_CALL_ALERTING) && (ag->call_state != BT_HFP_CALL_OUTGOING)) { in bt_hfp_ag_remote_reject()
2173 hfp_ag_unlock(ag); in bt_hfp_ag_remote_reject()
2176 hfp_ag_unlock(ag); in bt_hfp_ag_remote_reject()
2178 if (atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_remote_reject()
2182 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_remote_reject()
2188 int bt_hfp_ag_remote_accept(struct bt_hfp_ag *ag) in bt_hfp_ag_remote_accept() argument
2194 if (ag == NULL) { in bt_hfp_ag_remote_accept()
2198 hfp_ag_lock(ag); in bt_hfp_ag_remote_accept()
2199 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_remote_accept()
2200 hfp_ag_unlock(ag); in bt_hfp_ag_remote_accept()
2204 if (ag->call_state != BT_HFP_CALL_ALERTING) { in bt_hfp_ag_remote_accept()
2205 hfp_ag_unlock(ag); in bt_hfp_ag_remote_accept()
2208 hfp_ag_unlock(ag); in bt_hfp_ag_remote_accept()
2210 if (atomic_test_bit(ag->flags, BT_HFP_AG_INCOMING_CALL)) { in bt_hfp_ag_remote_accept()
2214 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 1, bt_hfp_ag_accept_cb, NULL); in bt_hfp_ag_remote_accept()
2219 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_SETUP_IND, BT_HFP_CALL_SETUP_NONE, in bt_hfp_ag_remote_accept()
2228 int bt_hfp_ag_remote_terminate(struct bt_hfp_ag *ag) in bt_hfp_ag_remote_terminate() argument
2234 if (ag == NULL) { in bt_hfp_ag_remote_terminate()
2238 hfp_ag_lock(ag); in bt_hfp_ag_remote_terminate()
2239 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_remote_terminate()
2240 hfp_ag_unlock(ag); in bt_hfp_ag_remote_terminate()
2244 if ((ag->call_state != BT_HFP_CALL_ACTIVE) && (ag->call_state != BT_HFP_CALL_HOLD)) { in bt_hfp_ag_remote_terminate()
2245 hfp_ag_unlock(ag); in bt_hfp_ag_remote_terminate()
2248 hfp_ag_unlock(ag); in bt_hfp_ag_remote_terminate()
2250 err = hfp_ag_update_indicator(ag, BT_HFP_AG_CALL_IND, 0, bt_hfp_ag_terminate_cb, NULL); in bt_hfp_ag_remote_terminate()
2255 int bt_hfp_ag_set_indicator(struct bt_hfp_ag *ag, enum bt_hfp_ag_indicator index, uint8_t value) in bt_hfp_ag_set_indicator() argument
2261 if (ag == NULL) { in bt_hfp_ag_set_indicator()
2265 hfp_ag_lock(ag); in bt_hfp_ag_set_indicator()
2266 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_set_indicator()
2267 hfp_ag_unlock(ag); in bt_hfp_ag_set_indicator()
2270 hfp_ag_unlock(ag); in bt_hfp_ag_set_indicator()
2294 err = hfp_ag_update_indicator(ag, index, value, NULL, NULL); in bt_hfp_ag_set_indicator()
2299 int bt_hfp_ag_set_operator(struct bt_hfp_ag *ag, char *name) in bt_hfp_ag_set_operator() argument
2305 if (ag == NULL) { in bt_hfp_ag_set_operator()
2309 hfp_ag_lock(ag); in bt_hfp_ag_set_operator()
2310 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_set_operator()
2311 hfp_ag_unlock(ag); in bt_hfp_ag_set_operator()
2316 len = MIN(sizeof(ag->operator) - 1, len); in bt_hfp_ag_set_operator()
2317 memcpy(ag->operator, name, len); in bt_hfp_ag_set_operator()
2318 ag->operator[len] = '\0'; in bt_hfp_ag_set_operator()
2319 hfp_ag_unlock(ag); in bt_hfp_ag_set_operator()
2324 int bt_hfp_ag_select_codec(struct bt_hfp_ag *ag, uint8_t id) in bt_hfp_ag_select_codec() argument
2330 if (ag == NULL) { in bt_hfp_ag_select_codec()
2334 hfp_ag_lock(ag); in bt_hfp_ag_select_codec()
2335 if (ag->state != BT_HFP_CONNECTED) { in bt_hfp_ag_select_codec()
2336 hfp_ag_unlock(ag); in bt_hfp_ag_select_codec()
2340 if (!(ag->hf_codec_ids && BIT(id))) { in bt_hfp_ag_select_codec()
2341 hfp_ag_unlock(ag); in bt_hfp_ag_select_codec()
2344 hfp_ag_unlock(ag); in bt_hfp_ag_select_codec()
2346 if (atomic_test_bit(ag->flags, BT_HFP_AG_CODEC_CONN)) { in bt_hfp_ag_select_codec()
2350 hfp_ag_lock(ag); in bt_hfp_ag_select_codec()
2351 ag->selected_codec_id = id; in bt_hfp_ag_select_codec()
2352 hfp_ag_unlock(ag); in bt_hfp_ag_select_codec()
2354 atomic_set_bit(ag->flags, BT_HFP_AG_CODEC_CHANGED); in bt_hfp_ag_select_codec()
2356 err = bt_hfp_ag_create_audio_connection(ag); in bt_hfp_ag_select_codec()