xref: /btstack/src/classic/hfp_gsm_model.c (revision aeb0f0fe93041a3b273682f6ea479d8717047afb)
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 
67*aeb0f0feSMatthias Ringwald static hfp_gsm_call_t         hfp_gsm_model_calls[HFP_GSM_MAX_NR_CALLS];
68*aeb0f0feSMatthias Ringwald static hfp_callsetup_status_t hfp_gsm_model_callsetup_status;
6974386ee0SMatthias Ringwald 
70*aeb0f0feSMatthias Ringwald static uint8_t hfp_gsm_model_clip_type;
71*aeb0f0feSMatthias Ringwald static char    hfp_gsm_model_clip_number[HFP_GSM_MAX_CALL_NUMBER_SIZE];
72*aeb0f0feSMatthias Ringwald static char    hfp_gsm_model_last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE];
73d0c20769SMatthias Ringwald 
74*aeb0f0feSMatthias 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){
77*aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = status;
78*aeb0f0feSMatthias 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++){
82*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[i].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){
83*aeb0f0feSMatthias 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;
90*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE;
91*aeb0f0feSMatthias 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;
96*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD;
97*aeb0f0feSMatthias 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;
102*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD;
103*aeb0f0feSMatthias 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;
108*aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){
109*aeb0f0feSMatthias Ringwald         hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING;
11066a048abSMatthias Ringwald     } else {
111*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_get_number_active_calls() > 0){
112*aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING;
11366a048abSMatthias Ringwald         } else {
114*aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING;
11566a048abSMatthias Ringwald         }
11666a048abSMatthias Ringwald     }
117*aeb0f0feSMatthias 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;
122*aeb0f0feSMatthias Ringwald     if (!hfp_gsm_model_calls[index_in_table].used_slot) return -1;
123*aeb0f0feSMatthias 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*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].used_slot = 0;
14766a048abSMatthias Ringwald }
148d0c20769SMatthias Ringwald 
149d210d9c4SMatthias Ringwald void hfp_gsm_init(void){
150*aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
151*aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
152*aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
153*aeb0f0feSMatthias Ringwald     memset(hfp_gsm_model_last_dialed_number, 0, sizeof(hfp_gsm_model_last_dialed_number));
154*aeb0f0feSMatthias 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){
162*aeb0f0feSMatthias Ringwald     (void) memset(hfp_gsm_model_calls, 0, sizeof(hfp_gsm_model_calls));
163*aeb0f0feSMatthias Ringwald     hfp_gsm_model_callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
164*aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
165*aeb0f0feSMatthias Ringwald     (void) memset(hfp_gsm_model_clip_number, 0, sizeof(hfp_gsm_model_clip_number));
166*aeb0f0feSMatthias 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++){
196*aeb0f0feSMatthias 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 
2059cae807eSMatthias Ringwald static inline int get_held_call_index(void){
20666a048abSMatthias Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD);
207d210d9c4SMatthias Ringwald }
208d210d9c4SMatthias Ringwald 
2099cae807eSMatthias Ringwald static inline int get_response_held_call_index(void){
21066a048abSMatthias Ringwald     return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD);
211d210d9c4SMatthias Ringwald }
212d210d9c4SMatthias Ringwald 
2139cae807eSMatthias Ringwald static inline int get_number_none_calls(void){
21466a048abSMatthias Ringwald     int i, count = 0;
21566a048abSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
216*aeb0f0feSMatthias Ringwald         if (!hfp_gsm_model_calls[i].used_slot) count++;
21766a048abSMatthias Ringwald     }
21866a048abSMatthias Ringwald     return count;
219d210d9c4SMatthias Ringwald }
22074386ee0SMatthias Ringwald 
221*aeb0f0feSMatthias Ringwald static inline int hfp_gsm_model_get_number_active_calls(void){
22266a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_ACTIVE);
22374386ee0SMatthias Ringwald }
22474386ee0SMatthias Ringwald 
2259cae807eSMatthias Ringwald static inline int get_number_held_calls(void){
22666a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD);
22774386ee0SMatthias Ringwald }
22874386ee0SMatthias Ringwald 
2299cae807eSMatthias Ringwald static inline int get_number_response_held_calls(void){
23066a048abSMatthias Ringwald     return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD);
231d210d9c4SMatthias Ringwald }
232d210d9c4SMatthias Ringwald 
2339cae807eSMatthias Ringwald static int next_call_index(void){
234d0c20769SMatthias Ringwald     return HFP_GSM_MAX_NR_CALLS + 1 - get_number_none_calls();
235d0c20769SMatthias Ringwald }
236d0c20769SMatthias Ringwald 
237d0c20769SMatthias Ringwald static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * number){
23821791470SMilanka Ringwald     uint16_t number_str_len = (uint16_t) strlen(number);
23921791470SMilanka Ringwald     if (number_str_len == 0) return;
2409cae807eSMatthias Ringwald 
241*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].clip_type = type;
24221791470SMilanka Ringwald     int clip_number_size = btstack_min(number_str_len, HFP_GSM_MAX_CALL_NUMBER_SIZE - 1);
243*aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_calls[index_in_table].clip_number, number, clip_number_size);
244*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[index_in_table].clip_number[clip_number_size] = '\0';
245*aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_last_dialed_number, number, clip_number_size);
246*aeb0f0feSMatthias Ringwald     hfp_gsm_model_last_dialed_number[clip_number_size] = '\0';
2479cae807eSMatthias Ringwald 
248*aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_type = 0;
249*aeb0f0feSMatthias 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++){
255*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[i].index > hfp_gsm_model_calls[delete_index_in_table].index){
256*aeb0f0feSMatthias Ringwald             hfp_gsm_model_calls[i].index--;
257d0c20769SMatthias Ringwald         }
258d0c20769SMatthias Ringwald     }
25966a048abSMatthias Ringwald     free_call_slot(delete_index_in_table);
260d0c20769SMatthias Ringwald 
261*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_type = 0;
262*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].index = 0;
263*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[delete_index_in_table].clip_number[0] = '\0';
264*aeb0f0feSMatthias 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();
270*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].direction = direction;
271*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].index = next_call_index();
27266a048abSMatthias Ringwald     set_enhanced_call_status_initiated(next_free_slot);
273*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_type = 0;
274*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].clip_number[0] = '\0';
275*aeb0f0feSMatthias Ringwald     hfp_gsm_model_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
276d0c20769SMatthias Ringwald 
277*aeb0f0feSMatthias 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){
286*aeb0f0feSMatthias 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){
290*aeb0f0feSMatthias 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){
294*aeb0f0feSMatthias Ringwald     strncpy(hfp_gsm_model_last_dialed_number, number, sizeof(hfp_gsm_model_last_dialed_number));
295*aeb0f0feSMatthias Ringwald     hfp_gsm_model_last_dialed_number[sizeof(hfp_gsm_model_last_dialed_number) - 1] = 0;
2969de679b7SMilanka Ringwald }
2979de679b7SMilanka Ringwald 
2989cae807eSMatthias Ringwald hfp_gsm_call_t * hfp_gsm_call(int call_index){
2999cae807eSMatthias Ringwald     int i;
3009cae807eSMatthias Ringwald 
3019cae807eSMatthias Ringwald     for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
302*aeb0f0feSMatthias Ringwald         hfp_gsm_call_t * call = &hfp_gsm_model_calls[i];
3039cae807eSMatthias Ringwald         if (call->index != call_index) continue;
3049cae807eSMatthias Ringwald         return call;
3059cae807eSMatthias Ringwald     }
3069cae807eSMatthias Ringwald     return NULL;
3079cae807eSMatthias Ringwald }
3089cae807eSMatthias Ringwald 
3099cae807eSMatthias Ringwald uint8_t hfp_gsm_clip_type(void){
310*aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_clip_type != 0) return hfp_gsm_model_clip_type;
311d0c20769SMatthias Ringwald 
312d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
313d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
314*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
315*aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_type;
316d0c20769SMatthias Ringwald         }
317d0c20769SMatthias Ringwald     }
318d0c20769SMatthias Ringwald 
319d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
320d0c20769SMatthias Ringwald     if (active_call_index != -1){
321*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
322*aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_type;
323d0c20769SMatthias Ringwald         }
324d0c20769SMatthias Ringwald     }
325d0c20769SMatthias Ringwald     return 0;
326d0c20769SMatthias Ringwald }
327d0c20769SMatthias Ringwald 
3289cae807eSMatthias Ringwald char *  hfp_gsm_clip_number(void){
329*aeb0f0feSMatthias Ringwald     if (strlen(hfp_gsm_model_clip_number) != 0) return hfp_gsm_model_clip_number;
330d0c20769SMatthias Ringwald 
331d0c20769SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
332d0c20769SMatthias Ringwald     if (initiated_call_index != -1){
333*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[initiated_call_index].clip_type != 0) {
334*aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[initiated_call_index].clip_number;
335d0c20769SMatthias Ringwald         }
336d0c20769SMatthias Ringwald     }
337d0c20769SMatthias Ringwald 
338d0c20769SMatthias Ringwald     int active_call_index = get_active_call_index();
339d0c20769SMatthias Ringwald     if (active_call_index != -1){
340*aeb0f0feSMatthias Ringwald         if (hfp_gsm_model_calls[active_call_index].clip_type != 0) {
341*aeb0f0feSMatthias Ringwald             return hfp_gsm_model_calls[active_call_index].clip_number;
342d0c20769SMatthias Ringwald         }
343d0c20769SMatthias Ringwald     }
344*aeb0f0feSMatthias Ringwald     hfp_gsm_model_clip_number[0] = 0;
345*aeb0f0feSMatthias Ringwald     return hfp_gsm_model_clip_number;
346d0c20769SMatthias Ringwald }
347d0c20769SMatthias Ringwald 
3489cae807eSMatthias Ringwald hfp_call_status_t hfp_gsm_call_status(void){
349*aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() + get_number_held_calls() + get_number_response_held_calls()){
35074386ee0SMatthias Ringwald         return HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT;
35174386ee0SMatthias Ringwald     }
35274386ee0SMatthias Ringwald     return HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS;
35374386ee0SMatthias Ringwald }
35474386ee0SMatthias Ringwald 
3559cae807eSMatthias Ringwald hfp_callheld_status_t hfp_gsm_callheld_status(void){
35674386ee0SMatthias Ringwald     // @note: order is important
35774386ee0SMatthias Ringwald     if (get_number_held_calls() == 0){
35874386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_NO_CALLS_HELD;
35974386ee0SMatthias Ringwald     }
360*aeb0f0feSMatthias Ringwald     if (hfp_gsm_model_get_number_active_calls() == 0) {
36174386ee0SMatthias Ringwald         return HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS;
36274386ee0SMatthias Ringwald     }
36374386ee0SMatthias Ringwald     return HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED;
36474386ee0SMatthias Ringwald }
36574386ee0SMatthias Ringwald 
3669cae807eSMatthias Ringwald hfp_callsetup_status_t hfp_gsm_callsetup_status(void){
367*aeb0f0feSMatthias Ringwald     return hfp_gsm_model_callsetup_status;
36874386ee0SMatthias Ringwald }
36974386ee0SMatthias Ringwald 
3709cae807eSMatthias Ringwald static int hfp_gsm_response_held_active(void){
371d210d9c4SMatthias Ringwald     return get_response_held_call_index() != -1 ;
372d210d9c4SMatthias Ringwald }
373d210d9c4SMatthias Ringwald 
374d210d9c4SMatthias Ringwald int hfp_gsm_call_possible(void){
375d210d9c4SMatthias Ringwald     return get_number_none_calls() > 0;
376d210d9c4SMatthias Ringwald }
377d210d9c4SMatthias Ringwald 
378f8737b81SMatthias Ringwald void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number){
379d0c20769SMatthias Ringwald     int next_free_slot = get_next_free_slot();
38074386ee0SMatthias Ringwald     int current_call_index = get_active_call_index();
381d210d9c4SMatthias Ringwald     int initiated_call_index = get_initiated_call_index();
382d210d9c4SMatthias Ringwald     int held_call_index = get_held_call_index();
383d0c20769SMatthias Ringwald     int i;
384d0c20769SMatthias Ringwald 
38574386ee0SMatthias Ringwald     switch (event){
3869ff73f41SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_HF:
387fe899794SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_INITIATED_BY_AG:
38874386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_REDIAL_INITIATED:
38974386ee0SMatthias Ringwald             if (next_free_slot == -1){
390d210d9c4SMatthias Ringwald                 log_error("gsm: max call nr exceeded");
39174386ee0SMatthias Ringwald                 return;
39274386ee0SMatthias Ringwald             }
3939cae807eSMatthias Ringwald             create_call(HFP_ENHANCED_CALL_DIR_OUTGOING);
394d210d9c4SMatthias Ringwald             break;
39574386ee0SMatthias Ringwald 
396d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_REJECTED:
397d210d9c4SMatthias Ringwald             if (current_call_index != -1){
398d0c20769SMatthias Ringwald                 delete_call(current_call_index);
399d210d9c4SMatthias Ringwald             }
40066a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
401d210d9c4SMatthias Ringwald             break;
402d210d9c4SMatthias Ringwald 
403d210d9c4SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_ACCEPTED:
40474386ee0SMatthias Ringwald             if (current_call_index != -1){
40566a048abSMatthias Ringwald                 set_enhanced_call_status_held(current_call_index);
40674386ee0SMatthias Ringwald             }
40766a048abSMatthias Ringwald             set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE);
40874386ee0SMatthias Ringwald             break;
409d210d9c4SMatthias Ringwald 
41074386ee0SMatthias Ringwald         case HFP_AG_OUTGOING_CALL_RINGING:
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?
442*aeb0f0feSMatthias 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)){
451*aeb0f0feSMatthias 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++){
531*aeb0f0feSMatthias 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 
544*aeb0f0feSMatthias 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++){
555*aeb0f0feSMatthias 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 
560*aeb0f0feSMatthias 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++){
571*aeb0f0feSMatthias Ringwald                     if (hfp_gsm_model_calls[i].used_slot){
57266a048abSMatthias Ringwald                         set_enhanced_call_status_active(i);
573*aeb0f0feSMatthias 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 
591*aeb0f0feSMatthias Ringwald             hfp_gsm_model_clip_type = type;
592*aeb0f0feSMatthias Ringwald             strncpy(hfp_gsm_model_clip_number, number, sizeof(hfp_gsm_model_clip_number));
593*aeb0f0feSMatthias Ringwald             hfp_gsm_model_clip_number[sizeof(hfp_gsm_model_clip_number) - 1] = '\0';
594d0c20769SMatthias Ringwald 
595d0c20769SMatthias Ringwald             break;
59674386ee0SMatthias Ringwald         default:
59774386ee0SMatthias Ringwald             break;
59874386ee0SMatthias Ringwald     }
59974386ee0SMatthias Ringwald }
600