xref: /btstack/src/classic/hfp_gsm_model.c (revision baa221a80834aca0ddd50902b96f36bd89643a47)
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
2374386ee0SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
2474386ee0SMatthias Ringwald  * RINGWALD 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;
91aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 1;
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;
97aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 1;
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;
103aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 1;
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     }
117aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 1;
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;
146aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 0;
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 
205*baa221a8SMilanka Ringwald static inline int get_dialing_call_index(void){
206*baa221a8SMilanka Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING);
207*baa221a8SMilanka Ringwald }
208*baa221a8SMilanka 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;
24621791470SMilanka Ringwald     int clip_number_size = btstack_min(number_str_len, HFP_GSM_MAX_CALL_NUMBER_SIZE - 1);
247aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_calls[index_in_table].clip_number, number, clip_number_size);
248aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].clip_number[clip_number_size] = '\0';
249aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_last_dialed_number, number, clip_number_size);
250aeb0f0feSMatthias Ringwald     hfp_gsm_model_last_dialed_number[clip_number_size] = '\0';
2519cae807eSMatthias Ringwald 
252aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
253aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
254d0c20769SMatthias Ringwald }
255d0c20769SMatthias Ringwald 
256d0c20769SMatthias Ringwald static void delete_call(int delete_index_in_table){
257d0c20769SMatthias Ringwald     int i ;
258d0c20769SMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
259aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[i].index > hfp_gsm_model_calls[delete_index_in_table].index){
260aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[i].index--;
261d0c20769SMatthias Ringwald         }
262d0c20769SMatthias Ringwald     }
26366a048abSMatthias Ringwald     free_call_slot(delete_index_in_table);
264d0c20769SMatthias Ringwald 
265aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_type = 0;
266aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].index = 0;
267aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_number[0] = '\0';
268aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
269d0c20769SMatthias Ringwald }
270d0c20769SMatthias Ringwald 
2719cae807eSMatthias Ringwald 
2729cae807eSMatthias Ringwald static void create_call(hfp_enhanced_call_dir_t direction){
273d0c20769SMatthias Ringwald     int next_free_slot = get_next_free_slot();
274aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].direction = direction;
275aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].index = next_call_index();
27666a048abSMatthias Ringwald     set_enhanced_call_status_initiated(next_free_slot);
277aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_type = 0;
278aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_number[0] = '\0';
279aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
280d0c20769SMatthias Ringwald 
281aeb0f0feSMatthias Ringwald     hfp_gsm_set_clip(next_free_slot, hfp_gsm_model_clip_type, hfp_gsm_model_clip_number);
282d0c20769SMatthias Ringwald }
283d0c20769SMatthias Ringwald 
2849cae807eSMatthias Ringwald 
2859cae807eSMatthias Ringwald int hfp_gsm_get_number_of_calls(void){
2869cae807eSMatthias Ringwald     return HFP_GSM_MAX_NR_CALLS - get_number_none_calls();
2879cae807eSMatthias Ringwald }
2889cae807eSMatthias Ringwald 
2899cae807eSMatthias Ringwald void hfp_gsm_clear_last_dialed_number(void){
290aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_last_dialed_number, 0, sizeof(hfp_gsm_model_last_dialed_number));
2919cae807eSMatthias Ringwald }
2929cae807eSMatthias Ringwald 
2939cae807eSMatthias Ringwald char * hfp_gsm_last_dialed_number(void){
294aeb0f0feSMatthias Ringwald     return &hfp_gsm_model_last_dialed_number[0];
2959cae807eSMatthias Ringwald }
2969cae807eSMatthias Ringwald 
2979de679b7SMilanka Ringwald void hfp_gsm_set_last_dialed_number(const char* number){
298aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_last_dialed_number, number, sizeof(hfp_gsm_model_last_dialed_number));
299aeb0f0feSMatthias Ringwald     hfp_gsm_model_last_dialed_number[sizeof(hfp_gsm_model_last_dialed_number) - 1] = 0;
3009de679b7SMilanka Ringwald }
3019de679b7SMilanka Ringwald 
3029cae807eSMatthias Ringwald hfp_gsm_call_t * hfp_gsm_call(int call_index){
3039cae807eSMatthias Ringwald     int i;
3049cae807eSMatthias Ringwald 
3059cae807eSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
306aeb0f0feSMatthias Ringwald         hfp_gsm_call_t * call = &hfp_gsm_model_calls[i];
3079cae807eSMatthias Ringwald         if (call->index != call_index) continue;
3089cae807eSMatthias Ringwald         return call;
3099cae807eSMatthias Ringwald     }
3109cae807eSMatthias Ringwald     return NULL;
3119cae807eSMatthias Ringwald }
3129cae807eSMatthias Ringwald 
3139cae807eSMatthias Ringwald uint8_t hfp_gsm_clip_type(void){
314aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_clip_type != 0) return hfp_gsm_model_clip_type;
315d0c20769SMatthias Ringwald 
316d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
317d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
318aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
319aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_type;
320d0c20769SMatthias Ringwald         }
321d0c20769SMatthias Ringwald     }
322d0c20769SMatthias Ringwald 
323d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
324d0c20769SMatthias Ringwald     if (active_call_index != -1){
325aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
326aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_type;
327d0c20769SMatthias Ringwald         }
328d0c20769SMatthias Ringwald     }
329d0c20769SMatthias Ringwald     return 0;
330d0c20769SMatthias Ringwald }
331d0c20769SMatthias Ringwald 
3329cae807eSMatthias Ringwald char *  hfp_gsm_clip_number(void){
333aeb0f0feSMatthias Ringwald     if (strlen(hfp_gsm_model_clip_number) != 0) return hfp_gsm_model_clip_number;
334d0c20769SMatthias Ringwald 
335d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
336d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
337aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
338aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_number;
339d0c20769SMatthias Ringwald         }
340d0c20769SMatthias Ringwald     }
341d0c20769SMatthias Ringwald 
342d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
343d0c20769SMatthias Ringwald     if (active_call_index != -1){
344aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
345aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_number;
346d0c20769SMatthias Ringwald         }
347d0c20769SMatthias Ringwald     }
348aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_number[0] = 0;
349aeb0f0feSMatthias Ringwald     return hfp_gsm_model_clip_number;
350d0c20769SMatthias Ringwald }
351d0c20769SMatthias Ringwald 
3529cae807eSMatthias Ringwald hfp_call_status_t hfp_gsm_call_status(void){
353aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() + get_number_held_calls() + get_number_response_held_calls()){
35474386ee0SMatthias Ringwald         return HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT;
35574386ee0SMatthias Ringwald     }
35674386ee0SMatthias Ringwald     return HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS;
35774386ee0SMatthias Ringwald }
35874386ee0SMatthias Ringwald 
3599cae807eSMatthias Ringwald hfp_callheld_status_t hfp_gsm_callheld_status(void){
36074386ee0SMatthias Ringwald     // @note: order is important
36174386ee0SMatthias Ringwald     if (get_number_held_calls() == 0){
36274386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_NO_CALLS_HELD;
36374386ee0SMatthias Ringwald     }
364aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() == 0) {
36574386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS;
36674386ee0SMatthias Ringwald     }
36774386ee0SMatthias Ringwald     return HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED;
36874386ee0SMatthias Ringwald }
36974386ee0SMatthias Ringwald 
3709cae807eSMatthias Ringwald hfp_callsetup_status_t hfp_gsm_callsetup_status(void){
371aeb0f0feSMatthias Ringwald     return hfp_gsm_model_callsetup_status;
37274386ee0SMatthias Ringwald }
37374386ee0SMatthias Ringwald 
3749cae807eSMatthias Ringwald static int hfp_gsm_response_held_active(void){
375d210d9c4SMatthias Ringwald     return get_response_held_call_index() != -1 ;
376d210d9c4SMatthias Ringwald }
377d210d9c4SMatthias Ringwald 
378d210d9c4SMatthias Ringwald int hfp_gsm_call_possible(void){
379d210d9c4SMatthias Ringwald     return get_number_none_calls() > 0;
380d210d9c4SMatthias Ringwald }
381d210d9c4SMatthias Ringwald 
382f8737b81SMatthias Ringwald void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number){
383d0c20769SMatthias Ringwald     int next_free_slot = get_next_free_slot();
38474386ee0SMatthias Ringwald     int current_call_index = get_active_call_index();
385d210d9c4SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
386d210d9c4SMatthias Ringwald     int held_call_index = get_held_call_index();
387d0c20769SMatthias Ringwald     int i;
388d0c20769SMatthias Ringwald 
38974386ee0SMatthias Ringwald     switch (event){
3909ff73f41SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_HF:
391fe899794SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_AG:
39274386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_REDIAL_INITIATED:
39374386ee0SMatthias Ringwald             if (next_free_slot == -1){
394d210d9c4SMatthias Ringwald                 log_error("gsm: max call nr exceeded");
39574386ee0SMatthias Ringwald                 return;
39674386ee0SMatthias Ringwald             }
3979cae807eSMatthias Ringwald             create_call(HFP_ENHANCED_CALL_DIR_OUTGOING);
398d210d9c4SMatthias Ringwald             break;
39974386ee0SMatthias Ringwald 
400d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_REJECTED:
401d210d9c4SMatthias Ringwald             if (current_call_index != -1){
402d0c20769SMatthias Ringwald                 delete_call(current_call_index);
403d210d9c4SMatthias Ringwald             }
40466a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
405d210d9c4SMatthias Ringwald             break;
406d210d9c4SMatthias Ringwald 
407d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_ACCEPTED:
40874386ee0SMatthias Ringwald             if (current_call_index != -1){
40966a048abSMatthias Ringwald                 set_enhanced_call_status_held(current_call_index);
41074386ee0SMatthias Ringwald             }
41166a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE);
41274386ee0SMatthias Ringwald             break;
413d210d9c4SMatthias Ringwald 
41474386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_RINGING:
415*baa221a8SMilanka Ringwald             current_call_index = get_dialing_call_index();
416d210d9c4SMatthias Ringwald             if (current_call_index == -1){
417d210d9c4SMatthias Ringwald                 log_error("gsm: no active call");
418d210d9c4SMatthias Ringwald                 return;
419d210d9c4SMatthias Ringwald             }
42066a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE);
42174386ee0SMatthias Ringwald             break;
42274386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_ESTABLISHED:
42366a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
42466a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
42574386ee0SMatthias Ringwald             break;
426d210d9c4SMatthias Ringwald 
427d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL:
428d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS) break;
42966a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS);
4309cae807eSMatthias Ringwald             create_call(HFP_ENHANCED_CALL_DIR_INCOMING);
431d210d9c4SMatthias Ringwald             break;
432d210d9c4SMatthias Ringwald 
433d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG:
434d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
43566a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
436d210d9c4SMatthias Ringwald 
437d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){
43866a048abSMatthias Ringwald                 set_enhanced_call_status_held(current_call_index);
439d210d9c4SMatthias Ringwald             }
44066a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
441d210d9c4SMatthias Ringwald             break;
442d210d9c4SMatthias Ringwald 
443d210d9c4SMatthias Ringwald         case HFP_AG_HELD_CALL_JOINED_BY_AG:
444d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
445d210d9c4SMatthias Ringwald 
446d210d9c4SMatthias Ringwald             // TODO: is following condition correct? Can we join incoming call before it is answered?
447aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){
44866a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
44966a048abSMatthias Ringwald                 set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
4509cae807eSMatthias Ringwald             } else if (hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED) {
45166a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
452d210d9c4SMatthias Ringwald             }
453d210d9c4SMatthias Ringwald 
4549cae807eSMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
45566a048abSMatthias Ringwald                 if (is_enhanced_call_status_active(i)){
456aeb0f0feSMatthias Ringwald                     hfp_gsm_model_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
4579cae807eSMatthias Ringwald                 }
458d210d9c4SMatthias Ringwald             }
459d210d9c4SMatthias Ringwald             break;
460d210d9c4SMatthias Ringwald 
461d210d9c4SMatthias Ringwald         case HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF:
462d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
463d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break;
46466a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
46566a048abSMatthias Ringwald             set_enhanced_call_status_active(initiated_call_index);
466d210d9c4SMatthias Ringwald             break;
467d210d9c4SMatthias Ringwald 
468d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG:
469d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF:
470d210d9c4SMatthias Ringwald             if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
471d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break;
47266a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
47366a048abSMatthias Ringwald             set_enhanced_call_status_response_hold(initiated_call_index);
474d210d9c4SMatthias Ringwald             break;
475d210d9c4SMatthias Ringwald 
476d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG:
477d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF:
478d210d9c4SMatthias Ringwald             if (!hfp_gsm_response_held_active()) break;
47966a048abSMatthias Ringwald             set_enhanced_call_status_active(get_response_held_call_index());
480d210d9c4SMatthias Ringwald             break;
481d210d9c4SMatthias Ringwald 
482d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG:
483d210d9c4SMatthias Ringwald         case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF:
484d210d9c4SMatthias Ringwald             if (!hfp_gsm_response_held_active()) break;
485d0c20769SMatthias Ringwald             delete_call(get_response_held_call_index());
486d210d9c4SMatthias Ringwald             break;
487d210d9c4SMatthias Ringwald 
488d210d9c4SMatthias Ringwald 
489d210d9c4SMatthias Ringwald         case HFP_AG_TERMINATE_CALL_BY_HF:
490d210d9c4SMatthias Ringwald             switch (hfp_gsm_call_status()){
491d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
49266a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
493d210d9c4SMatthias Ringwald                     break;
494d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT:
495d0c20769SMatthias Ringwald                     delete_call(current_call_index);
496d210d9c4SMatthias Ringwald                     break;
4977bbeb3adSMilanka Ringwald                 default:
4987bbeb3adSMilanka Ringwald                     break;
499d210d9c4SMatthias Ringwald             }
500d210d9c4SMatthias Ringwald             break;
501d210d9c4SMatthias Ringwald 
502d210d9c4SMatthias Ringwald         case HFP_AG_TERMINATE_CALL_BY_AG:
503d210d9c4SMatthias Ringwald             switch (hfp_gsm_call_status()){
504d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
505d210d9c4SMatthias Ringwald                     if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break;
50666a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
507d210d9c4SMatthias Ringwald                     break;
508d210d9c4SMatthias Ringwald                 case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT:
50966a048abSMatthias Ringwald                     set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
510d0c20769SMatthias Ringwald                     delete_call(current_call_index);
511d210d9c4SMatthias Ringwald                     break;
512d210d9c4SMatthias Ringwald                 default:
513d210d9c4SMatthias Ringwald                     break;
514d210d9c4SMatthias Ringwald             }
515d210d9c4SMatthias Ringwald             break;
516d210d9c4SMatthias Ringwald 
517d0c20769SMatthias Ringwald         case HFP_AG_CALL_DROPPED:
51866a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
519d210d9c4SMatthias Ringwald             if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
520d210d9c4SMatthias Ringwald 
521d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
522d0c20769SMatthias Ringwald                 delete_call(i);
523d210d9c4SMatthias Ringwald             }
524d210d9c4SMatthias Ringwald             break;
525d0c20769SMatthias Ringwald 
526d210d9c4SMatthias Ringwald         case HFP_AG_CALL_HOLD_USER_BUSY:
527d210d9c4SMatthias Ringwald             // Held or waiting call gets active,
52866a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
52966a048abSMatthias Ringwald             free_call_slot(initiated_call_index);
53066a048abSMatthias Ringwald             set_enhanced_call_status_active(held_call_index);
531d210d9c4SMatthias Ringwald             break;
532d210d9c4SMatthias Ringwald 
533d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
534c1ab6cc1SMatthias Ringwald             if ((index != 0) && (index <= HFP_GSM_MAX_NR_CALLS) ){
535d0c20769SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
536aeb0f0feSMatthias Ringwald                     if (hfp_gsm_model_calls[i].index == index){
537d0c20769SMatthias Ringwald                         delete_call(i);
538d0c20769SMatthias Ringwald                         continue;
539d0c20769SMatthias Ringwald                     }
540d0c20769SMatthias Ringwald                 }
541d0c20769SMatthias Ringwald             } else {
542d210d9c4SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
54366a048abSMatthias Ringwald                     if (is_enhanced_call_status_active(i)){
544d0c20769SMatthias Ringwald                         delete_call(i);
545d0c20769SMatthias Ringwald                     }
546d210d9c4SMatthias Ringwald                 }
547d210d9c4SMatthias Ringwald             }
548d210d9c4SMatthias Ringwald 
549aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
55066a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
551d210d9c4SMatthias Ringwald             } else {
55266a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
553d210d9c4SMatthias Ringwald             }
554d0c20769SMatthias Ringwald 
55566a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
556d210d9c4SMatthias Ringwald             break;
557d0c20769SMatthias Ringwald 
558d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
559d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
560aeb0f0feSMatthias Ringwald                 if (is_enhanced_call_status_active(i) && (hfp_gsm_model_calls[i].index != index)){
56166a048abSMatthias Ringwald                     set_enhanced_call_status_held(i);
562d210d9c4SMatthias Ringwald                 }
563d210d9c4SMatthias Ringwald             }
564d210d9c4SMatthias Ringwald 
565aeb0f0feSMatthias Ringwald             if (hfp_gsm_model_callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
56666a048abSMatthias Ringwald                 set_enhanced_call_status_active(initiated_call_index);
567d210d9c4SMatthias Ringwald             } else {
56866a048abSMatthias Ringwald                 set_enhanced_call_status_active(held_call_index);
569d210d9c4SMatthias Ringwald             }
57066a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
571d210d9c4SMatthias Ringwald             break;
572d0c20769SMatthias Ringwald 
573d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_ADD_HELD_CALL:
574d210d9c4SMatthias Ringwald             if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){
575d210d9c4SMatthias Ringwald                 for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
576aeb0f0feSMatthias Ringwald                     if (hfp_gsm_model_calls[i].used_slot){
57766a048abSMatthias Ringwald                         set_enhanced_call_status_active(i);
578aeb0f0feSMatthias Ringwald                         hfp_gsm_model_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
579d210d9c4SMatthias Ringwald                     }
580d210d9c4SMatthias Ringwald                 }
581d210d9c4SMatthias Ringwald             }
582d210d9c4SMatthias Ringwald             break;
583d0c20769SMatthias Ringwald 
584d0c20769SMatthias Ringwald         case HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS:
585d210d9c4SMatthias Ringwald             for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
586d0c20769SMatthias Ringwald                 delete_call(i);
587d210d9c4SMatthias Ringwald             }
588d0c20769SMatthias Ringwald             break;
589d210d9c4SMatthias Ringwald 
590d0c20769SMatthias Ringwald         case HFP_AG_SET_CLIP:
591d0c20769SMatthias Ringwald             if (initiated_call_index != -1){
592d0c20769SMatthias Ringwald                 hfp_gsm_set_clip(initiated_call_index, type, number);
593d210d9c4SMatthias Ringwald                 break;
594d210d9c4SMatthias Ringwald             }
5959cae807eSMatthias Ringwald 
596aeb0f0feSMatthias Ringwald             hfp_gsm_model_clip_type = type;
597aeb0f0feSMatthias Ringwald             strncpy(hfp_gsm_model_clip_number, number, sizeof(hfp_gsm_model_clip_number));
598aeb0f0feSMatthias Ringwald             hfp_gsm_model_clip_number[sizeof(hfp_gsm_model_clip_number) - 1] = '\0';
599d0c20769SMatthias Ringwald 
600d0c20769SMatthias Ringwald             break;
60174386ee0SMatthias Ringwald         default:
60274386ee0SMatthias Ringwald             break;
60374386ee0SMatthias Ringwald     }
60474386ee0SMatthias Ringwald }
605