xref: /btstack/src/classic/hfp_gsm_model.c (revision df1e871fcfe703cb03429ba32131851efc0e720f)
174386ee0SMatthias Ringwald /*
274386ee0SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
374386ee0SMatthias Ringwald  *
474386ee0SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
574386ee0SMatthias Ringwald  * modification, are permitted provided that the following conditions
674386ee0SMatthias Ringwald  * are met:
774386ee0SMatthias Ringwald  *
874386ee0SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
974386ee0SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
1074386ee0SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
1174386ee0SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
1274386ee0SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
1374386ee0SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
1474386ee0SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
1574386ee0SMatthias Ringwald  *    from this software without specific prior written permission.
1674386ee0SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
1774386ee0SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
1874386ee0SMatthias Ringwald  *    monetary gain.
1974386ee0SMatthias Ringwald  *
2074386ee0SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
2174386ee0SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2274386ee0SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2574386ee0SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2674386ee0SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2774386ee0SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2874386ee0SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2974386ee0SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
3074386ee0SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3174386ee0SMatthias Ringwald  * SUCH DAMAGE.
3274386ee0SMatthias Ringwald  *
3374386ee0SMatthias Ringwald  * Please inquire about commercial licensing options at
3474386ee0SMatthias Ringwald  * [email protected]
3574386ee0SMatthias Ringwald  *
3674386ee0SMatthias Ringwald  */
37ab2c6ae4SMatthias Ringwald 
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "hfp_gsm_model.c"
3974386ee0SMatthias Ringwald 
4074386ee0SMatthias Ringwald // *****************************************************************************
4174386ee0SMatthias Ringwald //
429cae807eSMatthias Ringwald // GSM Model
4374386ee0SMatthias Ringwald //
4474386ee0SMatthias Ringwald // *****************************************************************************
4574386ee0SMatthias Ringwald 
467907f069SMatthias Ringwald #include "btstack_config.h"
4774386ee0SMatthias Ringwald 
4874386ee0SMatthias Ringwald #include <stdint.h>
4974386ee0SMatthias Ringwald #include <string.h>
5074386ee0SMatthias Ringwald 
5174386ee0SMatthias Ringwald #include "btstack_memory.h"
5259c6af15SMatthias Ringwald #include "classic/core.h"
5374386ee0SMatthias Ringwald #include "classic/hfp.h"
5474386ee0SMatthias Ringwald #include "classic/hfp_gsm_model.h"
55746ccb7eSMatthias Ringwald #include "classic/sdp_server.h"
56efda0b48SMatthias Ringwald #include "classic/sdp_client_rfcomm.h"
5716ece135SMatthias Ringwald #include "btstack_debug.h"
5874386ee0SMatthias Ringwald #include "hci.h"
5956042629SMatthias Ringwald #include "hci_cmd.h"
6074386ee0SMatthias Ringwald #include "hci_dump.h"
6174386ee0SMatthias Ringwald #include "l2cap.h"
6282636622SMatthias Ringwald #include "btstack_run_loop.h"
6374386ee0SMatthias Ringwald 
6474386ee0SMatthias Ringwald #define HFP_GSM_MAX_NR_CALLS 3
659cae807eSMatthias Ringwald #define HFP_GSM_MAX_CALL_NUMBER_SIZE 25
6674386ee0SMatthias Ringwald 
67aeb0f0feSMatthias Ringwald static hfp_gsm_call_t         hfp_gsm_model_calls[HFP_GSM_MAX_NR_CALLS];
68aeb0f0feSMatthias Ringwald static hfp_callsetup_status_t hfp_gsm_model_callsetup_status;
6974386ee0SMatthias Ringwald 
70aeb0f0feSMatthias Ringwald static uint8_t hfp_gsm_model_clip_type;
71aeb0f0feSMatthias Ringwald static char    hfp_gsm_model_clip_number[HFP_GSM_MAX_CALL_NUMBER_SIZE];
72aeb0f0feSMatthias Ringwald static char    hfp_gsm_model_last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE];
73d0c20769SMatthias Ringwald 
74aeb0f0feSMatthias Ringwald static inline int hfp_gsm_model_get_number_active_calls(void);
7566a048abSMatthias Ringwald 
7666a048abSMatthias Ringwald static void set_callsetup_status(hfp_callsetup_status_t status){
77aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = status;
78aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_callsetup_status != HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE) return;
7966a048abSMatthias Ringwald 
8066a048abSMatthias Ringwald     int i ;
8166a048abSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
82aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[i].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){
83aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[i].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING;
8466a048abSMatthias Ringwald         }
8566a048abSMatthias Ringwald     }
8666a048abSMatthias Ringwald }
8766a048abSMatthias Ringwald 
8866a048abSMatthias Ringwald static inline void set_enhanced_call_status_active(int index_in_table){
89a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return;
90aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE;
91*df1e871fSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = true;
9266a048abSMatthias Ringwald }
9366a048abSMatthias Ringwald 
9466a048abSMatthias Ringwald static inline void set_enhanced_call_status_held(int index_in_table){
95a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return;
96aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD;
97*df1e871fSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = true;
9866a048abSMatthias Ringwald }
9966a048abSMatthias Ringwald 
10066a048abSMatthias Ringwald static inline void set_enhanced_call_status_response_hold(int index_in_table){
101a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return;
102aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD;
103*df1e871fSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = true;
10466a048abSMatthias Ringwald }
10566a048abSMatthias Ringwald 
10666a048abSMatthias Ringwald static inline void set_enhanced_call_status_initiated(int index_in_table){
107a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return;
108aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){
109aeb0f0feSMatthias Ringwald         hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING;
11066a048abSMatthias Ringwald     } else {
111aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_get_number_active_calls() > 0){
112aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING;
11366a048abSMatthias Ringwald         } else {
114aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING;
11566a048abSMatthias Ringwald         }
11666a048abSMatthias Ringwald     }
117*df1e871fSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = true;
11866a048abSMatthias Ringwald }
11966a048abSMatthias Ringwald 
12066a048abSMatthias Ringwald static int get_enhanced_call_status(int index_in_table){
121a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return -1;
122aeb0f0feSMatthias Ringwald     if (!hfp_gsm_model_calls[index_in_table].used_slot) return -1;
123aeb0f0feSMatthias Ringwald     return hfp_gsm_model_calls[index_in_table].enhanced_status;
12466a048abSMatthias Ringwald }
12566a048abSMatthias Ringwald 
12666a048abSMatthias Ringwald static inline int is_enhanced_call_status_active(int index_in_table){
127a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return 0;
12866a048abSMatthias Ringwald     return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_ACTIVE;
12966a048abSMatthias Ringwald }
13066a048abSMatthias Ringwald 
13166a048abSMatthias Ringwald static inline int is_enhanced_call_status_initiated(int index_in_table){
132a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return 0;
13366a048abSMatthias Ringwald     switch (get_enhanced_call_status(index_in_table)){
13466a048abSMatthias Ringwald         case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING:
13566a048abSMatthias Ringwald         case HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING:
13666a048abSMatthias Ringwald         case HFP_ENHANCED_CALL_STATUS_INCOMING:
13766a048abSMatthias Ringwald         case HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING:
13866a048abSMatthias Ringwald             return 1;
13966a048abSMatthias Ringwald         default:
14066a048abSMatthias Ringwald             return 0;
14166a048abSMatthias Ringwald     }
14266a048abSMatthias Ringwald }
14366a048abSMatthias Ringwald 
14466a048abSMatthias Ringwald static void free_call_slot(int index_in_table){
145a9a12719SMatthias Ringwald     if ((index_in_table < 0) || (index_in_table > HFP_GSM_MAX_NR_CALLS)) return;
146*df1e871fSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = false;
14766a048abSMatthias Ringwald }
148d0c20769SMatthias Ringwald 
149d210d9c4SMatthias Ringwald void hfp_gsm_init(void){
150aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
151aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
152aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
153aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_last_dialed_number, 0, sizeof(hfp_gsm_model_last_dialed_number));
154aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_calls, 0, sizeof(hfp_gsm_model_calls));
155d210d9c4SMatthias Ringwald     int i;
156d210d9c4SMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
15766a048abSMatthias Ringwald         free_call_slot(i);
158d210d9c4SMatthias Ringwald     }
159d210d9c4SMatthias Ringwald }
16074386ee0SMatthias Ringwald 
16120b2edb6SMatthias Ringwald void hfp_gsm_deinit(void){
162aeb0f0feSMatthias Ringwald     (void) memset(hfp_gsm_model_calls, 0, sizeof(hfp_gsm_model_calls));
163aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
164aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
165aeb0f0feSMatthias Ringwald     (void) memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
166aeb0f0feSMatthias Ringwald     (void) memset(hfp_gsm_model_last_dialed_number, 0, sizeof(hfp_gsm_model_last_dialed_number));
16720b2edb6SMatthias Ringwald }
16820b2edb6SMatthias Ringwald 
16966a048abSMatthias Ringwald static int get_number_calls_with_enhanced_status(hfp_enhanced_call_status_t enhanced_status){
17074386ee0SMatthias Ringwald     int i, count = 0;
17174386ee0SMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
172fdfcab43SMatthias Ringwald         if (get_enhanced_call_status(i) == (int) enhanced_status) count++;
17374386ee0SMatthias Ringwald     }
17474386ee0SMatthias Ringwald     return count;
17574386ee0SMatthias Ringwald }
17674386ee0SMatthias Ringwald 
17766a048abSMatthias Ringwald static int get_call_index_with_enhanced_status(hfp_enhanced_call_status_t enhanced_status){
17874386ee0SMatthias Ringwald     int i ;
17974386ee0SMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
180fdfcab43SMatthias Ringwald         if (get_enhanced_call_status(i) == (int) enhanced_status) return i;
18166a048abSMatthias Ringwald     }
18266a048abSMatthias Ringwald     return -1;
18366a048abSMatthias Ringwald }
18466a048abSMatthias Ringwald 
18566a048abSMatthias Ringwald static inline int get_initiated_call_index(void){
18666a048abSMatthias Ringwald     int i ;
18766a048abSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
18866a048abSMatthias Ringwald         if (is_enhanced_call_status_initiated(i)) return i;
18974386ee0SMatthias Ringwald     }
19074386ee0SMatthias Ringwald     return -1;
19174386ee0SMatthias Ringwald }
19274386ee0SMatthias Ringwald 
1939cae807eSMatthias Ringwald static inline int get_next_free_slot(void){
19466a048abSMatthias Ringwald     int i ;
19566a048abSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
196aeb0f0feSMatthias Ringwald         if (!hfp_gsm_model_calls[i].used_slot) return i;
19766a048abSMatthias Ringwald     }
19866a048abSMatthias Ringwald     return -1;
19974386ee0SMatthias Ringwald }
20074386ee0SMatthias Ringwald 
2019cae807eSMatthias Ringwald static inline int get_active_call_index(void){
20266a048abSMatthias Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_ACTIVE);
203d210d9c4SMatthias Ringwald }
204d210d9c4SMatthias Ringwald 
205baa221a8SMilanka Ringwald static inline int get_dialing_call_index(void){
206baa221a8SMilanka Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING);
207baa221a8SMilanka Ringwald }
208baa221a8SMilanka Ringwald 
2099cae807eSMatthias Ringwald static inline int get_held_call_index(void){
21066a048abSMatthias Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD);
211d210d9c4SMatthias Ringwald }
212d210d9c4SMatthias Ringwald 
2139cae807eSMatthias Ringwald static inline int get_response_held_call_index(void){
21466a048abSMatthias Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD);
215d210d9c4SMatthias Ringwald }
216d210d9c4SMatthias Ringwald 
2179cae807eSMatthias Ringwald static inline int get_number_none_calls(void){
21866a048abSMatthias Ringwald     int i, count = 0;
21966a048abSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
220aeb0f0feSMatthias Ringwald         if (!hfp_gsm_model_calls[i].used_slot) count++;
22166a048abSMatthias Ringwald     }
22266a048abSMatthias Ringwald     return count;
223d210d9c4SMatthias Ringwald }
22474386ee0SMatthias Ringwald 
225aeb0f0feSMatthias Ringwald static inline int hfp_gsm_model_get_number_active_calls(void){
22666a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_ACTIVE);
22774386ee0SMatthias Ringwald }
22874386ee0SMatthias Ringwald 
2299cae807eSMatthias Ringwald static inline int get_number_held_calls(void){
23066a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD);
23174386ee0SMatthias Ringwald }
23274386ee0SMatthias Ringwald 
2339cae807eSMatthias Ringwald static inline int get_number_response_held_calls(void){
23466a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD);
235d210d9c4SMatthias Ringwald }
236d210d9c4SMatthias Ringwald 
2379cae807eSMatthias Ringwald static int next_call_index(void){
238d0c20769SMatthias Ringwald     return HFP_GSM_MAX_NR_CALLS + 1 - get_number_none_calls();
239d0c20769SMatthias Ringwald }
240d0c20769SMatthias Ringwald 
241d0c20769SMatthias Ringwald static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * number){
24221791470SMilanka Ringwald     uint16_t number_str_len = (uint16_t) strlen(number);
24321791470SMilanka Ringwald     if (number_str_len == 0) return;
2449cae807eSMatthias Ringwald 
245aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].clip_type = type;
246c10fde09SMatthias Ringwald     btstack_strcpy(hfp_gsm_model_calls[index_in_table].clip_number, HFP_GSM_MAX_CALL_NUMBER_SIZE, number);
247c10fde09SMatthias Ringwald     btstack_strcpy(hfp_gsm_model_last_dialed_number, HFP_GSM_MAX_CALL_NUMBER_SIZE, number);
248aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
249aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
250d0c20769SMatthias Ringwald }
251d0c20769SMatthias Ringwald 
252d0c20769SMatthias Ringwald static void delete_call(int delete_index_in_table){
253d0c20769SMatthias Ringwald     int i ;
254d0c20769SMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
255aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[i].index > hfp_gsm_model_calls[delete_index_in_table].index){
256aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[i].index--;
257d0c20769SMatthias Ringwald         }
258d0c20769SMatthias Ringwald     }
25966a048abSMatthias Ringwald     free_call_slot(delete_index_in_table);
260d0c20769SMatthias Ringwald 
261aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_type = 0;
262aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].index = 0;
263aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_number[0] = '\0';
264aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
265d0c20769SMatthias Ringwald }
266d0c20769SMatthias Ringwald 
2679cae807eSMatthias Ringwald 
2689cae807eSMatthias Ringwald static void create_call(hfp_enhanced_call_dir_t direction){
269d0c20769SMatthias Ringwald     int next_free_slot = get_next_free_slot();
270aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].direction = direction;
271aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].index = next_call_index();
27266a048abSMatthias Ringwald     set_enhanced_call_status_initiated(next_free_slot);
273aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_type = 0;
274aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_number[0] = '\0';
275aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
276d0c20769SMatthias Ringwald 
277aeb0f0feSMatthias Ringwald     hfp_gsm_set_clip(next_free_slot, hfp_gsm_model_clip_type, hfp_gsm_model_clip_number);
278d0c20769SMatthias Ringwald }
279d0c20769SMatthias Ringwald 
2809cae807eSMatthias Ringwald 
2819cae807eSMatthias Ringwald int hfp_gsm_get_number_of_calls(void){
2829cae807eSMatthias Ringwald     return HFP_GSM_MAX_NR_CALLS - get_number_none_calls();
2839cae807eSMatthias Ringwald }
2849cae807eSMatthias Ringwald 
2859cae807eSMatthias Ringwald void hfp_gsm_clear_last_dialed_number(void){
286aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_last_dialed_number, 0, sizeof(hfp_gsm_model_last_dialed_number));
2879cae807eSMatthias Ringwald }
2889cae807eSMatthias Ringwald 
2899cae807eSMatthias Ringwald char * hfp_gsm_last_dialed_number(void){
290aeb0f0feSMatthias Ringwald     return &hfp_gsm_model_last_dialed_number[0];
2919cae807eSMatthias Ringwald }
2929cae807eSMatthias Ringwald 
2939de679b7SMilanka Ringwald void hfp_gsm_set_last_dialed_number(const char* number){
294c10fde09SMatthias Ringwald     btstack_strcpy(hfp_gsm_model_last_dialed_number, sizeof(hfp_gsm_model_last_dialed_number), number);
2959de679b7SMilanka Ringwald }
2969de679b7SMilanka Ringwald 
2979cae807eSMatthias Ringwald hfp_gsm_call_t * hfp_gsm_call(int call_index){
2989cae807eSMatthias Ringwald     int i;
2999cae807eSMatthias Ringwald 
3009cae807eSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
301aeb0f0feSMatthias Ringwald         hfp_gsm_call_t * call = &hfp_gsm_model_calls[i];
3029cae807eSMatthias Ringwald         if (call->index != call_index) continue;
3039cae807eSMatthias Ringwald         return call;
3049cae807eSMatthias Ringwald     }
3059cae807eSMatthias Ringwald     return NULL;
3069cae807eSMatthias Ringwald }
3079cae807eSMatthias Ringwald 
3089cae807eSMatthias Ringwald uint8_t hfp_gsm_clip_type(void){
309aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_clip_type != 0) return hfp_gsm_model_clip_type;
310d0c20769SMatthias Ringwald 
311d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
312d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
313aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
314aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_type;
315d0c20769SMatthias Ringwald         }
316d0c20769SMatthias Ringwald     }
317d0c20769SMatthias Ringwald 
318d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
319d0c20769SMatthias Ringwald     if (active_call_index != -1){
320aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
321aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_type;
322d0c20769SMatthias Ringwald         }
323d0c20769SMatthias Ringwald     }
324d0c20769SMatthias Ringwald     return 0;
325d0c20769SMatthias Ringwald }
326d0c20769SMatthias Ringwald 
3279cae807eSMatthias Ringwald char *  hfp_gsm_clip_number(void){
328aeb0f0feSMatthias Ringwald     if (strlen(hfp_gsm_model_clip_number) != 0) return hfp_gsm_model_clip_number;
329d0c20769SMatthias Ringwald 
330d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
331d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
332aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
333aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_number;
334d0c20769SMatthias Ringwald         }
335d0c20769SMatthias Ringwald     }
336d0c20769SMatthias Ringwald 
337d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
338d0c20769SMatthias Ringwald     if (active_call_index != -1){
339aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
340aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_number;
341d0c20769SMatthias Ringwald         }
342d0c20769SMatthias Ringwald     }
343aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_number[0] = 0;
344aeb0f0feSMatthias Ringwald     return hfp_gsm_model_clip_number;
345d0c20769SMatthias Ringwald }
346d0c20769SMatthias Ringwald 
3479cae807eSMatthias Ringwald hfp_call_status_t hfp_gsm_call_status(void){
348aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() + get_number_held_calls() + get_number_response_held_calls()){
34974386ee0SMatthias Ringwald         return HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT;
35074386ee0SMatthias Ringwald     }
35174386ee0SMatthias Ringwald     return HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS;
35274386ee0SMatthias Ringwald }
35374386ee0SMatthias Ringwald 
3549cae807eSMatthias Ringwald hfp_callheld_status_t hfp_gsm_callheld_status(void){
35574386ee0SMatthias Ringwald     // @note: order is important
35674386ee0SMatthias Ringwald     if (get_number_held_calls() == 0){
35774386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_NO_CALLS_HELD;
35874386ee0SMatthias Ringwald     }
359aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() == 0) {
36074386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS;
36174386ee0SMatthias Ringwald     }
36274386ee0SMatthias Ringwald     return HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED;
36374386ee0SMatthias Ringwald }
36474386ee0SMatthias Ringwald 
3659cae807eSMatthias Ringwald hfp_callsetup_status_t hfp_gsm_callsetup_status(void){
366aeb0f0feSMatthias Ringwald     return hfp_gsm_model_callsetup_status;
36774386ee0SMatthias Ringwald }
36874386ee0SMatthias Ringwald 
3699cae807eSMatthias Ringwald static int hfp_gsm_response_held_active(void){
370d210d9c4SMatthias Ringwald     return get_response_held_call_index() != -1 ;
371d210d9c4SMatthias Ringwald }
372d210d9c4SMatthias Ringwald 
373d210d9c4SMatthias Ringwald int hfp_gsm_call_possible(void){
374d210d9c4SMatthias Ringwald     return get_number_none_calls() > 0;
375d210d9c4SMatthias Ringwald }
376d210d9c4SMatthias Ringwald 
377f8737b81SMatthias Ringwald void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number){
378d0c20769SMatthias Ringwald     int next_free_slot = get_next_free_slot();
37974386ee0SMatthias Ringwald     int current_call_index = get_active_call_index();
380d210d9c4SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
381d210d9c4SMatthias Ringwald     int held_call_index = get_held_call_index();
382d0c20769SMatthias Ringwald     int i;
383d0c20769SMatthias Ringwald 
38474386ee0SMatthias Ringwald     switch (event){
3859ff73f41SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_HF:
386fe899794SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_AG:
38774386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_REDIAL_INITIATED:
38874386ee0SMatthias Ringwald             if (next_free_slot == -1){
389d210d9c4SMatthias Ringwald                 log_error("gsm: max call nr exceeded");
39074386ee0SMatthias Ringwald                 return;
39174386ee0SMatthias Ringwald             }
3929cae807eSMatthias Ringwald             create_call(HFP_ENHANCED_CALL_DIR_OUTGOING);
393d210d9c4SMatthias Ringwald             break;
39474386ee0SMatthias Ringwald 
395d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_REJECTED:
396d210d9c4SMatthias Ringwald             if (current_call_index != -1){
397d0c20769SMatthias Ringwald                 delete_call(current_call_index);
398d210d9c4SMatthias Ringwald             }
39966a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
400d210d9c4SMatthias Ringwald             break;
401d210d9c4SMatthias Ringwald 
402d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_ACCEPTED:
40374386ee0SMatthias Ringwald             if (current_call_index != -1){
40466a048abSMatthias Ringwald                 set_enhanced_call_status_held(current_call_index);
40574386ee0SMatthias Ringwald             }
40666a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE);
40774386ee0SMatthias Ringwald             break;
408d210d9c4SMatthias Ringwald 
40974386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_RINGING:
410baa221a8SMilanka Ringwald             current_call_index = get_dialing_call_index();
411d210d9c4SMatthias Ringwald             if (current_call_index == -1){
412d210d9c4SMatthias Ringwald                 log_error("gsm: no active call");
413d210d9c4SMatthias Ringwald                 return;
414d210d9c4SMatthias Ringwald             }
41566a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE);
41674386ee0SMatthias Ringwald             break;
41774386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_ESTABLISHED:
41866a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
41966a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
42074386ee0SMatthias Ringwald             break;
421d210d9c4SMatthias Ringwald 
422d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL:
423d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS) break;
42466a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS);
4259cae807eSMatthias Ringwald             create_call(HFP_ENHANCED_CALL_DIR_INCOMING);
426d210d9c4SMatthias Ringwald             break;
427d210d9c4SMatthias Ringwald 
428d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG:
429d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
43066a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
431d210d9c4SMatthias Ringwald 
432d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){
43366a048abSMatthias Ringwald                 set_enhanced_call_status_held(current_call_index);
434d210d9c4SMatthias Ringwald             }
43566a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
436d210d9c4SMatthias Ringwald             break;
437d210d9c4SMatthias Ringwald 
438d210d9c4SMatthias Ringwald         case HFP_AG_HELD_CALL_JOINED_BY_AG:
439d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
440d210d9c4SMatthias Ringwald 
441d210d9c4SMatthias Ringwald             // TODO: is following condition correct? Can we join incoming call before it is answered?
442aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){
44366a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
44466a048abSMatthias Ringwald                 set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
4459cae807eSMatthias Ringwald             } else if (hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED) {
44666a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
447d210d9c4SMatthias Ringwald             }
448d210d9c4SMatthias Ringwald 
4499cae807eSMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
45066a048abSMatthias Ringwald                 if (is_enhanced_call_status_active(i)){
451aeb0f0feSMatthias Ringwald                     hfp_gsm_model_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
4529cae807eSMatthias Ringwald                 }
453d210d9c4SMatthias Ringwald             }
454d210d9c4SMatthias Ringwald             break;
455d210d9c4SMatthias Ringwald 
456d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF:
457d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
458d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break;
45966a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
46066a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
461d210d9c4SMatthias Ringwald             break;
462d210d9c4SMatthias Ringwald 
463d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG:
464d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF:
465d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
466d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break;
46766a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
46866a048abSMatthias Ringwald             set_enhanced_call_status_response_hold(initiated_call_index);
469d210d9c4SMatthias Ringwald             break;
470d210d9c4SMatthias Ringwald 
471d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG:
472d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF:
473d210d9c4SMatthias Ringwald             if (!hfp_gsm_response_held_active()) break;
47466a048abSMatthias Ringwald             set_enhanced_call_status_active(get_response_held_call_index());
475d210d9c4SMatthias Ringwald             break;
476d210d9c4SMatthias Ringwald 
477d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG:
478d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF:
479d210d9c4SMatthias Ringwald             if (!hfp_gsm_response_held_active()) break;
480d0c20769SMatthias Ringwald             delete_call(get_response_held_call_index());
481d210d9c4SMatthias Ringwald             break;
482d210d9c4SMatthias Ringwald 
483d210d9c4SMatthias Ringwald 
484d210d9c4SMatthias Ringwald         case HFP_AG_TERMINATE_CALL_BY_HF:
485d210d9c4SMatthias Ringwald             switch (hfp_gsm_call_status()){
486d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
48766a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
488d210d9c4SMatthias Ringwald                     break;
489d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT:
490d0c20769SMatthias Ringwald                     delete_call(current_call_index);
491d210d9c4SMatthias Ringwald                     break;
4927bbeb3adSMilanka Ringwald                 default:
4937bbeb3adSMilanka Ringwald                     break;
494d210d9c4SMatthias Ringwald             }
495d210d9c4SMatthias Ringwald             break;
496d210d9c4SMatthias Ringwald 
497d210d9c4SMatthias Ringwald         case HFP_AG_TERMINATE_CALL_BY_AG:
498d210d9c4SMatthias Ringwald             switch (hfp_gsm_call_status()){
499d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
500d210d9c4SMatthias Ringwald                     if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
50166a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
502d210d9c4SMatthias Ringwald                     break;
503d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT:
50466a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
505d0c20769SMatthias Ringwald                     delete_call(current_call_index);
506d210d9c4SMatthias Ringwald                     break;
507d210d9c4SMatthias Ringwald                 default:
508d210d9c4SMatthias Ringwald                     break;
509d210d9c4SMatthias Ringwald             }
510d210d9c4SMatthias Ringwald             break;
511d210d9c4SMatthias Ringwald 
512d0c20769SMatthias Ringwald         case HFP_AG_CALL_DROPPED:
51366a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
514d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
515d210d9c4SMatthias Ringwald 
516d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
517d0c20769SMatthias Ringwald                 delete_call(i);
518d210d9c4SMatthias Ringwald             }
519d210d9c4SMatthias Ringwald             break;
520d0c20769SMatthias Ringwald 
521d210d9c4SMatthias Ringwald         case HFP_AG_CALL_HOLD_USER_BUSY:
522d210d9c4SMatthias Ringwald             // Held or waiting call gets active,
52366a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
52466a048abSMatthias Ringwald             free_call_slot(initiated_call_index);
52566a048abSMatthias Ringwald             set_enhanced_call_status_active(held_call_index);
526d210d9c4SMatthias Ringwald             break;
527d210d9c4SMatthias Ringwald 
528d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
529c1ab6cc1SMatthias Ringwald             if ((index != 0) && (index <= HFP_GSM_MAX_NR_CALLS) ){
530d0c20769SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
531aeb0f0feSMatthias Ringwald                     if (hfp_gsm_model_calls[i].index == index){
532d0c20769SMatthias Ringwald                         delete_call(i);
533d0c20769SMatthias Ringwald                         continue;
534d0c20769SMatthias Ringwald                     }
535d0c20769SMatthias Ringwald                 }
536d0c20769SMatthias Ringwald             } else {
537d210d9c4SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
53866a048abSMatthias Ringwald                     if (is_enhanced_call_status_active(i)){
539d0c20769SMatthias Ringwald                         delete_call(i);
540d0c20769SMatthias Ringwald                     }
541d210d9c4SMatthias Ringwald                 }
542d210d9c4SMatthias Ringwald             }
543d210d9c4SMatthias Ringwald 
544aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
54566a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
546d210d9c4SMatthias Ringwald             } else {
54766a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
548d210d9c4SMatthias Ringwald             }
549d0c20769SMatthias Ringwald 
55066a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
551d210d9c4SMatthias Ringwald             break;
552d0c20769SMatthias Ringwald 
553d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
554d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
555aeb0f0feSMatthias Ringwald                 if (is_enhanced_call_status_active(i) && (hfp_gsm_model_calls[i].index != index)){
55666a048abSMatthias Ringwald                     set_enhanced_call_status_held(i);
557d210d9c4SMatthias Ringwald                 }
558d210d9c4SMatthias Ringwald             }
559d210d9c4SMatthias Ringwald 
560aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
56166a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
562d210d9c4SMatthias Ringwald             } else {
56366a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
564d210d9c4SMatthias Ringwald             }
56566a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
566d210d9c4SMatthias Ringwald             break;
567d0c20769SMatthias Ringwald 
568d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_ADD_HELD_CALL:
569d210d9c4SMatthias Ringwald             if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){
570d210d9c4SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
571aeb0f0feSMatthias Ringwald                     if (hfp_gsm_model_calls[i].used_slot){
57266a048abSMatthias Ringwald                         set_enhanced_call_status_active(i);
573aeb0f0feSMatthias Ringwald                         hfp_gsm_model_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
574d210d9c4SMatthias Ringwald                     }
575d210d9c4SMatthias Ringwald                 }
576d210d9c4SMatthias Ringwald             }
577d210d9c4SMatthias Ringwald             break;
578d0c20769SMatthias Ringwald 
579d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS:
580d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
581d0c20769SMatthias Ringwald                 delete_call(i);
582d210d9c4SMatthias Ringwald             }
583d0c20769SMatthias Ringwald             break;
584d210d9c4SMatthias Ringwald 
585d0c20769SMatthias Ringwald         case HFP_AG_SET_CLIP:
586d0c20769SMatthias Ringwald             if (initiated_call_index != -1){
587d0c20769SMatthias Ringwald                 hfp_gsm_set_clip(initiated_call_index, type, number);
588d210d9c4SMatthias Ringwald                 break;
589d210d9c4SMatthias Ringwald             }
5909cae807eSMatthias Ringwald 
591aeb0f0feSMatthias Ringwald             hfp_gsm_model_clip_type = type;
592c10fde09SMatthias Ringwald             btstack_strcpy(hfp_gsm_model_clip_number, sizeof(hfp_gsm_model_clip_number), number);
593d0c20769SMatthias Ringwald             break;
59474386ee0SMatthias Ringwald         default:
59574386ee0SMatthias Ringwald             break;
59674386ee0SMatthias Ringwald     }
59774386ee0SMatthias Ringwald }
598