FreeCalypso > hg > tcs211-c139
comparison chipsetsw/services/atp/atp_uart_handle_msg.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /********************************************************************************/ | |
2 /* */ | |
3 /* File Name: atp_uart_handle_msg.c */ | |
4 /* */ | |
5 /* Purpose: This file contains the internal function related to */ | |
6 /* the ATP-UART interface and used to handle incoming */ | |
7 /* messages */ | |
8 /* */ | |
9 /* Note: None. */ | |
10 /* */ | |
11 /* Revision History: */ | |
12 /* 10/04/01 Pascal Pompei */ | |
13 /* - Create. */ | |
14 /* */ | |
15 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved. */ | |
16 /* */ | |
17 /********************************************************************************/ | |
18 #include "atp/atp_i.h" | |
19 #include "atp/atp_uart_i.h" | |
20 #include "rvm/rvm_use_id_list.h" | |
21 | |
22 | |
23 /********************************************************************************/ | |
24 /* */ | |
25 /* Function Name: atp_uart_handle_msg */ | |
26 /* */ | |
27 /* Purpose: This function handles incoming messages available from */ | |
28 /* the mailbox dedicated to the ATP-UART interface. */ | |
29 /* */ | |
30 /* Input Parameters: None. */ | |
31 /* */ | |
32 /* Output Parameters: None. */ | |
33 /* */ | |
34 /* Global Parameters: None. */ | |
35 /* */ | |
36 /* Notes: The GSM protocol stack must be started first. */ | |
37 /* Nevertheless, note that incoming data calls are not */ | |
38 /* supported for now. Moreover, the AT Parser is alerted */ | |
39 /* that the call is terminated by receiving an 'Ok' or a */ | |
40 /* 'No Carrier' final result code only. At last, the GSM */ | |
41 /* protocol stack is initialized by invoking the */ | |
42 /* following AT commands: */ | |
43 /* ATE0 : Echo mode switched off, */ | |
44 /* AT+CFUN=1 : Set Phone Functionality (Full), */ | |
45 /* AT+COPS=0 : Operator Selection. */ | |
46 /* */ | |
47 /* Revision History: */ | |
48 /* 10/04/01 Pascal Pompei */ | |
49 /* - Create. */ | |
50 /* */ | |
51 /********************************************************************************/ | |
52 T_ATP_UART_ERROR_CODES atp_uart_handle_msg (void) | |
53 { | |
54 /* Declare local variables. */ | |
55 UINT16 event_pending = 0x0000; | |
56 UINT32 in_buffer_size = 0x00000000; | |
57 BOOLEAN echo_mode_switched_off = FALSE; | |
58 BOOLEAN error_occurred = FALSE; | |
59 T_ATP_CALLBACK return_path = {0x00, \ | |
60 NULL}; | |
61 T_ATP_ENTITY_MODE mode = {CMD_SUPPORT_ON, \ | |
62 TXT_MODE, \ | |
63 COPY_ON}; | |
64 T_ATP_SW_ENTITY_NAME name = ATP_GSM_NAME; | |
65 | |
66 /********************** atp_uart_handle_msg function begins *********************/ | |
67 | |
68 /* First, wait until the COM port is activated. */ | |
69 while ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).com_port_handle == INVALID_HANDLE_VALUE) | |
70 { | |
71 | |
72 /* Wait for the next event(s) of interest. */ | |
73 event_pending = rvf_wait (ATP_UART_ALL_EVENT_FLAGS, | |
74 0x00000000); | |
75 | |
76 /* If an expected event occurred, then get the associated message from */ | |
77 /* the mailbox dedicated to the ATP-UART interface. */ | |
78 if (event_pending & ATP_UART_EXPECTED_EVENT) | |
79 { | |
80 | |
81 /* Declare a local block variable. */ | |
82 T_RV_HDR *incoming_message_p = NULL; | |
83 | |
84 /* Get the incoming message from the mailbox dedicated to the */ | |
85 /* ATP-UART interface. */ | |
86 incoming_message_p = (T_RV_HDR *) rvf_read_mbox (ATP_UART_MAILBOX); | |
87 | |
88 /* Check whether the incoming message is valid. */ | |
89 if (incoming_message_p == NULL) | |
90 { | |
91 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
92 " ATP-UART (handle_msg). Invalid event occurred "); | |
93 return (RVM_INTERNAL_ERR); | |
94 } | |
95 switch (incoming_message_p->msg_id) | |
96 { | |
97 | |
98 /* 'ATP-UART Open COM Port'. */ | |
99 case ATP_UART_OPEN_COM_PORT: | |
100 { | |
101 | |
102 /* Declare a local block variable. */ | |
103 UINT8 gsm_basic_init_p[] = {'A', 'T', 'E', '0', \ | |
104 ATP_CR_CHARACTER}; | |
105 | |
106 /* Open the COM port whose number and baud rate are */ | |
107 /* specified. If any error occurred, then call the */ | |
108 /* function used whenever any unrecoverable error */ | |
109 /* occurs and abort. */ | |
110 if (atp_uart_create_com_port ((unsigned char) (((T_ATP_UART_OPEN_COM_PORT *) (incoming_message_p))->com_port), \ | |
111 ((T_ATP_UART_OPEN_COM_PORT *) (incoming_message_p))->baud_rate) != RV_OK) | |
112 { | |
113 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
114 " ATP-UART (handle_msg). Unable to activate the COM port "); | |
115 return (RVM_INTERNAL_ERR); | |
116 } | |
117 rvf_send_trace (" ATP-UART (handle_msg). COM port properly opened ", | |
118 50, | |
119 NULL_PARAM, | |
120 RV_TRACE_LEVEL_DEBUG_LOW, | |
121 ATP_USE_ID); | |
122 | |
123 /* Configure the GSM especially not to echo characters */ | |
124 /* during 'Command State' and 'Online Command State'. */ | |
125 /* If any error occurred, then call the function used */ | |
126 /* whenever any unrecoverable error occurs and abort. */ | |
127 if (atp_uart_write_com_port (gsm_basic_init_p, \ | |
128 sizeof (gsm_basic_init_p)) != RV_OK) | |
129 { | |
130 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
131 " ATP-UART (handle_msg). GSM configuration failed "); | |
132 return (RVM_INTERNAL_ERR); | |
133 } | |
134 break; | |
135 } | |
136 | |
137 /* Unexpected message. */ | |
138 default: | |
139 { | |
140 rvf_send_trace (" ATP-UART (handle_msg). Unexpected message received ", | |
141 53, | |
142 incoming_message_p->msg_id, | |
143 RV_TRACE_LEVEL_WARNING, | |
144 ATP_USE_ID); | |
145 break; | |
146 } | |
147 } | |
148 (void) rvf_free_buf ((T_RVF_BUFFER *) (incoming_message_p)); | |
149 } | |
150 } | |
151 | |
152 /* Then, wait for the echo mode being switched off. */ | |
153 while (echo_mode_switched_off == FALSE) | |
154 { | |
155 | |
156 /* Wait for the next event(s) of interest. */ | |
157 event_pending = rvf_wait (ATP_UART_ALL_EVENT_FLAGS, | |
158 0x00000001); | |
159 | |
160 /* If an expected event occurred, then get the associated message from */ | |
161 /* the mailbox dedicated to the ATP-UART interface. */ | |
162 if (event_pending & ATP_UART_EXPECTED_EVENT) | |
163 { | |
164 | |
165 /* Declare a local block variable. */ | |
166 T_RV_HDR *incoming_message_p = NULL; | |
167 | |
168 /* Get the incoming message from the mailbox dedicated to the */ | |
169 /* ATP-UART interface. */ | |
170 incoming_message_p = (T_RV_HDR *) rvf_read_mbox (ATP_UART_MAILBOX); | |
171 | |
172 /* Check whether the incoming message is valid. */ | |
173 if (incoming_message_p == NULL) | |
174 { | |
175 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
176 " ATP-UART (handle_msg). Invalid event occurred "); | |
177 return (RVM_INTERNAL_ERR); | |
178 } | |
179 rvf_send_trace (" ATP-UART (handle_msg). Unexpected message received ", | |
180 53, | |
181 incoming_message_p->msg_id, | |
182 RV_TRACE_LEVEL_WARNING, | |
183 ATP_USE_ID); | |
184 (void) rvf_free_buf ((T_RVF_BUFFER *) (incoming_message_p)); | |
185 } | |
186 | |
187 /* Now, attempt forwarding data to the AT Parser. Thus, initialize the */ | |
188 /* amount of data to be forwarded. */ | |
189 in_buffer_size = (UINT32) (ATP_UART_MAX_PACKET_SIZE - \ | |
190 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left); | |
191 | |
192 /* Then, wait for data from the COM port. If any error occurred, then */ | |
193 /* abort. */ | |
194 if (atp_uart_read_com_port (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[(gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left]), \ | |
195 &in_buffer_size) == RV_OK) | |
196 { | |
197 | |
198 /* Declare local block variables. */ | |
199 UINT32 in_buffer_begin = 0x00000000; | |
200 UINT32 in_buffer_end = 0x00000000; | |
201 T_ATP_CMD *cmd_info_p = NULL; | |
202 T_ATP_CMD_NB cmd_nb = 0x0000; | |
203 T_ATP_CMD_TYPE cmd_type = UNKNOWN; | |
204 | |
205 /* Send every 'Text Command' to the AT Parser separately. */ | |
206 while (in_buffer_end < in_buffer_size) | |
207 { | |
208 | |
209 /* Skip leading <CR> and <LF> characters. */ | |
210 for (in_buffer_begin = in_buffer_end; | |
211 (in_buffer_begin < in_buffer_size) && \ | |
212 (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin] == ATP_LF_CHARACTER) || \ | |
213 ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin] == ATP_CR_CHARACTER)); | |
214 in_buffer_begin++) | |
215 { | |
216 } | |
217 | |
218 /* Get the 'Text Command' length by searching for the ending */ | |
219 /* <CR> character. */ | |
220 for (in_buffer_end = in_buffer_begin; | |
221 (in_buffer_end < in_buffer_size) && \ | |
222 ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end] != ATP_CR_CHARACTER); | |
223 in_buffer_end++) | |
224 { | |
225 } | |
226 | |
227 /* Abort whether no ending <CR> character found. */ | |
228 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end] != ATP_CR_CHARACTER) | |
229 { | |
230 | |
231 /* Update the number of bytes left. */ | |
232 in_buffer_size -= in_buffer_begin; | |
233 | |
234 /* Defrag. */ | |
235 memcpy ((void *) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p), | |
236 (void *) (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin])), | |
237 in_buffer_size); | |
238 | |
239 /* Update the number of bytes left. */ | |
240 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = in_buffer_size; | |
241 break; | |
242 } | |
243 | |
244 /* Otherwise, replace the ending <CR> character by NULL. */ | |
245 /* Indeed, such a 'Text Command' must be a NULL-terminated */ | |
246 /* string. */ | |
247 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end++] = '\x00'; | |
248 rvf_send_trace (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin]), | |
249 (UINT8) (in_buffer_end - in_buffer_begin - 0x01), | |
250 NULL_PARAM, | |
251 RV_TRACE_LEVEL_DEBUG_LOW, | |
252 ATP_USE_ID); | |
253 | |
254 /* Check whether the 'Text Command' is a final result code. */ | |
255 if ((atp_translate_txt_to_cmd (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin]), \ | |
256 UNKNOWN, \ | |
257 &cmd_type, \ | |
258 &cmd_nb, \ | |
259 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
260 &cmd_info_p) == RV_OK) && \ | |
261 (cmd_type == RESULT_CODE)) | |
262 { | |
263 | |
264 /* If needed, de-allocate the command-related information. */ | |
265 if (cmd_info_p != NULL) | |
266 { | |
267 (void) rvf_free_buf ((T_RVF_BUFFER *) (cmd_info_p)); | |
268 } | |
269 | |
270 /* Check whether the 'Text Command' corresponds to the 'OK' */ | |
271 /* final result code. */ | |
272 if (cmd_nb == ATP_OK_NB) | |
273 { | |
274 rvf_send_trace (" ATP-UART (handle_msg). Echo mode switched off ", | |
275 48, | |
276 NULL_PARAM, | |
277 RV_TRACE_LEVEL_DEBUG_LOW, | |
278 ATP_USE_ID); | |
279 | |
280 /* The echo mode is properly switched off. */ | |
281 echo_mode_switched_off = TRUE; | |
282 break; | |
283 } | |
284 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
285 " ATP-UART (handle_msg). Echo mode not switched off "); | |
286 return (RVM_INTERNAL_ERR); | |
287 } | |
288 | |
289 /* If needed, de-allocate the command-related information. */ | |
290 if (cmd_info_p != NULL) | |
291 { | |
292 (void) rvf_free_buf ((T_RVF_BUFFER *) (cmd_info_p)); | |
293 } | |
294 } | |
295 continue; | |
296 } | |
297 rvf_send_trace (" ATP-UART (handle_msg). Failed in getting data from the COM port ", | |
298 66, | |
299 NULL_PARAM, | |
300 RV_TRACE_LEVEL_WARNING, | |
301 ATP_USE_ID); | |
302 } | |
303 | |
304 /* At last, initialize the remainder of the return path in order to receive */ | |
305 /* events from the AT parser. */ | |
306 return_path.addr_id = gbl_atp_uart_ctrl_blk_p->addr_id; | |
307 | |
308 /* Register the ATP-UART interface to the AT Parser. If any error occurred, */ | |
309 /* then call the function used whenever any unrecoverable error occurs and */ | |
310 /* abort. */ | |
311 if (atp_reg (name, \ | |
312 return_path, \ | |
313 mode, \ | |
314 &((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id)) != RV_OK) | |
315 { | |
316 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
317 " ATP-UART (handle_msg). Registration failed "); | |
318 return (RVM_INTERNAL_ERR); | |
319 } | |
320 rvf_send_trace (" ATP-UART (handle_msg). Registration completed ", | |
321 48, | |
322 NULL_PARAM, | |
323 RV_TRACE_LEVEL_DEBUG_LOW, | |
324 ATP_USE_ID); | |
325 | |
326 /* Now, wait for the next events to be handled as long as no error occurs. */ | |
327 while (error_occurred == FALSE) | |
328 { | |
329 | |
330 /* Wait for the next event(s) of interest. */ | |
331 event_pending = rvf_wait (ATP_UART_ALL_EVENT_FLAGS, | |
332 0x00000001); | |
333 | |
334 /* If an expected event occurred, then get the associated message from */ | |
335 /* the mailbox dedicated to the ATP-UART interface. */ | |
336 if (event_pending & ATP_UART_EXPECTED_EVENT) | |
337 { | |
338 | |
339 /* Declare a local block variable. */ | |
340 T_RV_HDR *incoming_message_p = NULL; | |
341 | |
342 /* Get the incoming message from the mailbox dedicated to the */ | |
343 /* ATP-UART interface. */ | |
344 incoming_message_p = (T_RV_HDR *) rvf_read_mbox (ATP_UART_MAILBOX); | |
345 | |
346 /* Check whether the incoming message is valid. */ | |
347 if (incoming_message_p == NULL) | |
348 { | |
349 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
350 " ATP-UART (handle_msg). Invalid event occurred "); | |
351 return (RVM_INTERNAL_ERR); | |
352 } | |
353 switch (incoming_message_p->msg_id) | |
354 { | |
355 | |
356 /* 'ATP Open Port Indication'. */ | |
357 case ATP_OPEN_PORT_IND: | |
358 { | |
359 | |
360 /* Declare local block variables. */ | |
361 T_ATP_PORT_INFO gsm_port_info = {NOT_DEFINED_CONFIG, \ | |
362 ATP_NO_RING_TYPE, \ | |
363 ATP_ALL_THE_SIGNAL_UNMASK, \ | |
364 0x0000}; | |
365 T_ATP_NO_COPY_INFO gsm_no_copy_info = {RVF_INVALID_MB_ID, \ | |
366 RVF_INVALID_MB_ID, \ | |
367 TX_HEADER_OFF, \ | |
368 0x00, \ | |
369 0x00, \ | |
370 RX_HEADER_OFF, \ | |
371 0x00, \ | |
372 0x00, \ | |
373 NORMAL_PACKET}; | |
374 T_ATP_CUSTOM_FROM_GSM_INFO *gsm_custom_info_p = NULL; | |
375 | |
376 rvf_send_trace (" ATP-UART (handle_msg). 'ATP Open Port Indication' received ", | |
377 61, | |
378 NULL_PARAM, | |
379 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
380 ATP_USE_ID); | |
381 | |
382 /* Set custom information associated with the pseudo */ | |
383 /* GSM Software Entity. If insufficient resources, then */ | |
384 /* call the function used whenever any unrecoverable */ | |
385 /* error occurs and abort. */ | |
386 if (rvf_get_buf (gbl_atp_uart_ctrl_blk_p->mb_id, \ | |
387 sizeof (T_ATP_CUSTOM_FROM_GSM_INFO), \ | |
388 (T_RVF_BUFFER **) (&gsm_custom_info_p)) == RVF_RED) | |
389 { | |
390 ATP_UART_UNRECOVERABLE_ERROR (RVM_MEMORY_ERR, | |
391 " ATP-UART (handle_msg). Insufficient resources "); | |
392 return (RVM_MEMORY_ERR); | |
393 } | |
394 gsm_custom_info_p->custom_type = ATP_FROM_GSM_INFO; | |
395 gsm_custom_info_p->optimal_gsm_max_packet_size = ATP_UART_MAX_PACKET_SIZE; | |
396 | |
397 /* Open the virtual modem port with the AT Parser. If */ | |
398 /* any error occurred, then de-allocate custom */ | |
399 /* information associated with the pseudo GSM Software */ | |
400 /* Entity, call the function used whenever any */ | |
401 /* unrecoverable error occurs and abort. */ | |
402 if (atp_open_port_rsp (((T_ATP_OPEN_PORT_IND *) (incoming_message_p))->initiator_id, \ | |
403 ((T_ATP_OPEN_PORT_IND *) (incoming_message_p))->initiator_port_nb, \ | |
404 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
405 ATP_UART_GSM_PORT_NB, \ | |
406 gsm_port_info, \ | |
407 gsm_no_copy_info, \ | |
408 (T_ATP_CUSTOM_INFO *) (gsm_custom_info_p), \ | |
409 OPEN_PORT_OK) != RV_OK) | |
410 { | |
411 (void) rvf_free_buf ((T_RVF_BUFFER *) (gsm_custom_info_p)); | |
412 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
413 " ATP-UART (handle_msg). Unable to open the virtual modem port with the AT Parser "); | |
414 return (RVM_INTERNAL_ERR); | |
415 } | |
416 rvf_send_trace (" ATP-UART (handle_msg). Virtual modem port properly established with the AT Parser ", | |
417 84, | |
418 NULL_PARAM, | |
419 RV_TRACE_LEVEL_DEBUG_LOW, | |
420 ATP_USE_ID); | |
421 | |
422 /* The virtual modem port opened with the AT Parser is */ | |
423 /* now properly initialized. */ | |
424 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_established = TRUE; | |
425 | |
426 /* If needed, de-allocate custom information contained */ | |
427 /* in the 'ATP Open Port Indication'. */ | |
428 if (((T_ATP_OPEN_PORT_IND *) incoming_message_p)->custom_info_p != NULL) | |
429 { | |
430 rvf_free_buf ((T_RVF_BUFFER *) (((T_ATP_OPEN_PORT_IND *) (incoming_message_p))->custom_info_p)); | |
431 } | |
432 break; | |
433 } | |
434 | |
435 /* 'ATP Text Command Ready'. */ | |
436 case ATP_TXT_CMD_RDY: | |
437 { | |
438 | |
439 /* Declare local block variables. */ | |
440 UINT8 txt_cmd_length = 0x00; | |
441 T_ATP_TXT_CMD_RDY *txt_cmd_rdy_p = (T_ATP_TXT_CMD_RDY *) (incoming_message_p); | |
442 | |
443 rvf_send_trace (" ATP-UART (handle_msg). 'ATP Text Command Ready' received ", | |
444 59, | |
445 NULL_PARAM, | |
446 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
447 ATP_USE_ID); | |
448 | |
449 /* If any error occurred, then abort. */ | |
450 if ((txt_cmd_rdy_p->port_nb != ATP_UART_GSM_PORT_NB) || \ | |
451 (txt_cmd_rdy_p->txt_cmd_p == NULL)) | |
452 { | |
453 rvf_send_trace (" ATP-UART (handle_msg). 'Text Command' transfer failed ", | |
454 56, | |
455 NULL_PARAM, | |
456 RV_TRACE_LEVEL_WARNING, | |
457 ATP_USE_ID); | |
458 break; | |
459 } | |
460 | |
461 /* Get the length of the 'Text Command'. Note that such */ | |
462 /* a 'Text Command' is a NULL-terminated string. */ | |
463 txt_cmd_length = (UINT8) (strlen (txt_cmd_rdy_p->txt_cmd_p)); | |
464 rvf_send_trace (txt_cmd_rdy_p->txt_cmd_p, | |
465 txt_cmd_length, | |
466 NULL_PARAM, | |
467 RV_TRACE_LEVEL_DEBUG_LOW, | |
468 ATP_USE_ID); | |
469 | |
470 /* Forward the 'Text Command' to the COM port. If any */ | |
471 /* error occurred, then proceed. */ | |
472 txt_cmd_rdy_p->txt_cmd_p[txt_cmd_length] = ATP_CR_CHARACTER; | |
473 if (atp_uart_write_com_port ((UINT8 *) (txt_cmd_rdy_p->txt_cmd_p), \ | |
474 (txt_cmd_length + 0x00000001)) != RV_OK) | |
475 { | |
476 rvf_send_trace (" ATP-UART (handle_msg). 'Text Command' transfer failed ", | |
477 56, | |
478 NULL_PARAM, | |
479 RV_TRACE_LEVEL_WARNING, | |
480 ATP_USE_ID); | |
481 } | |
482 | |
483 /* De-allocate the data buffer provided with the 'ATP */ | |
484 /* Command Ready'. */ | |
485 (void) rvf_free_buf ((T_RVF_BUFFER *) (txt_cmd_rdy_p->txt_cmd_p)); | |
486 break; | |
487 } | |
488 | |
489 /* 'ATP No Copy Data Ready'. */ | |
490 case ATP_NO_COPY_DATA_RDY: | |
491 { | |
492 | |
493 /* Declare a local block variable. */ | |
494 T_ATP_NO_COPY_DATA_RDY *no_copy_data_rdy_p = (T_ATP_NO_COPY_DATA_RDY *) (incoming_message_p); | |
495 | |
496 rvf_send_trace (" ATP-UART (handle_msg). 'ATP No Copy Data Ready' received ", | |
497 59, | |
498 NULL_PARAM, | |
499 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
500 ATP_USE_ID); | |
501 | |
502 /* If any error occurred, then abort. */ | |
503 if ((no_copy_data_rdy_p->port_nb != ATP_UART_GSM_PORT_NB) || \ | |
504 (no_copy_data_rdy_p->atp_buffer_p == NULL)) | |
505 { | |
506 rvf_send_trace (" ATP-UART (handle_msg). Data transfer to the COM port failed ", | |
507 62, | |
508 NULL_PARAM, | |
509 RV_TRACE_LEVEL_WARNING, | |
510 ATP_USE_ID); | |
511 break; | |
512 } | |
513 rvf_send_trace (" ATP-UART (handle_msg). Data size ", | |
514 35, | |
515 no_copy_data_rdy_p->buffer_size, | |
516 RV_TRACE_LEVEL_DEBUG_LOW, | |
517 ATP_USE_ID); | |
518 | |
519 /* Forward data to the COM port. If any error occurred, */ | |
520 /* then proceed. */ | |
521 if (atp_uart_write_com_port (no_copy_data_rdy_p->atp_buffer_p, \ | |
522 no_copy_data_rdy_p->buffer_size) != RV_OK) | |
523 { | |
524 rvf_send_trace (" ATP-UART (handle_msg). Data transfer to the COM port failed ", | |
525 62, | |
526 NULL_PARAM, | |
527 RV_TRACE_LEVEL_WARNING, | |
528 ATP_USE_ID); | |
529 } | |
530 | |
531 /* De-allocate the data buffer provided with the 'ATP */ | |
532 /* No Copy Data Ready'. */ | |
533 (void) rvf_free_buf ((T_RVF_BUFFER *) (no_copy_data_rdy_p->atp_buffer_p)); | |
534 break; | |
535 } | |
536 | |
537 /* 'ATP Signal Changed'. */ | |
538 case ATP_SIGNAL_CHANGED: | |
539 { | |
540 | |
541 /* Declare a local block variable. */ | |
542 T_ATP_SIGNAL_CHANGED *signal_changed_p = (T_ATP_SIGNAL_CHANGED *) (incoming_message_p); | |
543 | |
544 rvf_send_trace (" ATP-UART (handle_msg). 'ATP Signal Changed' received ", | |
545 55, | |
546 NULL_PARAM, | |
547 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
548 ATP_USE_ID); | |
549 | |
550 /* If any error occurred, then abort. */ | |
551 if (signal_changed_p->port_nb != ATP_UART_GSM_PORT_NB) | |
552 { | |
553 rvf_send_trace (" ATP-UART (handle_msg). Invalid port number ", | |
554 45, | |
555 NULL_PARAM, | |
556 RV_TRACE_LEVEL_WARNING, | |
557 ATP_USE_ID); | |
558 break; | |
559 } | |
560 rvf_send_trace (" ATP-UART (handle_msg). Bit mask ", | |
561 34, | |
562 signal_changed_p->signal, | |
563 RV_TRACE_LEVEL_DEBUG_LOW, | |
564 ATP_USE_ID); | |
565 | |
566 /* Update the RS232 control signals associated with the */ | |
567 /* virtual modem port. */ | |
568 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).control_signals = signal_changed_p->signal; | |
569 break; | |
570 } | |
571 | |
572 /* 'ATP Port Mode Changed'. */ | |
573 case ATP_PORT_MODE_CHANGED: | |
574 { | |
575 | |
576 /* Declare a local block variable. */ | |
577 T_ATP_PORT_MODE_CHANGED *port_mode_changed_p = (T_ATP_PORT_MODE_CHANGED *) (incoming_message_p); | |
578 | |
579 rvf_send_trace (" ATP-UART (handle_msg). 'ATP Port Mode Changed' received ", | |
580 58, | |
581 NULL_PARAM, | |
582 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
583 ATP_USE_ID); | |
584 | |
585 /* If any error occurred, then abort. */ | |
586 if (port_mode_changed_p->port_nb != ATP_UART_GSM_PORT_NB) | |
587 { | |
588 rvf_send_trace (" ATP-UART (handle_msg). Invalid port number ", | |
589 45, | |
590 NULL_PARAM, | |
591 RV_TRACE_LEVEL_WARNING, | |
592 ATP_USE_ID); | |
593 break; | |
594 } | |
595 rvf_send_trace (" ATP-UART (handle_msg). Mode ", | |
596 30, | |
597 port_mode_changed_p->mode, | |
598 RV_TRACE_LEVEL_DEBUG_LOW, | |
599 ATP_USE_ID); | |
600 | |
601 /* If the virtual modem port is in 'Data' mode, then */ | |
602 /* send the escape sequence first. */ | |
603 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_mode == ATP_PORT_DATA_MODE) | |
604 { | |
605 | |
606 /* Forward the escape sequence to the COM port. If */ | |
607 /* any error occurred, then call the function used */ | |
608 /* whenever any unrecoverable error occurs and */ | |
609 /* abort. */ | |
610 if (atp_uart_write_com_port ((UINT8 *) (ATP_ESCAPE_SEQUENCE), \ | |
611 (sizeof (ATP_ESCAPE_SEQUENCE) - 0x00000001)) != RV_OK) | |
612 { | |
613 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR, | |
614 " ATP-UART (handle_msg). 'Escape sequence' not transmitted "); | |
615 return (RVM_INTERNAL_ERR); | |
616 } | |
617 rvf_send_trace (" ATP-UART (handle_msg). 'Escape sequence' properly transmitted ", | |
618 64, | |
619 NULL_PARAM, | |
620 RV_TRACE_LEVEL_DEBUG_LOW, | |
621 ATP_USE_ID); | |
622 } | |
623 | |
624 /* Update the mode of the virtual modem port. */ | |
625 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_mode = port_mode_changed_p->mode; | |
626 break; | |
627 } | |
628 | |
629 /* 'ATP Port Closed'. */ | |
630 case ATP_PORT_CLOSED: | |
631 { | |
632 rvf_send_trace (" ATP-UART (handle_msg). 'ATP Port Closed' received ", | |
633 52, | |
634 NULL_PARAM, | |
635 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
636 ATP_USE_ID); | |
637 | |
638 /* If any error occurred, then abort. */ | |
639 if (((T_ATP_PORT_CLOSED *) (incoming_message_p))->port_nb != ATP_UART_GSM_PORT_NB) | |
640 { | |
641 rvf_send_trace (" ATP-UART (handle_msg). Invalid port number ", | |
642 45, | |
643 NULL_PARAM, | |
644 RV_TRACE_LEVEL_WARNING, | |
645 ATP_USE_ID); | |
646 break; | |
647 } | |
648 | |
649 /* The virtual modem port opened with the AT Parser is */ | |
650 /* now closed. */ | |
651 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_established = FALSE; | |
652 break; | |
653 } | |
654 | |
655 /* 'ATP-UART Start GSM'. */ | |
656 case ATP_UART_START_GSM: | |
657 { | |
658 | |
659 /* Declare a local block variable. */ | |
660 UINT8 gsm_init_p[] = {'A', 'T', '+', 'C', 'F', 'U', 'N', '=', '1', ';', '+', 'C', 'O', 'P', 'S', '=', '0', \ | |
661 ATP_CR_CHARACTER}; | |
662 | |
663 rvf_send_trace (" ATP-UART (handle_msg). 'ATP-UART Start GSM' received ", | |
664 55, | |
665 NULL_PARAM, | |
666 RV_TRACE_LEVEL_DEBUG_MEDIUM, | |
667 ATP_USE_ID); | |
668 | |
669 /* If any error occurred, then abort. */ | |
670 if (atp_uart_write_com_port (gsm_init_p, \ | |
671 sizeof (gsm_init_p)) != RV_OK) | |
672 { | |
673 rvf_send_trace (" ATP-UART (handle_msg). Unable to start the GSM protocol stack ", | |
674 64, | |
675 NULL_PARAM, | |
676 RV_TRACE_LEVEL_WARNING, | |
677 ATP_USE_ID); | |
678 break; | |
679 } | |
680 break; | |
681 } | |
682 | |
683 /* Unexpected message. */ | |
684 default: | |
685 { | |
686 rvf_send_trace (" ATP-UART (handle_msg). Unexpected message received ", | |
687 53, | |
688 incoming_message_p->msg_id, | |
689 RV_TRACE_LEVEL_WARNING, | |
690 ATP_USE_ID); | |
691 break; | |
692 } | |
693 } | |
694 (void) rvf_free_buf ((T_RVF_BUFFER *) (incoming_message_p)); | |
695 } | |
696 | |
697 /* Now, if the flow control is activated, then proceed without getting */ | |
698 /* any data from the COM port. */ | |
699 if (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).control_signals & ATP_RX_FLOW_UNMASK) == ATP_RX_FLOW_ON) | |
700 { | |
701 continue; | |
702 } | |
703 | |
704 /* Otherwise, attempt forwarding data to the AT Parser. Thus, */ | |
705 /* initialize the amount of data to be forwarded. */ | |
706 in_buffer_size = (UINT32) (ATP_UART_MAX_PACKET_SIZE - \ | |
707 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left); | |
708 | |
709 /* Then, wait for data from the COM port. If any error occurred, then */ | |
710 /* abort. */ | |
711 if (atp_uart_read_com_port (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[(gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left]), \ | |
712 &in_buffer_size) != RV_OK) | |
713 { | |
714 rvf_send_trace (" ATP-UART (handle_msg). Failed in getting data from the COM port ", | |
715 66, | |
716 NULL_PARAM, | |
717 RV_TRACE_LEVEL_WARNING, | |
718 ATP_USE_ID); | |
719 continue; | |
720 } | |
721 | |
722 /* Take new data into account. */ | |
723 in_buffer_size = (UINT32) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left + \ | |
724 in_buffer_size); | |
725 | |
726 /* If no virtual modem port established with the AT Parser or if no */ | |
727 /* data pending for transmission to the AT Parser, then update the */ | |
728 /* number of bytes left and proceed. */ | |
729 if (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_established == FALSE) || \ | |
730 (in_buffer_size == 0x00000000)) | |
731 { | |
732 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = in_buffer_size; | |
733 continue; | |
734 } | |
735 | |
736 /* Otherwise, re-initialize the number of bytes left. */ | |
737 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = 0x00000000; | |
738 rvf_send_trace (" ATP-UART (handle_msg). Get data from the COM port ", | |
739 52, | |
740 in_buffer_size, | |
741 RV_TRACE_LEVEL_DEBUG_LOW, | |
742 ATP_USE_ID); | |
743 | |
744 /* At last, depending on the mode, transfert data from the COM port as */ | |
745 /* 'Text Command' or 'Data'. */ | |
746 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_mode == ATP_PORT_CMD_MODE) | |
747 { | |
748 | |
749 /* Declare local block variables. */ | |
750 UINT32 in_buffer_begin = 0x00000000; | |
751 UINT32 in_buffer_end = 0x00000000; | |
752 T_ATP_CMD *cmd_info_p = NULL; | |
753 T_ATP_CMD_NB cmd_nb = 0x0000; | |
754 T_ATP_TXT_CMD txt_cmd_p = NULL; | |
755 T_ATP_CMD_TYPE cmd_type = UNKNOWN; | |
756 | |
757 /* Send every 'Text Command' to the AT Parser separately. */ | |
758 while (in_buffer_end < in_buffer_size) | |
759 { | |
760 | |
761 /* Skip leading <CR> and <LF> characters. */ | |
762 for (in_buffer_begin = in_buffer_end; | |
763 (in_buffer_begin < in_buffer_size) && \ | |
764 (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin] == ATP_LF_CHARACTER) || \ | |
765 ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin] == ATP_CR_CHARACTER)); | |
766 in_buffer_begin++) | |
767 { | |
768 } | |
769 | |
770 /* Get the 'Text Command' length by searching for the ending */ | |
771 /* <CR> character. */ | |
772 for (in_buffer_end = in_buffer_begin; | |
773 (in_buffer_end < in_buffer_size) && \ | |
774 ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end] != ATP_CR_CHARACTER); | |
775 in_buffer_end++) | |
776 { | |
777 } | |
778 | |
779 /* Abort whether no ending <CR> character found. */ | |
780 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end] != ATP_CR_CHARACTER) | |
781 { | |
782 | |
783 /* Update the number of bytes left. */ | |
784 in_buffer_size -= in_buffer_begin; | |
785 | |
786 /* Defrag. */ | |
787 memcpy ((void *) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p), | |
788 (void *) (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin])), | |
789 in_buffer_size); | |
790 | |
791 /* Update the number of bytes left. */ | |
792 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = in_buffer_size; | |
793 break; | |
794 } | |
795 | |
796 /* Otherwise, replace the ending <CR> character by NULL. */ | |
797 /* Indeed, such a 'Text Command' must be a NULL-terminated */ | |
798 /* string. */ | |
799 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_end++] = '\x00'; | |
800 | |
801 /* Allocate memory in order to forward the 'Text Command' to */ | |
802 /* the AT Parser. If insufficient resources, then call the */ | |
803 /* function used whenever any unrecoverable error occurs and */ | |
804 /* abort. */ | |
805 if (rvf_get_buf (gbl_atp_uart_ctrl_blk_p->mb_id, \ | |
806 (in_buffer_end - in_buffer_begin), \ | |
807 (T_RVF_BUFFER **) (&txt_cmd_p)) == RVF_RED) | |
808 { | |
809 ATP_UART_UNRECOVERABLE_ERROR (RVM_MEMORY_ERR, | |
810 " ATP-UART (handle_msg). Insufficient resources "); | |
811 break; | |
812 } | |
813 | |
814 /* Copy the 'Text Command'. */ | |
815 memcpy ((void *) (txt_cmd_p), | |
816 (void *) (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_begin])), | |
817 (in_buffer_end - in_buffer_begin)); | |
818 rvf_send_trace (txt_cmd_p, | |
819 (UINT8) (in_buffer_end - in_buffer_begin - 0x01), | |
820 NULL_PARAM, | |
821 RV_TRACE_LEVEL_DEBUG_LOW, | |
822 ATP_USE_ID); | |
823 | |
824 /* Check whether the 'Text Command' is a final or an */ | |
825 /* unsolicited result code. */ | |
826 if ((atp_translate_txt_to_cmd (txt_cmd_p, \ | |
827 UNKNOWN, \ | |
828 &cmd_type, \ | |
829 &cmd_nb, \ | |
830 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
831 &cmd_info_p) == RV_OK) && \ | |
832 (cmd_type == RESULT_CODE)) | |
833 { | |
834 | |
835 /* If the 'Text Command' corresponds to the 'Connect' final */ | |
836 /* result code, then turn the 'Data Carrier Detect' on */ | |
837 /* before sending it to the AT Parser (See ITU-T */ | |
838 /* Recommendation V.250 ter page 32). If any error */ | |
839 /* occurred, then de-allocate the 'Text Command' and abort. */ | |
840 if (cmd_nb == ATP_CONNECT_NB) | |
841 { | |
842 if (atp_set_signal ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
843 ATP_UART_GSM_PORT_NB, \ | |
844 ATP_DCD_1, \ | |
845 ATP_DCD_UNMASK) != RV_OK) | |
846 { | |
847 (void) rvf_free_buf ((T_RVF_BUFFER *) (txt_cmd_p)); | |
848 | |
849 /* If needed, de-allocate the command-related */ | |
850 /* information. */ | |
851 if (cmd_info_p != NULL) | |
852 { | |
853 (void) rvf_free_buf ((T_RVF_BUFFER *) (cmd_info_p)); | |
854 } | |
855 rvf_send_trace (" ATP-UART (handle_msg). 'Data Carrier Detect' not turned on ", | |
856 61, | |
857 NULL_PARAM, | |
858 RV_TRACE_LEVEL_WARNING, | |
859 ATP_USE_ID); | |
860 break; | |
861 } | |
862 rvf_send_trace (" ATP-UART (handle_msg). 'Data Carrier Detect' properly turned on ", | |
863 66, | |
864 NULL_PARAM, | |
865 RV_TRACE_LEVEL_DEBUG_LOW, | |
866 ATP_USE_ID); | |
867 } | |
868 } | |
869 | |
870 /* Otherwise, the 'Text Command' is recognized as a preliminary */ | |
871 /* result code. */ | |
872 else | |
873 { | |
874 cmd_type = PRELIMINARY_RESULT_CODE; | |
875 } | |
876 | |
877 /* If needed, de-allocate the command-related information. */ | |
878 if (cmd_info_p != NULL) | |
879 { | |
880 (void) rvf_free_buf ((T_RVF_BUFFER *) (cmd_info_p)); | |
881 } | |
882 | |
883 /* Forward the 'Text Command' to the AT Parser. If any error */ | |
884 /* occurred, then de-allocate the 'Text Command' and abort. */ | |
885 if (atp_send_txt_cmd ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
886 ATP_UART_GSM_PORT_NB, \ | |
887 cmd_type, \ | |
888 txt_cmd_p) != RV_OK) | |
889 { | |
890 (void) rvf_free_buf ((T_RVF_BUFFER *) (txt_cmd_p)); | |
891 rvf_send_trace (" ATP-UART (handle_msg). 'Text Command' failed ", | |
892 47, | |
893 NULL_PARAM, | |
894 RV_TRACE_LEVEL_WARNING, | |
895 ATP_USE_ID); | |
896 break; | |
897 } | |
898 } | |
899 } | |
900 else | |
901 { | |
902 | |
903 /* Declare local block variables. */ | |
904 UINT8 no_carrier_count = 0x00; | |
905 UINT8 no_carrier_p[] = {ATP_CR_CHARACTER, \ | |
906 ATP_LF_CHARACTER, \ | |
907 'N', 'O', ' ', 'C', 'A', 'R', 'R', 'I', 'E', 'R', \ | |
908 ATP_CR_CHARACTER, \ | |
909 ATP_LF_CHARACTER}; | |
910 UINT8 ok_count = 0x00; | |
911 UINT8 ok_p[] = {ATP_CR_CHARACTER, \ | |
912 ATP_LF_CHARACTER, \ | |
913 'O', 'K', \ | |
914 ATP_CR_CHARACTER, \ | |
915 ATP_LF_CHARACTER}; | |
916 UINT32 in_buffer_count = 0x00000000; | |
917 UINT32 in_data_size = 0x00000000; | |
918 T_ATP_CMD_NB result_code_nb = ATP_MAX_NB_OF_RESULT_CODES; | |
919 | |
920 /* First, search for 'Ok' or 'No Carrier' final result codes. */ | |
921 for (in_buffer_count = 0x00000000, \ | |
922 in_data_size = in_buffer_size; | |
923 in_buffer_count < in_buffer_size; | |
924 in_buffer_count++) | |
925 { | |
926 | |
927 /* Search for an 'Ok' final result code. */ | |
928 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_count] == ok_p[ok_count]) | |
929 { | |
930 | |
931 /* 'Ok' final result code detected. */ | |
932 if (++ok_count == sizeof (ok_p)) | |
933 { | |
934 result_code_nb = ATP_OK_NB; | |
935 rvf_send_trace (" ATP-UART (handle_msg). 'Ok' final result code detected ", | |
936 57, | |
937 NULL_PARAM, | |
938 RV_TRACE_LEVEL_DEBUG_LOW, | |
939 ATP_USE_ID); | |
940 | |
941 /* Send the remainder to the AT Parser. */ | |
942 in_data_size = in_buffer_count - (sizeof (ok_p) - 0x00000001); | |
943 break; | |
944 } | |
945 } | |
946 else | |
947 { | |
948 ok_count = 0x00; | |
949 } | |
950 | |
951 /* Search for a 'No Carrier' final result code. */ | |
952 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_count] == no_carrier_p[no_carrier_count]) | |
953 { | |
954 | |
955 /* 'No Carrier' final result code detected. */ | |
956 if (++no_carrier_count == sizeof (no_carrier_p)) | |
957 { | |
958 result_code_nb = ATP_NO_CARRIER_NB; | |
959 rvf_send_trace (" ATP-UART (handle_msg). 'No Carrier' final result code detected ", | |
960 65, | |
961 NULL_PARAM, | |
962 RV_TRACE_LEVEL_DEBUG_LOW, | |
963 ATP_USE_ID); | |
964 | |
965 /* Send the remainder to the AT Parser. */ | |
966 in_data_size = in_buffer_count - (sizeof (no_carrier_p) - 0x00000001); | |
967 break; | |
968 } | |
969 } | |
970 else | |
971 { | |
972 no_carrier_count = 0x00; | |
973 } | |
974 } | |
975 | |
976 /* Then, check for some bytes to be forwarded data to the AT */ | |
977 /* Parser. */ | |
978 if (in_data_size > 0x00000000) | |
979 { | |
980 | |
981 /* Forward data to the AT Parser. If any error occurred, then */ | |
982 /* proceed. */ | |
983 if (atp_send_data ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
984 ATP_UART_GSM_PORT_NB, \ | |
985 (void *) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p), \ | |
986 in_data_size, \ | |
987 &((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left)) != RV_OK) | |
988 { | |
989 rvf_send_trace (" ATP-UART (handle_msg). Data transfer to the AT Parser failed ", | |
990 63, | |
991 NULL_PARAM, | |
992 RV_TRACE_LEVEL_WARNING, | |
993 ATP_USE_ID); | |
994 } | |
995 | |
996 /* Update the number of bytes left. */ | |
997 in_data_size -= (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left; | |
998 in_buffer_size -= in_data_size; | |
999 | |
1000 /* Check whether some bytes left to be sent to the AT Parser. */ | |
1001 if ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left > 0x00000000) | |
1002 { | |
1003 | |
1004 /* Defrag. */ | |
1005 memcpy ((void *) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p), | |
1006 (void *) (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_data_size])), | |
1007 in_buffer_size); | |
1008 | |
1009 /* Update the number of bytes left. */ | |
1010 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = in_buffer_size; | |
1011 continue; | |
1012 } | |
1013 } | |
1014 | |
1015 /* At last, check whether an 'Ok' or a 'No Carrier' final result */ | |
1016 /* code was detected. */ | |
1017 if (result_code_nb != ATP_MAX_NB_OF_RESULT_CODES) | |
1018 { | |
1019 | |
1020 /* Turn the 'Data Carrier Detect' off before sending it to the */ | |
1021 /* AT Parser (See ITU-T Recommendation V.250 ter page 37). */ | |
1022 /* However, proceed whether any error occurred. */ | |
1023 if (((atp_set_signal ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
1024 ATP_UART_GSM_PORT_NB, \ | |
1025 ATP_DCD_0, \ | |
1026 ATP_DCD_UNMASK) != RV_OK) || \ | |
1027 (atp_send_cmd ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \ | |
1028 ATP_UART_GSM_PORT_NB, \ | |
1029 RESULT_CODE, \ | |
1030 result_code_nb, \ | |
1031 NULL) != RV_OK))) | |
1032 { | |
1033 rvf_send_trace (" ATP-UART (handle_msg). Final result code not transmitted ", | |
1034 59, | |
1035 NULL_PARAM, | |
1036 RV_TRACE_LEVEL_WARNING, | |
1037 ATP_USE_ID); | |
1038 } | |
1039 | |
1040 /* Update the number of bytes left. */ | |
1041 in_buffer_size -= in_buffer_count; | |
1042 | |
1043 /* Update the mode of the virtual modem port. */ | |
1044 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_mode = ATP_PORT_CMD_MODE; | |
1045 } | |
1046 | |
1047 /* If some data left, then defrag. */ | |
1048 memcpy ((void *) ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p), | |
1049 (void *) (&((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).in_buffer_p[in_buffer_count])), | |
1050 in_buffer_size); | |
1051 | |
1052 /* Update the number of bytes left. */ | |
1053 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).nb_bytes_left = in_buffer_size; | |
1054 } | |
1055 } | |
1056 return (RVM_OK); | |
1057 | |
1058 } /********************* End of atp_uart_handle_msg function ********************/ |