comparison src/g23m-aci/aci/dcm_utils.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : DCM and TCPIP
4 | Modul : ACI
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Description : This file contains Useful DCM (Data connection manager)functions.
18 +-----------------------------------------------------------------------------
19 */
20
21 /************************************ INCLUDES ********************************************/
22 #include "aci_all.h"
23
24 #include "aci.h"
25 #include "aci_cmh.h"
26 #include "Gaci_cmh.h"
27 #include "dcm.h"
28 #include "dcm_utils.h"
29 #include "dcm_state.h"
30 #include "dcm_env.h"
31 #include "dcm_f.h"
32 #include "psa_dcm.h"
33 #include "socket_api.h"
34
35 #include "wap_aci.h"
36
37 /**************************** LOCAL VARIABLE DEFINITION ************************************/
38
39 /**************************** EXTERN VARIABLE DEFINITION ***********************************/
40 EXTERN T_DCM_ENV_CTRL_BLK *dcm_env_ctrl_blk_p;
41
42
43 /**************************** LOCAL FUCNTION DEFINITION ************************************/
44 LOCAL T_DCM_RET dcm_send_cgdcont_get_cmd(U8 row);
45 LOCAL T_DCM_RET dcm_send_cgdcont_cmd(U8 row);
46 LOCAL T_DCM_RET dcm_send_cgatt_cmd(U8 row);
47 LOCAL T_DCM_RET dcm_send_cgdeact_cmd(U8 row);
48 LOCAL T_DCM_RET dcm_send_cgpco_auth_cmd(U8 row);
49 LOCAL T_DCM_RET dcm_send_cgpco_get_cmd(U8 row);
50 LOCAL T_DCM_RET dcm_send_cgerep_cmd(U8 row);
51 LOCAL T_DCM_RET dcm_send_cgpaddr_cmd(U8 current_row);
52 LOCAL T_DCM_RET dcm_send_percentppp_cmd(U8 row);
53 LOCAL T_DCM_RET dcm_send_sat_dn_cmd(U8 row);
54 LOCAL T_DCM_RET dcm_send_percentppp_get_cmd(U8 row);
55 LOCAL T_DCM_RET dcm_send_percentcal_get_cmd(UBYTE row);
56 LOCAL T_DCM_RET dcm_send_sat_abort_cmd(U8 row);
57
58 LOCAL ULONG dcm_ipaddr_htonl(ULONG horder_ipaddr);
59
60 LOCAL void set_state_from_ctrl_blk();
61
62 /************************** EXTERN FUCNTION DEFINITION *********************************/
63 EXTERN T_DCM_RET dcm_handle_message (T_DCM_HDR *msg_p);
64 EXTERN void psaTCPIP_Shutdown_Req(void);
65
66
67 BOOL is_netdrop = FALSE ; //pinghua added patch for DCM open/close
68
69 /***************************************************************************************
70 * Function : dcm_process_unwaited_events_state_intermediate_conn
71 * Parameter : T_DCM_HDR *
72 * -Pointer on the header of the message.
73 * Return : T_DCM_RET
74 * DCM_OK or DCM errors
75 * Description : Function used in all intermediate states where events is unwaited,
76 * but must be processed.
77 ***************************************************************************************/
78 T_DCM_RET dcm_process_unwaited_events_state_intermediate_conn(T_DCM_HDR * msg_p)
79 {
80 T_DCM_OPEN_CONN_REQ_MSG * dcm_open_conn_req_msg_p;
81 T_DCM_CLOSE_CONN_REQ_MSG * dcm_close_conn_req_msg_p;
82
83 TRACE_FUNCTION("DCM: dcm_process_unwaited_events_state_intermediate_conn()");
84
85 switch(msg_p->msg_id)
86 {
87 case DCM_ERROR_IND_MSG:
88 return dcm_process_event_error_reception(msg_p);
89 /*lint -e527 suppress Warning -- Unreachable */
90 /* break is removed ,as case is returning before break so it is not needed */
91 /*lint +e527 */
92 case DCM_OPEN_CONN_REQ_MSG:
93 dcm_open_conn_req_msg_p = (T_DCM_OPEN_CONN_REQ_MSG*)msg_p;
94 psaDCM_open_conn_cnf(DCM_BUSY,
95 dcm_open_conn_req_msg_p->conn_req.api_instance);
96 return (DCM_BUSY); /* It is replaced with return in next line to avoid warning */
97 /*lint -e527 suppress Warning -- Unreachable */
98 /* break is removed ,as case is returning before break so it is not needed */
99 /*lint +e527 */
100 case DCM_CLOSE_CONN_REQ_MSG:
101 dcm_close_conn_req_msg_p = (T_DCM_CLOSE_CONN_REQ_MSG*)msg_p;
102 /* DCM CLOSE REQ have to be accepted in ACTVATING STATE */
103 if(dcm_env_ctrl_blk_p->state[0] EQ DCM_ACTIVATING_CONN)
104 {
105 dcm_process_close_conn_event(dcm_close_conn_req_msg_p);
106 }
107 else
108 {
109 psaDCM_close_conn_cnf(DCM_BUSY,
110 dcm_close_conn_req_msg_p->close_req.api_instance);
111 }
112 return DCM_OK;
113 /*lint -e527 suppress Warning -- Unreachable */
114 /* break is removed ,as case is returning before break so it is not needed */
115 /*lint +e527 */
116 default:
117 /* Ignore event - Stay in the same state. */
118 return DCM_UNKNOWN_EVENT;
119 }
120 }
121
122
123 /*
124 * Function used to close a connection (with PS and later with api_instance)
125 *
126 * The closing is always on demand of the IPU_id, or may be internally launched.
127 * The closing of the connection begin by the closing of the port with the PS.
128 * - Close the connection with the PS.
129 *
130 * @param T_DCM_CLOSE_CONN_REQ_MSG*
131 * @return DCM_OK or DCM errors
132 */
133 /***************************************************************************************
134 * Function : dcm_process_close_conn_event
135 * Parameter : T_APPLI_USER
136 * -Pointer on the header of the message.
137 * Return : T_DCM_RET
138 * DCM_OK or DCM errors
139 * Description : Function used in all intermediate states where events is unwaited,
140 * but must be processed.
141 ***************************************************************************************/
142 T_DCM_RET dcm_process_close_conn_event(T_DCM_CLOSE_CONN_REQ_MSG *close_conn_p )
143 {
144 U8 i;
145 U8 current_bearer_count;
146 //pinghua DCM_OPEN_CLOSE patch 20080429 start
147 T_P_CGREG_STAT status = (T_P_CGREG_STAT)0;
148 USHORT lac, ci;
149
150
151 TRACE_FUNCTION("DCM: dcm_process_close_conn_event()");
152
153 qAT_PercentCGREG(CMD_SRC_LCL, &status, &lac, &ci);
154 TRACE_EVENT_P1("NOW NET STATA is %d", status);
155 if(status>=P_CGREG_STAT_LIMITED )
156 {
157 psaDCM_close_conn_cnf(DCM_NO_NETWORK, close_conn_p->close_req.api_instance);
158 return DCM_NO_NETWORK;
159
160 }
161 // pinghua DCM_OPEN_CLOSE patch 20080429 end
162
163 for (i=0; i < DCM_MAX_NUMBER_IPU; i++)
164 {
165 if( (dcm_env_ctrl_blk_p->ipu_list[i].api_instance EQ
166 close_conn_p->close_req.api_instance) AND
167 (dcm_env_ctrl_blk_p->ipu_list[i].row_state) )
168 {
169 if(dcm_env_ctrl_blk_p->ipu_list[i].bearer_type EQ DCM_BEARER_GPRS)
170 {
171 current_bearer_count = dcm_env_ctrl_blk_p->gprs_current_total_row;
172 }
173 else
174 {
175 current_bearer_count = dcm_env_ctrl_blk_p->gsm_current_total_row;
176 }
177 /* raise the flag that indicates a disconnection */
178 dcm_env_ctrl_blk_p->ipu_list[i].row_state = ROW_CLOSING;
179 dcm_new_state(DCM_CLOSING_CONN , DCM_SUB_NO_ACTION);
180
181 if(current_bearer_count EQ 1)
182 {
183 if(dcm_env_ctrl_blk_p->ipu_list[i].bearer_type EQ DCM_BEARER_GPRS)
184 {
185 dcm_send_cgdeact_cmd(i);
186 }
187 else
188 {
189 dcm_send_percentcal_get_cmd(i);
190 }
191 }
192 else
193 {
194 psaDCM_close_conn_cnf(DCM_OK,close_conn_p->close_req.api_instance);
195 /* free the row used */
196 dcm_free_row(i);
197 set_state_from_ctrl_blk();
198 }
199 }
200 }
201 return DCM_OK;
202 }
203
204 // pinghua DCM_OPEN_CLOSE patch 20080429 start here
205 T_DCM_RET dcm_process_network_drop(T_DCM_CLOSE_CONN_REQ_MSG *close_conn_p )
206 {
207 U8 i;
208 U8 current_bearer_count;
209
210
211 TRACE_FUNCTION("DCM: dcm_process_network_drop()");
212
213 for (i=0; i < DCM_MAX_NUMBER_IPU; i++)
214 {
215 if( (dcm_env_ctrl_blk_p->ipu_list[i].api_instance EQ
216 close_conn_p->close_req.api_instance) AND
217 (dcm_env_ctrl_blk_p->ipu_list[i].row_state) )
218 {
219 if(dcm_env_ctrl_blk_p->ipu_list[i].bearer_type EQ DCM_BEARER_GPRS)
220 {
221 current_bearer_count = dcm_env_ctrl_blk_p->gprs_current_total_row;
222 }
223 else
224 {
225 current_bearer_count = dcm_env_ctrl_blk_p->gsm_current_total_row;
226 }
227 /* raise the flag that indicates a disconnection */
228 dcm_env_ctrl_blk_p->ipu_list[i].row_state = ROW_CLOSING;
229 dcm_new_state(DCM_CLOSING_CONN , DCM_SUB_NO_ACTION);
230
231 if(current_bearer_count EQ 1)
232 {
233 if(dcm_env_ctrl_blk_p->ipu_list[i].bearer_type EQ DCM_BEARER_GPRS)
234 {
235 dcm_send_cgdeact_cmd(i);
236 is_netdrop = TRUE ; // pinghua added DCM_OPEN_CLOSE patch
237 }
238 else
239 {
240 dcm_send_percentcal_get_cmd(i);
241 }
242 }
243 else
244 {
245 psaDCM_close_conn_cnf(DCM_OK,close_conn_p->close_req.api_instance);
246 /* free the row used */
247 dcm_free_row(i);
248 set_state_from_ctrl_blk();
249 }
250 }
251 }
252 return DCM_OK;
253 }
254 //pinghua DCM_OPEN_CLOSE patch 20080429 end
255
256 /*******************************************************************************
257 * Function used to open a connection (with PS)
258 *
259 * The opening is always on demand of the IPU_id.
260 * - Open the connection with the PS.
261 *
262 * @return DCM_OK or DCM errors
263 *******************************************************************************/
264
265 EXTERN T_ACI_WAP_STATES wap_state;
266 T_DCM_RET dcm_process_open_conn_event(T_DCM_OPEN_CONN_REQ_MSG *open_conn_p)
267 {
268 U8 row_id, row_id_free;
269 // pinghua DCM_OPEN_CLOSE patch 20080429 start
270 T_P_CGREG_STAT status = (T_P_CGREG_STAT)0;
271 USHORT lac, ci;
272 TRACE_FUNCTION("DCM: dcm_process_open_conn_event()");
273
274
275 qAT_PercentCGREG(CMD_SRC_LCL, &status, &lac, &ci);
276 TRACE_EVENT_P1("NOW NET STATA is %d", status);
277 if(status>=P_CGREG_STAT_LIMITED )
278 {
279 psaDCM_open_conn_cnf(DCM_NO_NETWORK, open_conn_p->conn_req.api_instance);
280 return DCM_NO_NETWORK;
281
282 }
283 if( wap_state != Wap_Not_Init )
284 {
285 // if(dcm_env_ctrl_blk_p->state[0]==DCM_CONN_ACTIVATED ||
286 // dcm_env_ctrl_blk_p->state[0]==DCM_CLOSING_CONN || dcm_env_ctrl_blk_p->state[0] ==DCM_ACTIVATING_CONN )
287 {
288 psaDCM_open_conn_cnf(DCM_NOT_READY, open_conn_p->conn_req.api_instance);
289 return DCM_NOT_READY;
290 }
291
292 }
293
294 // pinghua DCM_OPEN_CLOSE patch 20080429 end
295
296
297 /* check if the max number of IPU is reached */
298 if (( dcm_env_ctrl_blk_p->gsm_current_total_row +
299 dcm_env_ctrl_blk_p->gprs_current_total_row ) >= DCM_MAX_NUMBER_IPU )
300 {
301 /* Too many IPU_id opened */
302 /* send the negative confirmation to the IPU */
303 psaDCM_open_conn_cnf(DCM_NOT_READY,
304 open_conn_p->conn_req.api_instance);
305 return (DCM_NOT_READY); /* It is replaced with return in next line to avoid warning */
306 }
307
308 /* if possible, get the next row */
309 for (row_id = 0, row_id_free = DCM_MAX_NUMBER_IPU; row_id < DCM_MAX_NUMBER_IPU; row_id++)
310 {
311 if (dcm_env_ctrl_blk_p->ipu_list[row_id].row_state)
312 {
313 /* send a negative confirmation whether the IPU already exists */
314 if (dcm_env_ctrl_blk_p->ipu_list[row_id].api_instance EQ
315 open_conn_p->conn_req.api_instance)
316 {
317 /* send the negative confirmation to the IPU */
318 psaDCM_open_conn_cnf(DCM_ALREADY_ACTIVATED,
319 open_conn_p->conn_req.api_instance);
320 return( DCM_ALREADY_ACTIVATED ); /* It is replaced with return in next line to avoid warning */
321 }
322 }
323 else
324 {
325 /* get the first entry */
326 if (row_id_free EQ DCM_MAX_NUMBER_IPU)
327 {
328 row_id_free = row_id;
329 }
330 }
331 }
332
333 if (row_id_free EQ DCM_MAX_NUMBER_IPU)
334 {
335 /* send the negative confirmation to the IPU */
336 psaDCM_open_conn_cnf(DCM_NOT_READY,
337 open_conn_p->conn_req.api_instance);
338 return( DCM_NOT_READY ); /* It is replaced with return in next line to avoid warning */
339 }
340 /* Check the bearer type */
341 /* check best one bearer */
342 if(open_conn_p->conn_req.bearer_select EQ DCM_BEARER_ANY)
343 {
344 T_CGATT_STATE cgatt_state;
345 qAT_PlusCGATT(CMD_SRC_LCL,&cgatt_state);
346
347 if(cgatt_state EQ CGATT_STATE_ATTACHED)
348 open_conn_p->conn_req.bearer_select = DCM_BEARER_GPRS;
349 else
350 open_conn_p->conn_req.bearer_select = DCM_BEARER_GSM;
351 }
352
353 /* If application doesn't give any connection parameters than use default */
354 if(open_conn_p->conn_req.bearer_select EQ DCM_BEARER_GSM OR
355 open_conn_p->conn_req.bearer_select EQ DCM_BEARER_GPRS)
356 {
357 psaDCM_open_conn_cnf(DCM_INVALID_PARAMETER,open_conn_p->conn_req.api_instance);
358 return DCM_INVALID_PARAMETER;
359 }
360
361 /* If application gives the necessary parameters for a connection use these */
362 else if(open_conn_p->conn_req.bearer_select EQ DCM_BEARER_AS_SPECIFIED)
363 {
364 dcm_env_ctrl_blk_p->ipu_list[row_id_free].bearer_handle =
365 open_conn_p->conn_req.dcm_info_conn.bearer_handle;
366 dcm_env_ctrl_blk_p->ipu_list[row_id_free].app_handle =
367 open_conn_p->conn_req.dcm_info_conn.app_handle;
368 dcm_env_ctrl_blk_p->ipu_list[row_id_free].bearer_type =
369 open_conn_p->conn_req.dcm_info_conn.bearer_type;
370 dcm_env_ctrl_blk_p->ipu_list[row_id_free].apn_valid =
371 open_conn_p->conn_req.dcm_info_conn.apn_valid;
372 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].apn_valid)
373 {
374 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].apn,
375 (char*)open_conn_p->conn_req.dcm_info_conn.apn);
376 }
377 else
378 {
379 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].apn,"");
380 }
381 dcm_env_ctrl_blk_p->ipu_list[row_id_free].phone_number_valid =
382 open_conn_p->conn_req.dcm_info_conn.phone_number_valid;
383 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].phone_number_valid)
384 {
385 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].phone_number,
386 (char*)open_conn_p->conn_req.dcm_info_conn.phone_number);
387 }
388 else
389 {
390 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].phone_number,"");
391 }
392 dcm_env_ctrl_blk_p->ipu_list[row_id_free].user_id_valid =
393 open_conn_p->conn_req.dcm_info_conn.user_id_valid;
394 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].user_id_valid)
395 {
396 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].user_id,
397 (char*)open_conn_p->conn_req.dcm_info_conn.user_id);
398 }
399 else
400 {
401 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].user_id,"");
402 }
403 dcm_env_ctrl_blk_p->ipu_list[row_id_free].password_valid =
404 open_conn_p->conn_req.dcm_info_conn.password_valid;
405 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].password_valid)
406 {
407 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].password,
408 (char*)open_conn_p->conn_req.dcm_info_conn.password);
409 }
410 else
411 {
412 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row_id_free].password,"");
413 }
414 dcm_env_ctrl_blk_p->ipu_list[row_id_free].cid = open_conn_p->conn_req.dcm_info_conn.cid;
415 dcm_env_ctrl_blk_p->ipu_list[row_id_free].ip_address = open_conn_p->conn_req.dcm_info_conn.ip_address;
416 dcm_env_ctrl_blk_p->ipu_list[row_id_free].dns1 = open_conn_p->conn_req.dcm_info_conn.dns1;
417 dcm_env_ctrl_blk_p->ipu_list[row_id_free].dns2 = open_conn_p->conn_req.dcm_info_conn.dns2;
418 dcm_env_ctrl_blk_p->ipu_list[row_id_free].gateway = open_conn_p->conn_req.dcm_info_conn.gateway;
419 dcm_env_ctrl_blk_p->ipu_list[row_id_free].auth_type = open_conn_p->conn_req.dcm_info_conn.auth_type;
420 dcm_env_ctrl_blk_p->ipu_list[row_id_free].data_compr = open_conn_p->conn_req.dcm_info_conn.data_compr;
421 dcm_env_ctrl_blk_p->ipu_list[row_id_free].header_compr = open_conn_p->conn_req.dcm_info_conn.header_compr;
422 dcm_env_ctrl_blk_p->ipu_list[row_id_free].precedence = open_conn_p->conn_req.dcm_info_conn.precedence;
423 dcm_env_ctrl_blk_p->ipu_list[row_id_free].delay = open_conn_p->conn_req.dcm_info_conn.delay;
424 dcm_env_ctrl_blk_p->ipu_list[row_id_free].reliability = open_conn_p->conn_req.dcm_info_conn.reliability;
425 dcm_env_ctrl_blk_p->ipu_list[row_id_free].peak_throughput = open_conn_p->conn_req.dcm_info_conn.peak_throughput;
426 dcm_env_ctrl_blk_p->ipu_list[row_id_free].mean_throughput = open_conn_p->conn_req.dcm_info_conn.mean_throughput;
427 dcm_env_ctrl_blk_p->ipu_list[row_id_free].shareable = open_conn_p->conn_req.dcm_info_conn.shareable;
428 }
429
430 dcm_env_ctrl_blk_p->ipu_list[row_id_free].api_instance =
431 open_conn_p->conn_req.api_instance;
432
433 /* keep the curretn row */
434 dcm_env_ctrl_blk_p->current_row = row_id_free;
435
436 /* mark the row as used */
437 dcm_env_ctrl_blk_p->ipu_list[row_id_free].row_state = ROW_ASSIGNED;
438
439 /* sum the total of actual rows */
440 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].bearer_type EQ DCM_BEARER_GPRS)
441 {
442 dcm_env_ctrl_blk_p->gprs_current_total_row++;
443 }
444 else
445 {
446 dcm_env_ctrl_blk_p->gsm_current_total_row++;
447 }
448
449 if(dcm_env_ctrl_blk_p->gprs_current_total_row > 1 OR
450 dcm_env_ctrl_blk_p->gsm_current_total_row > 1)
451 {
452 psaDCM_open_conn_cnf(DCM_ALREADY_ACTIVATED,open_conn_p->conn_req.api_instance);
453 return DCM_ALREADY_ACTIVATED;
454 }
455
456 set_gpf_tcpip_call();
457
458 /* DCM state change */
459 dcm_new_state(DCM_ACTIVATING_CONN,DCM_SUB_NO_ACTION);
460
461 /* if GPRS: send first GPRS AT Command qAT_CGDCONT */
462 if(dcm_env_ctrl_blk_p->ipu_list[row_id_free].bearer_type EQ DCM_BEARER_GPRS)
463 {
464 dcm_send_cgdcont_get_cmd(dcm_env_ctrl_blk_p->current_row);
465 }
466 else /*send first GSM AT Command sAT_PercentPPP */
467 {
468 dcm_send_percentppp_cmd(dcm_env_ctrl_blk_p->current_row);
469 }
470
471 return DCM_OK;
472 }
473
474
475 /******************************************************************************/
476 T_DCM_RET dcm_process_get_current_conn_event(T_DCM_GET_CURRENT_CONN_REQ_MSG *current_conn_p)
477 {
478 TRACE_FUNCTION("DCM: dcm_process_get_current_conn_event()");
479
480 if(dcm_env_ctrl_blk_p->ipu_list[dcm_env_ctrl_blk_p->current_row].row_state EQ
481 ROW_ASSIGNED) {
482 psaDCM_get_current_conn_cnf(DCM_OK,
483 current_conn_p->current_conn_req.api_instance,
484 dcm_env_ctrl_blk_p);
485 }
486 else {
487 psaDCM_get_current_conn_cnf(DCM_NOT_READY,
488 current_conn_p->current_conn_req.api_instance,
489 dcm_env_ctrl_blk_p);
490 }
491 return DCM_OK;
492 }
493
494
495 /******************************************************************************/
496 T_DCM_RET dcm_process_unknown_event_in_idle(T_DCM_HDR* msg_p)
497 {
498 T_DCM_CLOSE_CONN_REQ_MSG *close_conn_req_p;
499 T_DCM_RET ret;
500
501 TRACE_FUNCTION("DCM: dcm_process_unknown_event_in_idle()");
502
503 if(msg_p EQ NULL)
504 return DCM_INVALID_PARAMETER;
505
506 switch(msg_p->msg_id)
507 {
508 case DCM_CLOSE_CONN_REQ_MSG :
509 close_conn_req_p =(T_DCM_CLOSE_CONN_REQ_MSG *)msg_p;
510 psaDCM_close_conn_cnf(DCM_UNKNOWN_EVENT,
511 close_conn_req_p->close_req.api_instance);
512 set_state_from_ctrl_blk();
513 ret = DCM_OK;
514 break;
515 default:
516 ret = DCM_UNKNOWN_EVENT;
517 break;
518 }
519 return ret;
520 }
521
522
523 /******************************************************************************/
524 T_DCM_RET dcm_free_row(U8 current_row)
525 {
526 TRACE_FUNCTION("DCM: dcm_free_row()");
527
528 /* Decrease the current number of IPU */
529 dcm_env_ctrl_blk_p->ipu_list[current_row].row_state = ROW_FREE;
530 if(dcm_env_ctrl_blk_p->ipu_list[current_row].bearer_type EQ DCM_BEARER_GPRS)
531 dcm_env_ctrl_blk_p->gprs_current_total_row--;
532 else
533 dcm_env_ctrl_blk_p->gsm_current_total_row--;
534
535 /* clear the row in the structure of IP Users */
536 dcm_clear_ipu_info(current_row);
537 return DCM_OK;
538 }
539
540
541 /*
542 * Function used to store some IPU informations
543 *
544 * @param row to access [0, 256],
545 * @param IPU id
546 * @param bearer type
547 * @param apn, mtu, pdp@, cid, user, password, dns1, dns2, gateway
548 * @return DCM_OK or DCM errors
549 */
550 T_DCM_RET dcm_store_ipu_info(U8 row, T_BEARER_TYPE bearer_type, char *apn,
551 char *number, char *pdp_addr, U8 cid_used,
552 char *user, char *password, U32 dns1, U32 dns2,
553 U32 gateway)
554 {
555 TRACE_FUNCTION("DCM: dcm_store_ipu_info()");
556
557 if(bearer_type EQ DCM_BEARER_GPRS)
558 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].apn, apn);
559 else if (bearer_type EQ DCM_BEARER_GSM)
560 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].phone_number,number);
561 else
562 return DCM_INVALID_PARAMETER;
563 dcm_env_ctrl_blk_p->ipu_list[row].bearer_type = bearer_type;
564 dcm_env_ctrl_blk_p->ipu_list[row].cid = cid_used;
565 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].user_id, user);
566 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].password, password);
567 dcm_env_ctrl_blk_p->ipu_list[row].dns1 = dns1;
568 dcm_env_ctrl_blk_p->ipu_list[row].dns2 = dns2;
569 dcm_env_ctrl_blk_p->ipu_list[row].gateway = gateway;
570
571 return DCM_OK;
572 }
573
574
575 /* resets parameters of a row */
576 T_DCM_RET dcm_clear_ipu_info(U8 row)
577 {
578 char empty[] = "";
579 TRACE_FUNCTION("DCM: dcm_clear_ipu_info()");
580
581 dcm_env_ctrl_blk_p->ipu_list[row].bearer_type = DCM_BEARER_NO;
582 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].apn, empty);
583 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].phone_number,empty);
584 dcm_env_ctrl_blk_p->ipu_list[row].cid = 0;
585 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].user_id, empty);
586 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].password, empty);
587 dcm_env_ctrl_blk_p->ipu_list[row].dns1 = 0;
588 dcm_env_ctrl_blk_p->ipu_list[row].dns2 = 0;
589 dcm_env_ctrl_blk_p->ipu_list[row].gateway = 0;
590
591 return DCM_OK;
592 }
593
594 /*
595 * Function used to send the <AT+CGDCONT=?> command
596 *
597 * This command is used to get the next Context IDentifier available in the PS.
598 * This cid will be used very often in the suite
599 *
600 * @param row in the IPU structure related to the actual command
601 * @return DCM_OK or DCM errors
602 */
603 LOCAL T_DCM_RET dcm_send_cgdcont_get_cmd(U8 row)
604 {
605 /*T_GPRS_CONT_REC defCtxts[MAX_CID_PLUS_EINS]; */
606 T_PDP_CONTEXT defCtxts[PDP_CONTEXT_CID_MAX];
607 SHORT cid_array[PDP_CONTEXT_CID_MAX];
608 UBYTE i;
609
610 TRACE_FUNCTION("DCM: dcm_send_cgdcont_get_cmd()");
611
612 if(qAT_PlusCGDCONT(CMD_SRC_LCL,defCtxts,cid_array) NEQ AT_CMPL)
613 {
614 psaDCM_open_conn_cnf( DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
615 dcm_free_row(row);
616 set_state_from_ctrl_blk();
617 return DCM_OK;
618 }
619 else
620 {
621 for( i= 0; i < MAX_CID_PLUS_EINS ; i++)
622 {
623 if(cid_array[i] EQ dcm_env_ctrl_blk_p->ipu_list[row].cid)
624 {
625 TRACE_EVENT_P2("DCM: dcm cid is the same %d=%d",
626 cid_array[i],
627 dcm_env_ctrl_blk_p->ipu_list[row].cid);
628 }
629 }
630 return dcm_send_cgdcont_cmd(row);
631 }
632
633 }
634
635
636 /*
637 * Function used to send the <AT+CGDCONT=cid, "IP", "apn", "", 0, 0> command
638 *
639 * This command is used to declare the PDP Context.
640 *
641 * @param row in the IPU structure related to the actual command
642 * @return DCM_OK or DCM errors
643 */
644 LOCAL T_DCM_RET dcm_send_cgdcont_cmd(U8 row)
645 {
646 /*T_GPRS_CONT_REC input_txt; */
647 T_PDP_CONTEXT input_txt;
648
649 TRACE_FUNCTION("DCM: dcm_send_cgdcont_cmd()");
650 TRACE_EVENT_P1("DCM: ipu_list[row].apn = %s",dcm_env_ctrl_blk_p->ipu_list[row].apn);
651
652 strcpy(input_txt.pdp_apn,(char*)dcm_env_ctrl_blk_p->ipu_list[row].apn);
653 strcpy(input_txt.pdp_type,"IP");
654 memset(&input_txt.pdp_addr,0,sizeof(T_NAS_ip));
655 input_txt.d_comp = PDP_CONTEXT_D_COMP_OMITTED;
656 input_txt.h_comp = PDP_CONTEXT_H_COMP_OMITTED;
657
658 if(sAT_PlusCGDCONT(CMD_SRC_LCL,dcm_env_ctrl_blk_p->ipu_list[row].cid, &input_txt) NEQ AT_CMPL)
659 {
660 psaDCM_open_conn_cnf(DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
661 dcm_free_row(row);
662 set_state_from_ctrl_blk();
663 return DCM_OK;
664 }
665 else
666 {
667 dcm_send_cgatt_cmd(row);
668 return DCM_OK;
669 }
670 }
671
672
673 /*
674 * Function used to send the <AT+CGATT=cid> command
675 *
676 * This command is used to force attachment to the network.
677 *
678 * @param row in the IPU structure related to the actual command
679 * @return DCM_OK or DCM errors
680 */
681 LOCAL T_DCM_RET dcm_send_cgatt_cmd(U8 row)
682 {
683 TRACE_FUNCTION("DCM: dcm_send_cgatt_cmd()");
684
685 /* prepare the AT command including some dynamic info like cid */
686 switch(sAT_PlusCGATT(CMD_SRC_LCL, CGATT_STATE_ATTACHED))
687 {
688 case AT_FAIL:
689 case AT_BUSY:
690 psaDCM_open_conn_cnf(DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
691 dcm_free_row(row);
692 set_state_from_ctrl_blk();
693 break;
694
695 case AT_CMPL:
696 dcm_send_cgpco_auth_cmd(row);
697 break;
698
699 case AT_EXCT:
700 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
701 dcm_new_state(DCM_ACTIVATING_CONN, DCM_SUB_WAIT_CGATT_CNF);
702 break;
703
704 default :
705 break;
706 }
707 return DCM_OK;
708 }
709
710
711 /*
712 * Function used to send the <AT%CGPCO=0, cid, "PAP, username,
713 * password, 0.0.0.0, 0.0.0.0"> command
714 *
715 * This command is used to configure the PS to TCPIP over SNDCP
716 *
717 * @param row in the IPU structure related to the actual command
718 * @return DCM_OK or DCM errors
719 */
720 LOCAL T_DCM_RET dcm_send_cgpco_auth_cmd(U8 row)
721 {
722 CHAR dns[2];
723 strcpy(dns, "");
724
725 TRACE_FUNCTION("DCM: dcm_send_cgpco_auth_cmd()");
726 TRACE_EVENT_P2("DCM: user=%s, password=%s",
727 dcm_env_ctrl_blk_p->ipu_list[row].user_id,
728 dcm_env_ctrl_blk_p->ipu_list[row].password);
729
730 if(sAT_PercentCGPCO(CMD_SRC_LCL,dcm_env_ctrl_blk_p->ipu_list[row].cid,
731 ACI_PCO_AUTH_PROT_PAP,
732 (char*)dcm_env_ctrl_blk_p->ipu_list[row].user_id,
733 (char*)dcm_env_ctrl_blk_p->ipu_list[row].password,
734 dns,dns) NEQ AT_CMPL)
735 {
736 psaDCM_open_conn_cnf(DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
737 dcm_free_row(row);
738 set_state_from_ctrl_blk();
739 return DCM_OK;
740 }
741 else
742 {
743 dcm_send_cgerep_cmd(row);
744 return DCM_OK;
745 }
746 }
747
748
749 /*
750 * Function used to send the <AT+CGEREP=cid, 0> command
751 *
752 * This command is used to configure the PS to send EVENT to us
753 *
754 * @param row in the IPU structure related to the actual command
755 * @return DCM_OK or DCM errors
756 */
757 LOCAL T_DCM_RET dcm_send_cgerep_cmd(U8 row)
758 {
759 TRACE_FUNCTION("DCM: dcm_send_cgerep_cmd()");
760
761 /* prepare the AT command including some dynamic info like cid */
762 if (sAT_PlusCGEREP(CMD_SRC_LCL,CGEREP_MODE_BUFFER,CGEREP_BFR_CLEAR) NEQ AT_CMPL)
763 {
764 psaDCM_open_conn_cnf(DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
765 dcm_free_row(row);
766 set_state_from_ctrl_blk();
767 return DCM_OK;
768 }
769 else
770 {
771 strcpy((char*)dcm_env_ctrl_blk_p->ipu_list[row].phone_number,"*98*1#");
772 /* reset the WAP-data if not done at call termination before */
773 sAT_PercentWAP(CMD_SRC_LCL,0);
774 sAT_PercentWAP(CMD_SRC_LCL,1);
775 dcm_send_sat_dn_cmd(row);
776 return DCM_OK;
777 }
778 }
779
780
781 /*
782 * Function used to send the <AT+CGACT=cid, 0> command
783 *
784 * This command is used to deactivate the PDP decontext.
785 *
786 * @param row in the IPU structure related to the actual command
787 * @return DCM_OK or DCM errors
788 */
789 LOCAL T_DCM_RET dcm_send_cgdeact_cmd(U8 row)
790 {
791 T_CGATT_STATE gprs_attach_state;
792 SHORT cids[MAX_CID_PLUS_EINS] = {GPRS_CID_1,PDP_CONTEXT_CID_INVALID};
793
794
795 TRACE_FUNCTION("DCM: dcm_send_cgdeact_cmd()");
796
797 /* Packet Counter */
798 sAT_PercentSNCNT(CMD_SRC_LCL,NAS_RESET_YES);
799
800 qAT_PlusCGATT(CMD_SRC_LCL,&gprs_attach_state);
801 TRACE_EVENT_P1("DCM: Attatch State %d",gprs_attach_state);
802
803 #if 0 //// pinghua DCM_OPEN_CLOSE patch 20080429
804
805 if(gprs_attach_state NEQ CGATT_STATE_ATTACHED)
806 {
807 psaDCM_close_conn_cnf(DCM_OK,dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
808 dcm_free_row(row);
809 set_state_from_ctrl_blk();
810 return DCM_OK;
811 }
812 #endif // // pinghua DCM_OPEN_CLOSE patch 20080429 end
813
814 /* GPRS BEARER CLOSING */
815 switch(sAT_PlusCGACT(CMD_SRC_LCL,CGACT_STATE_DEACTIVATED,cids))
816 {
817 case AT_FAIL:
818 case AT_BUSY:
819 psaDCM_close_conn_cnf(DCM_NOT_READY,
820 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
821 set_state_from_ctrl_blk();
822 break;
823
824 case AT_CMPL:
825 psaDCM_close_conn_cnf(DCM_OK, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
826 dcm_free_row(row);
827 set_state_from_ctrl_blk();
828 break;
829
830 case AT_EXCT:
831 dcm_new_state(DCM_CLOSING_CONN, DCM_SUB_WAIT_CGDEACT_CNF);
832 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
833 break;
834
835 default :
836 break;
837 }
838 return DCM_OK;
839 }
840
841
842 LOCAL T_DCM_RET dcm_send_sat_h_cmd(U8 row)
843 {
844 TRACE_FUNCTION("DCM: dcm_send_sat_h_cmd()");
845
846 switch(sAT_H(CMD_SRC_LCL))
847 {
848 case AT_FAIL:
849 case AT_BUSY:
850 psaDCM_close_conn_cnf(DCM_NOT_READY, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
851 set_state_from_ctrl_blk();
852 break;
853
854 case AT_CMPL:
855 break;
856
857 case AT_EXCT:
858 dcm_new_state(DCM_CLOSING_CONN, DCM_SUB_WAIT_SATH_CNF);
859 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
860 break;
861
862 default :
863 break;
864 }
865 return DCM_OK;
866 }
867
868
869 /*
870 * Function used to send the <AT+CGPADDR=cid> command
871 *
872 * This command is used to get back the pdp@ of the module
873 *
874 * @param row in the IPU structure related to the actual command
875 * @return DCM_OK or DCM errors
876 */
877 LOCAL T_DCM_RET dcm_send_cgpaddr_cmd(U8 row)
878 {
879 T_NAS_ip pdp_address[MAX_CID];
880 SHORT cid_array[MAX_CID];
881 cid_array[0] = dcm_env_ctrl_blk_p->ipu_list[row].cid;
882 cid_array[1] = PDP_CONTEXT_CID_INVALID;
883
884 TRACE_FUNCTION("DCM: dcm_send_cgpaddr_cmd()");
885
886 memset(pdp_address , 0x00, sizeof(T_NAS_ip)*MAX_CID);
887
888 /* prepare the AT command including some dynamic info like cid */
889 if(sAT_PlusCGPADDR(CMD_SRC_LCL,cid_array,pdp_address) NEQ AT_CMPL)
890 {
891 psaDCM_open_conn_cnf(DCM_NOT_READY,
892 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
893 dcm_free_row(row);
894 set_state_from_ctrl_blk();
895 return DCM_OK;
896 }
897 else
898 {
899 memcpy(dcm_env_ctrl_blk_p->ipu_list[row].pdp_addr,
900 pdp_address[0].ip_address.ipv4_addr.a4,
901 sizeof(NAS_SIZE_IPv4_ADDR));
902 TRACE_EVENT_P1("DCM: PDP addr=%s",dcm_env_ctrl_blk_p->ipu_list[row].pdp_addr);
903 dcm_send_cgpco_get_cmd(row);
904 return DCM_OK;
905 }
906 }
907
908
909 /*
910 * Function used to send the <AT%CGPCO=1,1,,cid> command
911 *
912 * This command is used to get back the dns1, dns2 and gateway @
913 *
914 * @param row in the IPU structure related to the actual command
915 * @return DCM_OK or DCM errors
916 */
917 LOCAL T_DCM_RET dcm_send_cgpco_get_cmd(U8 row)
918 {
919 TRACE_FUNCTION("DCM: dcm_send_cgpco_get_cmd()");
920
921 psaDCM_open_conn_cnf(DCM_OK, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
922 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
923 dcm_new_state(DCM_CONN_ACTIVATED, DCM_SUB_NO_ACTION);
924
925 return DCM_OK;
926 }
927
928
929 T_DCM_RET dcm_send_percentppp_cmd(U8 row)
930 {
931 TRACE_FUNCTION("DCM: dcm_send_percentppp_cmd()");
932 if(sAT_PercentPPP(CMD_SRC_LCL,
933 A_PAP,
934 (char*)dcm_env_ctrl_blk_p->ipu_list[row].user_id,
935 (char*)dcm_env_ctrl_blk_p->ipu_list[row].password,
936 USE_NO_PPP_FOR_AAA) NEQ AT_CMPL)
937 {
938 psaDCM_open_conn_cnf(DCM_NOT_READY,
939 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
940 dcm_free_row(row);
941 set_state_from_ctrl_blk();
942 }
943 else
944 {
945 /* reset the WAP-data if not done at call termination before */
946 sAT_PercentWAP(CMD_SRC_LCL,0);
947 sAT_PercentWAP(CMD_SRC_LCL,1);
948 dcm_send_sat_dn_cmd(row);
949 }
950
951 return DCM_OK;
952 }
953
954
955 LOCAL T_DCM_RET dcm_send_sat_dn_cmd(U8 row)
956 {
957 TRACE_FUNCTION("DCM: dcm_send_sat_dn_cmd()");
958
959 switch(sAT_Dn(CMD_SRC_LCL,
960 (char*)dcm_env_ctrl_blk_p->ipu_list[row].phone_number,
961 D_CLIR_OVRD_Default,
962 D_CUG_CTRL_NotPresent,
963 D_TOC_Data))
964 {
965 case AT_FAIL:
966 case AT_BUSY:
967 case AT_CMPL:
968 psaDCM_open_conn_cnf(DCM_NOT_READY,
969 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
970 dcm_free_row(row);
971 set_state_from_ctrl_blk();
972 break;
973
974 case AT_EXCT:
975 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
976 if(dcm_env_ctrl_blk_p->ipu_list[row].bearer_type EQ DCM_BEARER_GPRS) {
977 dcm_new_state(DCM_ACTIVATING_CONN, DCM_SUB_WAIT_CGACT_CNF);
978 }
979 else {
980 dcm_new_state(DCM_ACTIVATING_CONN, DCM_SUB_WAIT_SATDN_CNF);
981 }
982 break;
983
984 default:
985 break;
986 }
987
988 return DCM_OK;
989 }
990
991
992 LOCAL T_DCM_RET dcm_send_percentppp_get_cmd(U8 row)
993 {
994 ULONG dns1=0;
995 ULONG dns2 =0;
996 ULONG ipaddr = 0 ;
997
998 TRACE_FUNCTION("DCM: dcm_send_percentppp_get_cmd()");
999
1000 if(qAT_PercentPPP(CMD_SRC_LCL, &ipaddr,&dns1,&dns2) NEQ AT_CMPL)
1001 {
1002 psaDCM_open_conn_cnf(DCM_NOT_READY,
1003 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1004 dcm_free_row(row);
1005 set_state_from_ctrl_blk();
1006 }
1007 else
1008 {
1009 psaDCM_open_conn_cnf(DCM_OK,
1010 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1011 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
1012 dcm_new_state(DCM_CONN_ACTIVATED,DCM_SUB_NO_ACTION);
1013 }
1014
1015 return DCM_OK;
1016 }
1017
1018
1019 /*
1020 * Function used to process the events and errors received from PS
1021 *
1022 * @param received message
1023 * @return DCM_OK or DCM errors
1024 */
1025 T_DCM_RET dcm_process_event_error_reception(T_DCM_HDR * msg_p)
1026 {
1027 U8 row = dcm_env_ctrl_blk_p->current_row;;
1028
1029 TRACE_FUNCTION("DCM: dcm_process_event_error_reception()");
1030
1031 /* check if this port number is really used by DCM */
1032 if(dcm_env_ctrl_blk_p->ipu_list[row].row_state)
1033 {
1034 psaDCM_error_ind((T_DCM_STATUS_IND_MSG*)msg_p,
1035 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1036 dcm_free_row(row);
1037 /* We cannot use this function call here (set_state_from_ctrl_blk();)
1038 since this will execute reset_gpf_tcpip_call() immediately, but we need
1039 to evaulate this flag later on */
1040 if((dcm_env_ctrl_blk_p->gsm_current_total_row +
1041 dcm_env_ctrl_blk_p->gprs_current_total_row ) > 0)
1042 {
1043 /* another active connection */
1044 dcm_new_state(DCM_CONN_ACTIVATED, DCM_SUB_NO_ACTION);
1045 }
1046 else
1047 {
1048 dcm_new_state(DCM_IDLE, DCM_SUB_NO_ACTION);
1049 }
1050 }
1051 return DCM_OK;
1052 }
1053
1054
1055 /*
1056 * Function used to process the reception of the answer to AT+CGATT=...
1057 *
1058 * @param received message, and row in the IPU structure related to the actual command
1059 * @return DCM_OK or DCM errors
1060 */
1061 T_DCM_RET dcm_process_cgatt_ans(T_DCM_HDR * msg_p, U8 row)
1062 {
1063 TRACE_FUNCTION("DCM: dcm_process_cgatt_ans()");
1064
1065 if(msg_p->msg_id EQ DCM_NEXT_CMD_READY_MSG)
1066 {
1067 /* send next AT command */
1068 return dcm_send_cgpco_auth_cmd(row);
1069 }
1070 else
1071 {
1072 psaDCM_open_conn_cnf(DCM_NOT_READY,
1073 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1074 dcm_free_row(row);
1075 set_state_from_ctrl_blk();
1076 return DCM_OK;
1077 }
1078 }
1079
1080
1081 /*
1082 * Function used to process the reception of the answer to AT+CGACT=...
1083 *
1084 * @param received message, and row in the IPU structure related to the actual command
1085 * @return DCM_OK or DCM errors
1086 */
1087 T_DCM_RET dcm_process_cgact_ans(T_DCM_HDR * msg_p, U8 row)
1088 {
1089 TRACE_FUNCTION("DCM: dcm_process_cgact_ans()");
1090
1091 if (msg_p->msg_id EQ DCM_NEXT_CMD_READY_MSG)
1092 {
1093 return dcm_send_cgpaddr_cmd(row);
1094 }
1095 else
1096 {
1097 psaDCM_open_conn_cnf(DCM_NOT_READY,
1098 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1099 dcm_free_row(row);
1100 /*set_state_from_ctrl_blk();*/
1101 /* We cannot use this function call here (set_state_from_ctrl_blk();)
1102 since this will execute reset_gpf_tcpip_call() immediately, but we need
1103 to evaulate this flag later on */
1104
1105 if((dcm_env_ctrl_blk_p->gsm_current_total_row +
1106 dcm_env_ctrl_blk_p->gprs_current_total_row ) > 0)
1107 {
1108 /* another active connection */
1109 dcm_new_state(DCM_CONN_ACTIVATED, DCM_SUB_NO_ACTION);
1110 }
1111 else
1112 {
1113 dcm_new_state(DCM_IDLE, DCM_SUB_NO_ACTION);
1114 }
1115 return DCM_OK;
1116 }
1117 }
1118
1119
1120 T_DCM_RET dcm_process_cgdeact_ans(T_DCM_HDR * msg_p, U8 row)
1121 {
1122 TRACE_FUNCTION("DCM: dcm_process_cgdeact_ans()");
1123
1124 if(msg_p->msg_id EQ DCM_NEXT_CMD_READY_MSG)
1125 {
1126 //pinghua add one broken messaged indiction for net drop !
1127 if(is_netdrop == TRUE )
1128 {
1129
1130 psaDCM_error_ind((T_DCM_STATUS_IND_MSG*)msg_p,
1131 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1132
1133 }
1134 else
1135 psaDCM_close_conn_cnf(DCM_OK,
1136 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1137 //end
1138
1139 dcm_free_row(row);
1140 }
1141 else
1142 {
1143 psaDCM_close_conn_cnf(DCM_NOT_READY,
1144 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1145 dcm_env_ctrl_blk_p->ipu_list[row].row_state = ROW_ASSIGNED;
1146 }
1147 set_state_from_ctrl_blk();
1148 return DCM_OK;
1149 }
1150
1151
1152 T_DCM_RET dcm_process_sat_dn_ans(T_DCM_HDR * msg_p, U8 row)
1153 {
1154 TRACE_FUNCTION("DCM: dcm_process_sat_dn_ans()");
1155
1156 if(msg_p->msg_id EQ DCM_NEXT_CMD_READY_MSG)
1157 {
1158 return dcm_send_percentppp_get_cmd(row);
1159 }
1160 else
1161 {
1162 T_DCM_STATUS_IND_MSG * message = (T_DCM_STATUS_IND_MSG *)msg_p;
1163 /* We need to check if TCPIP has been already initialised successfully or not*/
1164 if ( wap_state EQ TCPIP_Activation)
1165 {
1166 /* Make shure we shutdown TCPIP properly */
1167 wap_state = TCPIP_Deactivation;
1168 psaTCPIP_Shutdown_Req();
1169 }
1170 psaDCM_open_conn_cnf(message->result, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1171 dcm_free_row(row);
1172 set_state_from_ctrl_blk();
1173 return DCM_OK;
1174 }
1175 }
1176
1177
1178 T_DCM_RET dcm_process_sat_h_ans(T_DCM_HDR * msg_p, U8 row)
1179 {
1180 TRACE_FUNCTION("DCM: dcm_process_sat_h_ans()");
1181
1182 if(msg_p->msg_id EQ DCM_NEXT_CMD_READY_MSG)
1183 {
1184 psaDCM_close_conn_cnf(DCM_OK,dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1185 dcm_free_row(row);
1186 }
1187 else
1188 {
1189 psaDCM_close_conn_cnf(DCM_NOT_READY,
1190 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1191 }
1192 set_state_from_ctrl_blk();
1193 return DCM_OK;
1194 }
1195
1196
1197 GLOBAL ULONG bytes2ipv4addr(UBYTE *host)
1198 {
1199 UBYTE c1;
1200 ULONG addr = 0;
1201 char *tmp;
1202 if (!host OR host[0]>'9' OR host[0]<'0') return((ULONG)-1);
1203
1204 tmp=(char *)host;
1205 c1 = atoi(tmp);
1206 addr = addr | c1 << 24;
1207 tmp = strstr(tmp, ".");
1208 if(!tmp) return((ULONG)-1);
1209 tmp++;
1210 c1 = atoi(tmp);
1211 addr = addr | c1 << 16;
1212 tmp = strstr(tmp, ".");
1213 if(!tmp) return((ULONG)-1);
1214 tmp++;
1215 c1 = atoi(tmp);
1216 addr = addr | c1 <<8 ;
1217 tmp = strstr(tmp, ".");
1218 if(!tmp) return((ULONG)-1);
1219 tmp++;
1220 c1 = atoi(tmp);
1221 addr = addr | c1 ;
1222 return dcm_ipaddr_htonl(addr);
1223 }
1224
1225
1226 LOCAL ULONG dcm_ipaddr_htonl(ULONG horder_ipaddr)
1227 {
1228 return((U32)((((U32)(horder_ipaddr) & 0x000000ffU) << 24) |
1229 (((U32)(horder_ipaddr) & 0x0000ff00U) << 8) |
1230 (((U32)(horder_ipaddr) & 0x00ff0000U) >> 8) |
1231 (((U32)(horder_ipaddr) & 0xff000000U) >> 24)));
1232 }
1233
1234
1235 LOCAL T_DCM_RET dcm_send_percentcal_get_cmd(UBYTE row)
1236 {
1237 T_ACI_CAL_ENTR call_tab[MAX_CALL_NR];
1238 UBYTE i;
1239 UBYTE count = 0;
1240
1241 TRACE_FUNCTION("DCM: dcm_send_percentcal_get_cmd()");
1242
1243 if(qAT_PercentCAL(CMD_SRC_LCL, call_tab) EQ AT_CMPL)
1244 {
1245 for(i=0; i<MAX_CALL_NR; i++)
1246 {
1247 if(call_tab[i].index EQ -1)
1248 {
1249 count++;
1250 /* in other words no active call*/
1251 if(count EQ (MAX_CALL_NR -1) )
1252 {
1253 TRACE_EVENT("DCM: No active call");
1254 psaDCM_close_conn_cnf(DCM_OK, dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1255 dcm_free_row(row);
1256 set_state_from_ctrl_blk();
1257 }
1258 break;
1259 }
1260 switch(call_tab[i].status)
1261 {
1262 case CAL_STAT_Active:
1263 dcm_send_sat_h_cmd(row);
1264 break;
1265 case CAL_STAT_Dial:
1266 case CAL_STAT_Alerting:
1267 dcm_send_sat_abort_cmd(row);
1268 break;
1269
1270 default:
1271 TRACE_EVENT("DCM: dcm_send_percentcal_get_cmd DEFAULT call status");
1272 break;
1273 }
1274 }
1275 return DCM_OK;
1276 }
1277 return DCM_OK;
1278 }
1279
1280
1281 LOCAL T_DCM_RET dcm_send_sat_abort_cmd(U8 row)
1282 {
1283 TRACE_FUNCTION("DCM: dcm_send_sat_h_cmd()");
1284
1285 switch(sAT_Abort(CMD_SRC_LCL,AT_CMD_D))
1286 {
1287 case AT_FAIL:
1288 case AT_BUSY:
1289 psaDCM_close_conn_cnf(DCM_NOT_READY,
1290 dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1291 set_state_from_ctrl_blk();
1292 break;
1293
1294 case AT_CMPL:
1295 psaDCM_close_conn_cnf(DCM_OK,dcm_env_ctrl_blk_p->ipu_list[row].api_instance);
1296 dcm_free_row(row);
1297 set_state_from_ctrl_blk();
1298 break;
1299
1300 case AT_EXCT:
1301 dcm_new_state(DCM_CLOSING_CONN, DCM_SUB_WAIT_SATH_CNF);
1302 dcm_env_ctrl_blk_p->dcm_call_back = dcm_handle_message;
1303 break;
1304
1305 default :
1306 break;
1307 }
1308 return DCM_OK;
1309 }
1310
1311
1312 /* This functions checks if antother conneciton is active and changes the
1313 DCM state corresponding */
1314 LOCAL void set_state_from_ctrl_blk()
1315 {
1316 if((dcm_env_ctrl_blk_p->gsm_current_total_row +
1317 dcm_env_ctrl_blk_p->gprs_current_total_row ) > 0)
1318 {
1319 /* another active connection */
1320 dcm_new_state(DCM_CONN_ACTIVATED, DCM_SUB_NO_ACTION);
1321 }
1322 else
1323 {
1324 dcm_new_state(DCM_IDLE, DCM_SUB_NO_ACTION);
1325 reset_gpf_tcpip_call();
1326 }
1327 }