FreeCalypso > hg > fc-magnetite
comparison src/g23m-fad/tcpip/socket_api.c @ 174:90eb61ecd093
src/g23m-fad: initial import from TCS3.2/LoCosto
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Oct 2016 05:40:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
173:bf64d785238a | 174:90eb61ecd093 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: socket.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2002 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : This file implements the socket API functionality. | |
17 | For a description of this file read g23m\condat\doc\8462_601.doc | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef SAP_DCM | |
22 #define SAP_DCM | |
23 #endif /* !SAP_DCM */ | |
24 | |
25 #define ENTITY_TCPIP | |
26 | |
27 #include <string.h> | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 | |
31 #include "socket_api.h" | |
32 | |
33 #include "custom.h" | |
34 #include "pei.h" | |
35 #include "socket_int.h" | |
36 #include "dcm.h" | |
37 #include "aci_all.h" | |
38 | |
39 | |
40 LOCAL const int UNUSED = 0; | |
41 | |
42 /* this function maps the DCM result codes to the Socket-API result codes */ | |
43 LOCAL T_SOCK_RESULT map_dcm_result_code(S32 result) | |
44 { | |
45 switch(result) | |
46 { | |
47 case DCM_OK: return SOCK_RESULT_OK; | |
48 case DCM_NOT_READY: return SOCK_RESULT_NOT_READY; | |
49 case DCM_ALREADY_ACTIVATED: return SOCK_RESULT_BEARER_ACTIVE; | |
50 case DCM_UNKNOWN_EVENT: return SOCK_RESULT_INTERNAL_ERROR; | |
51 case DCM_INVALID_PARAMETER: return SOCK_RESULT_INVALID_PARAMETER; | |
52 case DCM_BUSY: return SOCK_RESULT_IN_PROGRESS; | |
53 case DCM_PS_CONN_BROKEN: return SOCK_RESULT_NETWORK_LOST; | |
54 case DCM_NO_NETWORK: return SOCK_RESULT_BEARER_NOT_READY; | |
55 default: return SOCK_RESULT_INTERNAL_ERROR; | |
56 } | |
57 } | |
58 | |
59 | |
60 /******************************************************************************* | |
61 ** Function : FindSocketData | |
62 ** Parameter : T_SOCK_API_INSTANCE_DATA* | |
63 ** T_SOCK_SOCKET | |
64 ** Description : The function returns a pointer to the data structure of a socket. | |
65 ** If the socket does not exist or api_data is NULL, | |
66 ** then it returns NULL. | |
67 *******************************************************************************/ | |
68 LOCAL T_SOCK_SOCKET_DATA* FindSocketData(T_SOCK_API_INSTANCE_DATA* api_data, | |
69 T_SOCK_SOCKET tcpip_socket) | |
70 { | |
71 T_SOCK_SOCKET_DATA* socket_data; | |
72 | |
73 TRACE_FUNCTION("FindSocketData()"); | |
74 | |
75 /* must be checked whether api_data is NULL or not.*/ | |
76 if(api_data != NULL) | |
77 socket_data = api_data->socket_data; | |
78 else | |
79 { | |
80 TRACE_ERROR("FindSocketData: api_data = NULL!"); | |
81 return NULL; | |
82 } | |
83 | |
84 while((socket_data != NULL) && (tcpip_socket != socket_data->tcpip_socket)) | |
85 { | |
86 socket_data = socket_data->next_socket_data; | |
87 } | |
88 | |
89 TRACE_EVENT_P2("FindSocketData: tcpip_data=%x, ret=%x",tcpip_socket,socket_data ); | |
90 return socket_data; | |
91 } /* FindSocketData */ | |
92 | |
93 | |
94 | |
95 /******************************************************************************* | |
96 ** Function : ReleaseSocketData | |
97 ** Parameter : T_SOCK_API_INSTANCE_DATA* | |
98 ** T_SOCK_SOCKET_DATA* | |
99 ** Description : The function releases the specified socket data. | |
100 *******************************************************************************/ | |
101 static void ReleaseSocketData(T_SOCK_API_INSTANCE_DATA* api_data, | |
102 T_SOCK_SOCKET_DATA* socket_data) | |
103 { | |
104 T_SOCK_SOCKET_DATA* temp_socket_data; | |
105 | |
106 TRACE_FUNCTION("ReleaseSocketData()"); | |
107 | |
108 /* take socket data from linked list */ | |
109 if(api_data->socket_data == socket_data) | |
110 { | |
111 api_data->socket_data = socket_data->next_socket_data; | |
112 } | |
113 else | |
114 { | |
115 temp_socket_data = api_data->socket_data; | |
116 while(temp_socket_data->next_socket_data != socket_data) | |
117 { | |
118 temp_socket_data = temp_socket_data->next_socket_data; | |
119 } | |
120 temp_socket_data->next_socket_data = socket_data->next_socket_data; | |
121 } | |
122 | |
123 /* release socket data */ | |
124 MFREE(socket_data); | |
125 } /* ReleaseSocketData */ | |
126 | |
127 | |
128 /******************************************************************************/ | |
129 BOOL sock_api_initialize(T_SOCK_API_INSTANCE *api_instance, | |
130 T_HANDLE app_handle, | |
131 char* app_name) | |
132 { | |
133 T_SOCK_API_INSTANCE_DATA* api_data_p; | |
134 T_HANDLE hCommAPP; | |
135 T_HANDLE hCommTCPIP; | |
136 T_HANDLE hCommDCM; | |
137 | |
138 TRACE_FUNCTION("[Socket API] sock_api_initialize()"); | |
139 | |
140 /* open communication handles */ | |
141 if((hCommTCPIP = vsi_c_open (app_handle, TCPIP_NAME)) < VSI_OK) | |
142 { | |
143 TRACE_ERROR( "sock_api_initialize: vsi_c_open(TCP) failed"); | |
144 return FALSE; | |
145 } | |
146 | |
147 if((hCommAPP = vsi_c_open (app_handle, app_name)) < VSI_OK) | |
148 { | |
149 TRACE_ERROR( "sock_api_initialize: vsi_c_open(APP) failed"); | |
150 return FALSE; | |
151 } | |
152 | |
153 if((hCommDCM = vsi_c_open (app_handle, DCM_NAME)) < VSI_OK) | |
154 { | |
155 TRACE_ERROR( "sock_api_initialize: vsi_c_open(DCM) failed"); | |
156 return FALSE; | |
157 } | |
158 /* initialization successful */ | |
159 | |
160 /* allocate API Data structure */ | |
161 MALLOC(api_data_p, sizeof(T_SOCK_API_INSTANCE_DATA)); | |
162 | |
163 /*initialize API Data */ | |
164 api_data_p->app_handle = app_handle; | |
165 api_data_p->hCommAPP = hCommAPP; | |
166 api_data_p->hCommTCPIP = hCommTCPIP; | |
167 api_data_p->hCommDCM = hCommDCM; | |
168 api_data_p->socket_data = NULL; | |
169 | |
170 /* derefernce 'api_instance' and save address of 'api_data' */ | |
171 *api_instance = (T_SOCK_API_INSTANCE)api_data_p; | |
172 return TRUE; | |
173 } /* sock_api_initialize */ | |
174 | |
175 | |
176 /******************************************************************************/ | |
177 void sock_api_deinitialize(T_SOCK_API_INSTANCE api_instance) | |
178 { | |
179 T_SOCK_API_INSTANCE_DATA* api_data_p; | |
180 T_SOCK_SOCKET_DATA* socket_data1; | |
181 T_SOCK_SOCKET_DATA* socket_data2; | |
182 | |
183 TRACE_FUNCTION("[Socket API] sock_api_deinitialize()"); | |
184 | |
185 /* get the address of 'api_data' */ | |
186 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
187 | |
188 /*close communication channels */ | |
189 vsi_c_close (api_data_p->app_handle, api_data_p->hCommAPP); | |
190 vsi_c_close (api_data_p->app_handle, api_data_p->hCommTCPIP); | |
191 vsi_c_close (api_data_p->app_handle, api_data_p->hCommDCM); | |
192 | |
193 /* release all socket data */ | |
194 socket_data1 = api_data_p->socket_data; | |
195 | |
196 while(socket_data1 != NULL) | |
197 { | |
198 socket_data2 = socket_data1; | |
199 socket_data1 = socket_data1->next_socket_data; | |
200 MFREE(socket_data2); | |
201 } | |
202 | |
203 /* release API data */ | |
204 MFREE(api_data_p); | |
205 } | |
206 | |
207 | |
208 /******************************************************************************/ | |
209 T_SOCK_RESULT sock_open_bearer(T_SOCK_API_INSTANCE api_instance, | |
210 T_SOCK_BEARER_TYPE bearer_select, | |
211 int profile_number, | |
212 T_SOCK_BEARER_INFO *params, | |
213 T_SOCK_CALLBACK sock_cb, | |
214 void *context) | |
215 { | |
216 T_SOCK_API_INSTANCE_DATA* api_data_p; | |
217 | |
218 TRACE_FUNCTION("[Socket API] sock_open_bearer()"); | |
219 | |
220 if(sock_cb EQ NULL) | |
221 return SOCK_RESULT_INVALID_PARAMETER; | |
222 | |
223 /* set API data pointer */ | |
224 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
225 api_data_p->context = context; | |
226 api_data_p->callback = sock_cb; | |
227 | |
228 /* send primitive to DCM */ | |
229 { | |
230 PALLOC(dcm_open_conn_req, DCM_OPEN_CONN_REQ); | |
231 dcm_open_conn_req->api_instance = api_instance; | |
232 dcm_open_conn_req->bearer_select = bearer_select; | |
233 dcm_open_conn_req->profile_number = profile_number; | |
234 | |
235 dcm_open_conn_req->dcm_info_conn.bearer_handle = UNUSED; | |
236 dcm_open_conn_req->dcm_info_conn.app_handle = params->app_handle; | |
237 dcm_open_conn_req->dcm_info_conn.bearer_type = params->bearer_type; | |
238 dcm_open_conn_req->dcm_info_conn.apn_valid = params->apn_valid; | |
239 memcpy(dcm_open_conn_req->dcm_info_conn.apn, params->apn, SOCK_MAX_APN_LEN+1); | |
240 dcm_open_conn_req->dcm_info_conn.phone_number_valid = params->phone_nr_valid; | |
241 memcpy(dcm_open_conn_req->dcm_info_conn.phone_number, params->phone_nr, | |
242 SOCK_MAX_PHONENUM_LEN+1); | |
243 dcm_open_conn_req->dcm_info_conn.user_id_valid = params->user_id_valid; | |
244 memcpy(dcm_open_conn_req->dcm_info_conn.user_id, params->user_id, | |
245 SOCK_MAX_USERID_LEN+1); | |
246 dcm_open_conn_req->dcm_info_conn.password_valid = params->password_valid; | |
247 memcpy(dcm_open_conn_req->dcm_info_conn.password, params->password, | |
248 SOCK_MAX_PASSWORD_LEN+1); | |
249 dcm_open_conn_req->dcm_info_conn.cid = params->cid; | |
250 dcm_open_conn_req->dcm_info_conn.ip_address = params->ip_address; | |
251 dcm_open_conn_req->dcm_info_conn.dns1 = params->dns1; | |
252 dcm_open_conn_req->dcm_info_conn.dns2 = params->dns2; | |
253 dcm_open_conn_req->dcm_info_conn.gateway = params->gateway; | |
254 dcm_open_conn_req->dcm_info_conn.auth_type = params->authtype; | |
255 dcm_open_conn_req->dcm_info_conn.data_compr = params->data_compr; | |
256 dcm_open_conn_req->dcm_info_conn.header_compr = params->header_comp; | |
257 dcm_open_conn_req->dcm_info_conn.precedence = params->precedence; | |
258 dcm_open_conn_req->dcm_info_conn.delay = params->precedence; | |
259 dcm_open_conn_req->dcm_info_conn.reliability = params->reliability; | |
260 dcm_open_conn_req->dcm_info_conn.peak_throughput = params->peak_throughput; | |
261 dcm_open_conn_req->dcm_info_conn.mean_throughput = params->mean_througput; | |
262 dcm_open_conn_req->dcm_info_conn.shareable = params->shareable; | |
263 | |
264 PSEND(api_data_p->hCommDCM, dcm_open_conn_req); | |
265 } | |
266 return SOCK_RESULT_OK; | |
267 } | |
268 | |
269 /******************************************************************************/ | |
270 LOCAL void sock_open_bearer_cnf(T_DCM_OPEN_CONN_CNF *dcm_open_conn_cnf, | |
271 T_SOCK_API_INSTANCE api_instance) | |
272 { | |
273 T_SOCK_OPEN_BEARER_CNF sock_open_bearer_cnf; | |
274 T_SOCK_API_INSTANCE_DATA *api_data_p; | |
275 | |
276 TRACE_FUNCTION("[Socket API] sock_open_bearer_cnf()"); | |
277 | |
278 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
279 | |
280 /* fill signal struct */ | |
281 sock_open_bearer_cnf.result = map_dcm_result_code(dcm_open_conn_cnf->result); | |
282 sock_open_bearer_cnf.socket = UNUSED; | |
283 sock_open_bearer_cnf.event_type = SOCK_OPEN_BEARER_CNF; | |
284 sock_open_bearer_cnf.bearer_handle = dcm_open_conn_cnf->bearer_handle; | |
285 | |
286 /* release primitive */ | |
287 PFREE(dcm_open_conn_cnf); | |
288 | |
289 api_data_p->callback((T_SOCK_EVENTSTRUCT *)&sock_open_bearer_cnf, | |
290 api_data_p->context); | |
291 } | |
292 | |
293 /******************************************************************************/ | |
294 T_SOCK_RESULT sock_close_bearer(T_SOCK_API_INSTANCE api_instance, | |
295 T_SOCK_BEARER_HANDLE bearer_handle, | |
296 T_SOCK_CALLBACK sock_cb, | |
297 void *context) | |
298 { | |
299 T_SOCK_API_INSTANCE_DATA* api_data_p; | |
300 | |
301 TRACE_FUNCTION("[Socket API] sock_close_bearer()"); | |
302 | |
303 if(sock_cb EQ NULL) { | |
304 return SOCK_RESULT_INVALID_PARAMETER; | |
305 } | |
306 | |
307 /* set API data pointer */ | |
308 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
309 api_data_p->callback = sock_cb; | |
310 api_data_p->context = context; | |
311 | |
312 /* send primitive to DCM */ | |
313 { | |
314 PALLOC(dcm_close_conn_req, DCM_CLOSE_CONN_REQ); | |
315 dcm_close_conn_req->api_instance = api_instance; | |
316 dcm_close_conn_req->bearer_handle = bearer_handle; | |
317 PSEND(api_data_p->hCommDCM, dcm_close_conn_req); | |
318 } | |
319 | |
320 return SOCK_RESULT_OK; | |
321 } | |
322 | |
323 /******************************************************************************/ | |
324 LOCAL void sock_close_bearer_cnf(T_DCM_CLOSE_CONN_CNF *dcm_close_conn_cnf, | |
325 T_SOCK_API_INSTANCE api_instance) | |
326 { | |
327 T_SOCK_CLOSE_BEARER_CNF sock_close_bearer_cnf; | |
328 T_SOCK_API_INSTANCE_DATA *api_data_p; | |
329 | |
330 TRACE_FUNCTION("[Socket API] dcm_close_conn_cnf()"); | |
331 | |
332 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
333 | |
334 sock_close_bearer_cnf.result = map_dcm_result_code(dcm_close_conn_cnf->result); | |
335 sock_close_bearer_cnf.socket = UNUSED; | |
336 sock_close_bearer_cnf.event_type = SOCK_CLOSE_BEARER_CNF; | |
337 | |
338 /* release primitive */ | |
339 PFREE(dcm_close_conn_cnf); | |
340 | |
341 /* call callback function */ | |
342 api_data_p->callback((T_SOCK_EVENTSTRUCT *)&sock_close_bearer_cnf, | |
343 api_data_p->context); | |
344 } | |
345 | |
346 /******************************************************************************/ | |
347 T_SOCK_RESULT sock_bearer_info(T_SOCK_API_INSTANCE api_instance, | |
348 T_SOCK_BEARER_HANDLE bearer_handle, | |
349 T_SOCK_CALLBACK sock_cb, | |
350 void *context) | |
351 { | |
352 T_SOCK_API_INSTANCE_DATA* api_data_p; | |
353 | |
354 TRACE_FUNCTION("[Socket API] sock_bearer_info()"); | |
355 | |
356 if(sock_cb EQ NULL) | |
357 return SOCK_RESULT_INVALID_PARAMETER; | |
358 | |
359 /* set API data pointer */ | |
360 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
361 api_data_p->callback = sock_cb; | |
362 api_data_p->context = context; | |
363 | |
364 /* send primitive to DCM */ | |
365 { | |
366 PALLOC(dcm_get_current_conn_req, DCM_GET_CURRENT_CONN_REQ); | |
367 dcm_get_current_conn_req->api_instance = api_instance; | |
368 dcm_get_current_conn_req->bearer_handle = bearer_handle; | |
369 PSEND(api_data_p->hCommDCM, dcm_get_current_conn_req); | |
370 } | |
371 return SOCK_RESULT_OK; | |
372 } | |
373 | |
374 | |
375 /******************************************************************************/ | |
376 LOCAL void sock_bearer_info_cnf(T_DCM_GET_CURRENT_CONN_CNF *current_conn_cnf, | |
377 T_SOCK_API_INSTANCE api_instance) | |
378 { | |
379 T_SOCK_BEARER_INFO_CNF bearer_info; | |
380 T_SOCK_API_INSTANCE_DATA *api_data_p; | |
381 | |
382 TRACE_FUNCTION("[Socket API] sock_bearer_info_cnf()"); | |
383 | |
384 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
385 | |
386 bearer_info.result = map_dcm_result_code(current_conn_cnf->result); | |
387 bearer_info.socket = UNUSED; | |
388 bearer_info.event_type = SOCK_BEARER_INFO_CNF; | |
389 | |
390 bearer_info.bearer_params.bearer_handle = current_conn_cnf->dcm_info_conn.bearer_handle; | |
391 bearer_info.bearer_params.app_handle = current_conn_cnf->dcm_info_conn.app_handle; | |
392 bearer_info.bearer_params.bearer_type =(T_SOCK_BEARER_TYPE)current_conn_cnf->dcm_info_conn.bearer_type; | |
393 bearer_info.bearer_params.apn_valid = current_conn_cnf->dcm_info_conn.apn_valid; | |
394 memcpy(bearer_info.bearer_params.apn, | |
395 current_conn_cnf->dcm_info_conn.apn, SOCK_MAX_APN_LEN); | |
396 bearer_info.bearer_params.phone_nr_valid = current_conn_cnf->dcm_info_conn.phone_number_valid; | |
397 memcpy(bearer_info.bearer_params.phone_nr,current_conn_cnf->dcm_info_conn.phone_number, | |
398 SOCK_MAX_PHONENUM_LEN); | |
399 bearer_info.bearer_params.user_id_valid = current_conn_cnf->dcm_info_conn.user_id_valid; | |
400 memcpy(bearer_info.bearer_params.user_id, current_conn_cnf->dcm_info_conn.user_id, | |
401 SOCK_MAX_USERID_LEN); | |
402 bearer_info.bearer_params.password_valid = current_conn_cnf->dcm_info_conn.password_valid; | |
403 memcpy(bearer_info.bearer_params.password, current_conn_cnf->dcm_info_conn.password, | |
404 SOCK_MAX_PASSWORD_LEN); | |
405 bearer_info.bearer_params.cid = current_conn_cnf->dcm_info_conn.cid; | |
406 bearer_info.bearer_params.ip_address = current_conn_cnf->dcm_info_conn.ip_address; | |
407 bearer_info.bearer_params.dns1 = current_conn_cnf->dcm_info_conn.dns1; | |
408 bearer_info.bearer_params.dns2 = current_conn_cnf->dcm_info_conn.dns2; | |
409 bearer_info.bearer_params.gateway = current_conn_cnf->dcm_info_conn.gateway; | |
410 bearer_info.bearer_params.authtype = (T_SOCK_AUTHTYPE)current_conn_cnf->dcm_info_conn.auth_type; | |
411 bearer_info.bearer_params.data_compr = current_conn_cnf->dcm_info_conn.data_compr; | |
412 bearer_info.bearer_params.header_comp = current_conn_cnf->dcm_info_conn.header_compr; | |
413 bearer_info.bearer_params.precedence = current_conn_cnf->dcm_info_conn.precedence; | |
414 bearer_info.bearer_params.delay = current_conn_cnf->dcm_info_conn.delay; | |
415 bearer_info.bearer_params.reliability = current_conn_cnf->dcm_info_conn.reliability; | |
416 bearer_info.bearer_params.peak_throughput = current_conn_cnf->dcm_info_conn.peak_throughput; | |
417 bearer_info.bearer_params.mean_througput = current_conn_cnf->dcm_info_conn.mean_throughput; | |
418 bearer_info.bearer_params.shareable = current_conn_cnf->dcm_info_conn.shareable; | |
419 | |
420 /* release primitive */ | |
421 PFREE(current_conn_cnf); | |
422 | |
423 /* call callback function */ | |
424 api_data_p->callback((T_SOCK_EVENTSTRUCT *)&bearer_info, api_data_p->context); | |
425 } | |
426 | |
427 | |
428 /******************************************************************************/ | |
429 LOCAL void sock_dcm_error_ind(T_DCM_ERROR_IND *dcm_error_ind, | |
430 T_SOCK_API_INSTANCE api_instance) | |
431 { | |
432 T_SOCK_BAERER_CLOSED_IND sock_bearer_closed_ind; | |
433 T_SOCK_API_INSTANCE_DATA *api_data_p; | |
434 | |
435 TRACE_FUNCTION("[Socket API] sock_dcm_error_ind()"); | |
436 | |
437 api_data_p = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
438 | |
439 sock_bearer_closed_ind.event_type = SOCK_BAERER_CLOSED_IND; | |
440 sock_bearer_closed_ind.result = map_dcm_result_code(dcm_error_ind->result); | |
441 sock_bearer_closed_ind.socket = UNUSED; | |
442 sock_bearer_closed_ind.dcm_error = dcm_error_ind->dcm_err; | |
443 | |
444 PFREE(dcm_error_ind); | |
445 | |
446 if(api_data_p->callback NEQ NULL) | |
447 { | |
448 api_data_p->callback((T_SOCK_EVENTSTRUCT *)&sock_bearer_closed_ind, | |
449 api_data_p->context); | |
450 } | |
451 } | |
452 | |
453 | |
454 /* ******************* Socket related functions ***************************** */ | |
455 | |
456 /******************************************************************************/ | |
457 T_SOCK_RESULT sock_create(T_SOCK_API_INSTANCE api_instance, | |
458 T_SOCK_IPPROTO ipproto, | |
459 T_SOCK_CALLBACK callback, | |
460 void* context) | |
461 { | |
462 T_SOCK_API_INSTANCE_DATA* api_data; | |
463 T_SOCK_SOCKET_DATA* socket_data; | |
464 | |
465 TRACE_FUNCTION("[Socket API] sock_create()"); | |
466 TRACE_EVENT_P1("IP-Protocol=%d",(U32)ipproto); | |
467 | |
468 /* set api_data */ | |
469 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
470 | |
471 if(callback EQ NULL) | |
472 return SOCK_RESULT_INVALID_PARAMETER; | |
473 | |
474 /* check for correct data */ | |
475 if((ipproto != SOCK_IPPROTO_UDP) && (ipproto != SOCK_IPPROTO_TCP)) | |
476 { | |
477 TRACE_ERROR("[Socket API] Error: Invalid IP-Protocol"); | |
478 return SOCK_RESULT_INVALID_PARAMETER; | |
479 } | |
480 if( api_data == NULL ) | |
481 { | |
482 TRACE_ERROR("[Socket API] Error: api_instance == NULL!"); | |
483 return SOCK_RESULT_INVALID_PARAMETER; | |
484 } | |
485 | |
486 /* allocate socket data */ | |
487 MALLOC(socket_data, sizeof(T_SOCK_SOCKET_DATA)); | |
488 | |
489 /* put socket data in linked list */ | |
490 socket_data->next_socket_data = api_data->socket_data; | |
491 api_data->socket_data = socket_data; | |
492 | |
493 /* initialize socket data */ | |
494 socket_data->api_data = api_data; | |
495 socket_data->tcpip_socket = 0; | |
496 socket_data->callback = callback; | |
497 socket_data->context = context; | |
498 socket_data->rx_flow_control = SOCK_FLOW_XON; | |
499 socket_data->tx_flow_control = SOCK_FLOW_XON; | |
500 socket_data->rx_window = 1; | |
501 socket_data->tx_window = 1; | |
502 | |
503 /* send primitive to TCPIP */ | |
504 { | |
505 PALLOC(tcpip_create_req_prim, TCPIP_CREATE_REQ); | |
506 | |
507 tcpip_create_req_prim->app_handle = api_data->hCommAPP; | |
508 tcpip_create_req_prim->ipproto = ipproto; | |
509 tcpip_create_req_prim->request_id = (T_SOCK_SOCKET)socket_data; | |
510 | |
511 PSEND(api_data->hCommTCPIP, tcpip_create_req_prim); | |
512 } | |
513 | |
514 return SOCK_RESULT_OK; | |
515 }/* sock_create */ | |
516 | |
517 | |
518 /***************************************************************************************** | |
519 ** Function : sock_create_cnf | |
520 ** Parameter : T_TCPIP_CREATE_CNF * | |
521 ** T_SOCK_API_INSTANCE ' this value will be ignored in this function | |
522 ** because you can find socket_data only using request_id | |
523 *****************************************************************************************/ | |
524 LOCAL void sock_create_cnf(T_TCPIP_CREATE_CNF *tcpip_create_cnf, | |
525 T_SOCK_API_INSTANCE api_instance) | |
526 { | |
527 T_SOCK_SOCKET_DATA* socket_data; | |
528 T_SOCK_CREATE_CNF sock_create_cnf; | |
529 | |
530 TRACE_FUNCTION("[Socket API] sock_create_cnf()"); | |
531 | |
532 /* set socket data */ | |
533 socket_data = (T_SOCK_SOCKET_DATA*)tcpip_create_cnf->request_id; | |
534 | |
535 /* set received values */ | |
536 socket_data->tcpip_socket = tcpip_create_cnf->socket; | |
537 | |
538 /* fill confirm struct */ | |
539 sock_create_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_create_cnf->event_type; | |
540 sock_create_cnf.result = (T_SOCK_RESULT)tcpip_create_cnf->result; | |
541 sock_create_cnf.socket = (T_SOCK_SOCKET)socket_data; | |
542 | |
543 socket_data->callback((T_SOCK_EVENTSTRUCT *)&sock_create_cnf, socket_data->context); | |
544 | |
545 /* release socket data if context creation was not successful */ | |
546 if(tcpip_create_cnf->result != TCPIP_RESULT_OK) | |
547 { | |
548 TRACE_ERROR("[Socket API] Error: sock_create() failed"); | |
549 ReleaseSocketData(socket_data->api_data, socket_data); | |
550 } | |
551 | |
552 PFREE(tcpip_create_cnf); | |
553 }/* sock_create_cnf */ | |
554 | |
555 | |
556 /******************************************************************************/ | |
557 T_SOCK_RESULT sock_close(T_SOCK_SOCKET socket) | |
558 { | |
559 T_SOCK_API_INSTANCE_DATA* api_data; | |
560 T_SOCK_SOCKET_DATA* sock_data; | |
561 | |
562 TRACE_FUNCTION("[Socket API] sock_close()"); | |
563 | |
564 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
565 if(sock_data == NULL) | |
566 { | |
567 return SOCK_RESULT_INVALID_PARAMETER; | |
568 } | |
569 | |
570 api_data = sock_data->api_data; | |
571 | |
572 /* send primitive to TCPIP */ | |
573 { | |
574 PALLOC(tcpip_close_req_prim, TCPIP_CLOSE_REQ); | |
575 tcpip_close_req_prim->app_handle = api_data->hCommAPP; | |
576 tcpip_close_req_prim->socket = sock_data->tcpip_socket; | |
577 PSEND(api_data->hCommTCPIP, tcpip_close_req_prim); | |
578 } | |
579 return SOCK_RESULT_OK; | |
580 }/* sock_close */ | |
581 | |
582 | |
583 /******************************************************************************* | |
584 ** Function : sock_close_cnf | |
585 ** Parameter : T_SOCK_CLOSE_CNF * | |
586 *******************************************************************************/ | |
587 LOCAL void sock_close_cnf(T_TCPIP_CLOSE_CNF *tcpip_close_cnf, | |
588 T_SOCK_API_INSTANCE api_instance) | |
589 { | |
590 T_SOCK_SOCKET_DATA* sock_data; | |
591 T_SOCK_CLOSE_CNF sock_close_cnf; | |
592 T_SOCK_API_INSTANCE_DATA *api_data; | |
593 | |
594 TRACE_FUNCTION("[Socket API] sock_close_cnf()"); | |
595 | |
596 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
597 | |
598 sock_data = FindSocketData(api_data ,tcpip_close_cnf->socket); | |
599 if(sock_data == NULL) | |
600 { | |
601 PFREE(tcpip_close_cnf); | |
602 return; | |
603 } | |
604 | |
605 /* fill confirm struct */ | |
606 sock_close_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_close_cnf->event_type; | |
607 sock_close_cnf.result = (T_SOCK_RESULT)tcpip_close_cnf->result; | |
608 sock_close_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
609 | |
610 sock_data->callback(&sock_close_cnf, sock_data->context); | |
611 | |
612 /* release socket data if sock closing was successful */ | |
613 if(tcpip_close_cnf->result == TCPIP_RESULT_OK) | |
614 { | |
615 ReleaseSocketData(sock_data->api_data, sock_data); | |
616 } | |
617 | |
618 PFREE(tcpip_close_cnf); | |
619 }/* sock_close_cnf */ | |
620 | |
621 | |
622 /******************************************************************************/ | |
623 T_SOCK_RESULT sock_bind(T_SOCK_SOCKET socket, T_SOCK_PORT port) | |
624 { | |
625 T_SOCK_API_INSTANCE_DATA* api_data; | |
626 T_SOCK_SOCKET_DATA *sock_data; | |
627 | |
628 TRACE_FUNCTION("[Socket API] sock_bind()"); | |
629 | |
630 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
631 if(sock_data == NULL) | |
632 { | |
633 return SOCK_RESULT_INVALID_PARAMETER; | |
634 } | |
635 | |
636 api_data = sock_data->api_data; | |
637 { | |
638 PALLOC (tcpip_bind_req_prim, TCPIP_BIND_REQ); | |
639 tcpip_bind_req_prim->app_handle = api_data->hCommAPP; | |
640 tcpip_bind_req_prim->socket = sock_data->tcpip_socket; | |
641 tcpip_bind_req_prim->port = port; | |
642 PSEND(api_data->hCommTCPIP, tcpip_bind_req_prim); | |
643 } | |
644 return SOCK_RESULT_OK; | |
645 }/* sock_bind */ | |
646 | |
647 | |
648 /******************************************************************************* | |
649 ** Function : sock_bind_cnf | |
650 ** Parameter : T_SOCK_BIND_CNF * | |
651 ** T_SOCK_API_INSTANCE | |
652 *******************************************************************************/ | |
653 LOCAL void sock_bind_cnf(T_TCPIP_BIND_CNF *tcpip_bind_cnf, | |
654 T_SOCK_API_INSTANCE api_instance) | |
655 { | |
656 T_SOCK_SOCKET_DATA *sock_data; | |
657 T_SOCK_BIND_CNF sock_bind_cnf; | |
658 T_SOCK_API_INSTANCE_DATA *api_data; | |
659 | |
660 TRACE_FUNCTION("[Socket API] sock_bind_cnf()"); | |
661 | |
662 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
663 sock_data = FindSocketData(api_data ,tcpip_bind_cnf->socket); | |
664 if(sock_data == NULL) | |
665 { | |
666 PFREE(tcpip_bind_cnf); | |
667 return; | |
668 } | |
669 | |
670 /* fill confirm struct */ | |
671 sock_bind_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_bind_cnf->event_type; | |
672 sock_bind_cnf.result = (T_SOCK_RESULT)tcpip_bind_cnf->result; | |
673 sock_bind_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
674 | |
675 sock_data->callback(&sock_bind_cnf,sock_data->context); | |
676 | |
677 PFREE(tcpip_bind_cnf); | |
678 }/* sock_bind_cnf */ | |
679 | |
680 | |
681 /******************************************************************************/ | |
682 T_SOCK_RESULT sock_listen(T_SOCK_SOCKET socket ) | |
683 { | |
684 T_SOCK_API_INSTANCE_DATA* api_data; | |
685 T_SOCK_SOCKET_DATA* sock_data; | |
686 | |
687 TRACE_FUNCTION("[Socket API] sock_listen()"); | |
688 | |
689 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
690 if(sock_data == NULL) | |
691 { | |
692 TRACE_ERROR("[Socket API] listen() error: Invalid socket data"); | |
693 return SOCK_RESULT_INVALID_PARAMETER; | |
694 } | |
695 | |
696 api_data = sock_data->api_data; | |
697 { | |
698 PALLOC (tcpip_listen_req_prim, TCPIP_LISTEN_REQ); | |
699 tcpip_listen_req_prim->app_handle = api_data->hCommAPP; | |
700 tcpip_listen_req_prim->socket = sock_data->tcpip_socket; | |
701 PSEND(api_data->hCommTCPIP,tcpip_listen_req_prim ); | |
702 } | |
703 return SOCK_RESULT_OK; | |
704 }/* sock_listen */ | |
705 | |
706 | |
707 /******************************************************************************* | |
708 ** Function : sock_listen_cnf | |
709 ** Parameter : T_SOCK_LISTEN_CNF * | |
710 ** T_SOCK_API_INSTANCE | |
711 *******************************************************************************/ | |
712 LOCAL void sock_listen_cnf(T_TCPIP_LISTEN_CNF *tcpip_listen_cnf, | |
713 T_SOCK_API_INSTANCE api_instance ) | |
714 { | |
715 T_SOCK_SOCKET_DATA *sock_data; | |
716 T_SOCK_LISTEN_CNF sock_listen_cnf; | |
717 T_SOCK_API_INSTANCE_DATA *api_data; | |
718 | |
719 TRACE_FUNCTION("[Socket API] sock_listen_cnf()"); | |
720 | |
721 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
722 sock_data = FindSocketData(api_data ,tcpip_listen_cnf->socket); | |
723 if(sock_data == NULL) | |
724 { | |
725 PFREE(tcpip_listen_cnf); | |
726 return; | |
727 } | |
728 | |
729 /* fill confirm struct */ | |
730 sock_listen_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_listen_cnf->event_type; | |
731 sock_listen_cnf.result = (T_SOCK_RESULT)tcpip_listen_cnf->result; | |
732 sock_listen_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
733 | |
734 sock_data->callback(&sock_listen_cnf,sock_data->context); | |
735 | |
736 PFREE(tcpip_listen_cnf); | |
737 } /* sock_listen_cnf */ | |
738 | |
739 | |
740 /******************************************************************************/ | |
741 T_SOCK_RESULT sock_connect(T_SOCK_SOCKET socket, | |
742 T_SOCK_IPADDR ipaddr, | |
743 T_SOCK_PORT port) | |
744 { | |
745 T_SOCK_API_INSTANCE_DATA* api_data; | |
746 T_SOCK_SOCKET_DATA* sock_data; | |
747 | |
748 TRACE_FUNCTION("sock_connect()"); | |
749 | |
750 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
751 if(sock_data == NULL) | |
752 { | |
753 TRACE_ERROR("[Socket API] connect error: Invalid socket data"); | |
754 return SOCK_RESULT_INVALID_PARAMETER; | |
755 } | |
756 | |
757 api_data = sock_data->api_data; | |
758 { | |
759 PALLOC (tcpip_connect_req_prim, TCPIP_CONNECT_REQ); | |
760 tcpip_connect_req_prim->app_handle = api_data->hCommAPP; | |
761 tcpip_connect_req_prim->socket = sock_data->tcpip_socket; | |
762 tcpip_connect_req_prim->ipaddr = ipaddr; | |
763 tcpip_connect_req_prim->port = port; | |
764 PSEND(api_data->hCommTCPIP, tcpip_connect_req_prim); | |
765 } | |
766 return SOCK_RESULT_OK; | |
767 } /* sock_connect */ | |
768 | |
769 | |
770 /******************************************************************************* | |
771 ** Function : sock_connect_cnf | |
772 ** Parameter : T_SOCK_CONNECT_CNF * | |
773 ** T_SOCK_API_INSTANCE | |
774 *******************************************************************************/ | |
775 LOCAL void sock_connect_cnf(T_TCPIP_CONNECT_CNF *tcpip_connect_cnf, | |
776 T_SOCK_API_INSTANCE api_instance ) | |
777 { | |
778 T_SOCK_SOCKET_DATA *sock_data; | |
779 T_SOCK_CONNECT_CNF sock_connect_cnf; | |
780 T_SOCK_API_INSTANCE_DATA *api_data; | |
781 | |
782 TRACE_FUNCTION("sock_connect_cnf()"); | |
783 | |
784 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
785 | |
786 TRACE_EVENT_P3("api_data %d, socket %d, reslut %d",api_data, | |
787 tcpip_connect_cnf->socket,tcpip_connect_cnf->result); | |
788 | |
789 sock_data = FindSocketData(api_data ,tcpip_connect_cnf->socket); | |
790 if(sock_data == NULL) | |
791 { | |
792 TRACE_EVENT("sock data NULL !!!"); | |
793 PFREE(tcpip_connect_cnf); | |
794 return; | |
795 } | |
796 | |
797 /* fill confirm struct */ | |
798 sock_connect_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_connect_cnf->event_type; | |
799 sock_connect_cnf.result = (T_SOCK_RESULT)tcpip_connect_cnf->result; | |
800 sock_connect_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
801 | |
802 sock_data->callback(&sock_connect_cnf,sock_data->context); | |
803 | |
804 PFREE(tcpip_connect_cnf); | |
805 } /* sock_connect_cnf */ | |
806 | |
807 | |
808 /******************************************************************************/ | |
809 T_SOCK_RESULT sock_getsockname(T_SOCK_SOCKET socket) | |
810 { | |
811 T_SOCK_API_INSTANCE_DATA* api_data; | |
812 T_SOCK_SOCKET_DATA* sock_data; | |
813 | |
814 TRACE_FUNCTION("sock_getsockname()"); | |
815 | |
816 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
817 if(sock_data == NULL) | |
818 { | |
819 TRACE_ERROR("[Socket API] getsockname() error: Invalid socket data"); | |
820 return SOCK_RESULT_INVALID_PARAMETER; | |
821 } | |
822 api_data = sock_data->api_data; | |
823 | |
824 { | |
825 PALLOC(tcpip_sockname_req_prim, TCPIP_SOCKNAME_REQ); | |
826 tcpip_sockname_req_prim->app_handle = api_data->hCommAPP; | |
827 tcpip_sockname_req_prim->socket = sock_data->tcpip_socket; | |
828 PSEND(api_data->hCommTCPIP, tcpip_sockname_req_prim); | |
829 } | |
830 return SOCK_RESULT_OK; | |
831 } /* sock_getsockname */ | |
832 | |
833 | |
834 | |
835 /******************************************************************************* | |
836 ** Function : sock_connect_cnf | |
837 ** Parameter : T_SOCK_SOCKNAME_CNF * | |
838 ** T_SOCK_API_INSTANCE | |
839 *******************************************************************************/ | |
840 LOCAL void sock_sockname_cnf(T_TCPIP_SOCKNAME_CNF *tcpip_sockname_cnf, | |
841 T_SOCK_API_INSTANCE api_instance ) | |
842 { | |
843 T_SOCK_SOCKET_DATA *sock_data; | |
844 T_SOCK_SOCKNAME_CNF sock_sockname_cnf; | |
845 T_SOCK_API_INSTANCE_DATA *api_data; | |
846 | |
847 TRACE_FUNCTION("sock_getsockname_cnf()"); | |
848 | |
849 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
850 | |
851 sock_data = FindSocketData(api_data , tcpip_sockname_cnf->socket); | |
852 if(sock_data == NULL) | |
853 { | |
854 PFREE(tcpip_sockname_cnf); | |
855 return; | |
856 } | |
857 | |
858 /* fill confirm struct */ | |
859 sock_sockname_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_sockname_cnf->event_type; | |
860 sock_sockname_cnf.result = (T_SOCK_RESULT)tcpip_sockname_cnf->result; | |
861 sock_sockname_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
862 sock_sockname_cnf.ipaddr = tcpip_sockname_cnf->ipaddr; | |
863 sock_sockname_cnf.port = tcpip_sockname_cnf->port; | |
864 | |
865 sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_sockname_cnf,sock_data->context); | |
866 | |
867 PFREE(tcpip_sockname_cnf); | |
868 } /* sock_sockname_cnf */ | |
869 | |
870 | |
871 /******************************************************************************/ | |
872 T_SOCK_RESULT sock_getpeername(T_SOCK_SOCKET socket) | |
873 { | |
874 T_SOCK_API_INSTANCE_DATA* api_data; | |
875 T_SOCK_SOCKET_DATA* sock_data; | |
876 | |
877 TRACE_FUNCTION("sock_getpeername()"); | |
878 | |
879 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
880 api_data = sock_data->api_data; | |
881 | |
882 if((sock_data == NULL) OR (api_data == NULL)) | |
883 { | |
884 TRACE_ERROR("[Socket API] getpeername() error: Invalid socket data"); | |
885 return SOCK_RESULT_INVALID_PARAMETER; | |
886 } | |
887 | |
888 { | |
889 PALLOC (tcpip_peername_req_prim, TCPIP_PEERNAME_REQ); | |
890 tcpip_peername_req_prim->app_handle = api_data->hCommAPP; | |
891 tcpip_peername_req_prim->socket = sock_data->tcpip_socket; | |
892 PSEND(api_data->hCommTCPIP, tcpip_peername_req_prim); | |
893 } | |
894 return SOCK_RESULT_OK; | |
895 } /* sock_getpeername */ | |
896 | |
897 | |
898 /******************************************************************************* | |
899 ** Function : sock_peername_cnf | |
900 ** Parameter : T_SOCK_PEERNAME_CNF * | |
901 ** T_SOCK_API_INSTANCE | |
902 *******************************************************************************/ | |
903 LOCAL void sock_peername_cnf(T_TCPIP_PEERNAME_CNF *tcpip_peername_cnf, | |
904 T_SOCK_API_INSTANCE api_instance ) | |
905 { | |
906 T_SOCK_SOCKET_DATA *sock_data; | |
907 T_SOCK_PEERNAME_CNF sock_peername_cnf; | |
908 T_SOCK_API_INSTANCE_DATA *api_data; | |
909 | |
910 TRACE_FUNCTION("sock_getpeername_cnf()"); | |
911 | |
912 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
913 | |
914 sock_data = FindSocketData(api_data ,tcpip_peername_cnf->socket); | |
915 if(sock_data == NULL) | |
916 { | |
917 PFREE(tcpip_peername_cnf); | |
918 return; | |
919 } | |
920 | |
921 sock_peername_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_peername_cnf->event_type; | |
922 sock_peername_cnf.result = (T_SOCK_RESULT)tcpip_peername_cnf->result; | |
923 sock_peername_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
924 sock_peername_cnf.ipaddr = tcpip_peername_cnf->ipaddr; | |
925 sock_peername_cnf.port = tcpip_peername_cnf->port; | |
926 | |
927 sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_peername_cnf,sock_data->context); | |
928 | |
929 PFREE(tcpip_peername_cnf); | |
930 } /* sock_peername_cnf */ | |
931 | |
932 | |
933 /******************************************************************************/ | |
934 T_SOCK_RESULT sock_gethostbyname(T_SOCK_API_INSTANCE api_instance, | |
935 char* hostname, | |
936 T_SOCK_CALLBACK callback, | |
937 void* context) | |
938 { | |
939 T_SOCK_API_INSTANCE_DATA* api_data; | |
940 T_SOCK_SOCKET_DATA* socket_data; | |
941 | |
942 TRACE_FUNCTION("sock_gethostbyname()"); | |
943 TRACE_EVENT_P1("hostname: %s",hostname); | |
944 | |
945 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
946 | |
947 if(callback EQ NULL) | |
948 return SOCK_RESULT_INVALID_PARAMETER; | |
949 | |
950 if(api_data == NULL) | |
951 { | |
952 TRACE_ERROR("[Socket API] gethostbyname() error: Invalid socket data"); | |
953 return SOCK_RESULT_INVALID_PARAMETER; | |
954 } | |
955 | |
956 MALLOC(socket_data, sizeof(T_SOCK_SOCKET_DATA)); | |
957 | |
958 /* put socket data in linked list */ | |
959 socket_data->next_socket_data = api_data->socket_data; | |
960 api_data->socket_data = socket_data; | |
961 | |
962 /* initialize socket data */ | |
963 socket_data->api_data = api_data; | |
964 socket_data->tcpip_socket = 0; | |
965 socket_data->callback = callback; | |
966 socket_data->context = context; | |
967 socket_data->rx_flow_control = SOCK_FLOW_XON; | |
968 socket_data->tx_flow_control = SOCK_FLOW_XON; | |
969 socket_data->rx_window = 1; | |
970 socket_data->tx_window = 1; | |
971 | |
972 { | |
973 PALLOC (tcpip_hostinfo_req_prim , TCPIP_HOSTINFO_REQ); | |
974 tcpip_hostinfo_req_prim->app_handle = api_data->hCommAPP; | |
975 tcpip_hostinfo_req_prim->ipaddr = 0; | |
976 strcpy((char*)tcpip_hostinfo_req_prim->hostname, hostname); | |
977 tcpip_hostinfo_req_prim->request_id = (T_SOCK_SOCKET)socket_data; | |
978 PSEND(api_data->hCommTCPIP,tcpip_hostinfo_req_prim); | |
979 } | |
980 return SOCK_RESULT_OK; | |
981 } /* sock_gethostbyname */ | |
982 | |
983 | |
984 /******************************************************************************* | |
985 ** Function : sock_hostinfo_cnf | |
986 ** Parameter : T_SOCK_HOSTINFO_CNF * | |
987 ** T_SOCK_API_INSTANCE this value will be ignored ... | |
988 ** because you can find sock_data using request_id. | |
989 *******************************************************************************/ | |
990 LOCAL void sock_hostinfo_cnf(T_TCPIP_HOSTINFO_CNF* tcpip_hostinfo_cnf , | |
991 T_SOCK_API_INSTANCE api_instance ) | |
992 { | |
993 T_SOCK_SOCKET_DATA* socket_data; | |
994 T_SOCK_HOSTINFO_CNF sock_hostinfo_cnf; | |
995 | |
996 socket_data = (T_SOCK_SOCKET_DATA*)tcpip_hostinfo_cnf->request_id; | |
997 | |
998 /* set received values */ | |
999 socket_data->tcpip_socket = tcpip_hostinfo_cnf->socket; | |
1000 | |
1001 /* fill confirm struct */ | |
1002 sock_hostinfo_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_hostinfo_cnf->event_type; | |
1003 sock_hostinfo_cnf.result = (T_SOCK_RESULT)tcpip_hostinfo_cnf->result; | |
1004 sock_hostinfo_cnf.socket = (T_SOCK_SOCKET)socket_data; | |
1005 sock_hostinfo_cnf.ipaddr = tcpip_hostinfo_cnf->ipaddr; | |
1006 strcpy(sock_hostinfo_cnf.hostname,(char*)tcpip_hostinfo_cnf->hostname); | |
1007 | |
1008 socket_data->callback((T_SOCK_EVENTSTRUCT*)&sock_hostinfo_cnf, socket_data->context); | |
1009 | |
1010 ReleaseSocketData(socket_data->api_data, socket_data); | |
1011 | |
1012 PFREE(tcpip_hostinfo_cnf); | |
1013 } /* sock_hostinfo_cnf */ | |
1014 | |
1015 | |
1016 /******************************************************************************/ | |
1017 T_SOCK_RESULT sock_send(T_SOCK_SOCKET socket, char* buffer, U16 buffer_length) | |
1018 { | |
1019 T_SOCK_API_INSTANCE_DATA* api_data; | |
1020 T_SOCK_SOCKET_DATA* sock_data; | |
1021 | |
1022 TRACE_FUNCTION("[Socket API] sock_send()"); | |
1023 | |
1024 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1025 if(sock_data == NULL) | |
1026 { | |
1027 return SOCK_RESULT_INVALID_PARAMETER; | |
1028 } | |
1029 | |
1030 api_data = sock_data->api_data; | |
1031 | |
1032 if(sock_data->tx_window != 0) | |
1033 { | |
1034 PALLOC(tcpip_data_req_prim,TCPIP_DATA_REQ); | |
1035 tcpip_data_req_prim->app_handle = api_data->hCommAPP; | |
1036 tcpip_data_req_prim->socket = sock_data->tcpip_socket; | |
1037 tcpip_data_req_prim->ipaddr = 0; | |
1038 tcpip_data_req_prim->port = 0; | |
1039 tcpip_data_req_prim->buflen = buffer_length; | |
1040 tcpip_data_req_prim->data = (U32) M_ALLOC(buffer_length); | |
1041 | |
1042 if(tcpip_data_req_prim->data) | |
1043 { | |
1044 /* copy the user data buffer, | |
1045 the prim-data is freed by tcpip_clear_send_buffer() */ | |
1046 memcpy((char *)tcpip_data_req_prim->data,buffer,buffer_length); | |
1047 } | |
1048 else | |
1049 { | |
1050 PFREE(tcpip_data_req_prim); | |
1051 return SOCK_RESULT_OUT_OF_MEMORY; | |
1052 } | |
1053 sock_data->tx_window--; | |
1054 PSEND(api_data->hCommTCPIP,tcpip_data_req_prim); | |
1055 return SOCK_RESULT_OK; | |
1056 } | |
1057 else /* tx_window = 0 */ | |
1058 { | |
1059 sock_data->tx_flow_control = SOCK_FLOW_XOFF; | |
1060 return SOCK_RESULT_NO_BUFSPACE; | |
1061 } | |
1062 } /* sock_send */ | |
1063 | |
1064 | |
1065 /******************************************************************************/ | |
1066 T_SOCK_RESULT sock_sendto(T_SOCK_SOCKET socket, char* buffer,U16 buffer_length, | |
1067 T_SOCK_IPADDR ipaddr,T_SOCK_PORT port) | |
1068 { | |
1069 T_SOCK_API_INSTANCE_DATA* api_data; | |
1070 T_SOCK_SOCKET_DATA* sock_data; | |
1071 | |
1072 TRACE_FUNCTION("[Socket API] sock_sendto()"); | |
1073 | |
1074 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1075 if(sock_data == NULL) | |
1076 return SOCK_RESULT_INVALID_PARAMETER; | |
1077 api_data = sock_data->api_data; | |
1078 | |
1079 if(sock_data->tx_window != 0) | |
1080 { | |
1081 PALLOC(tcpip_data_req_prim,TCPIP_DATA_REQ); | |
1082 tcpip_data_req_prim->app_handle = api_data->hCommAPP; | |
1083 tcpip_data_req_prim->socket = sock_data->tcpip_socket; | |
1084 tcpip_data_req_prim->ipaddr = ipaddr; | |
1085 tcpip_data_req_prim->port = port; | |
1086 tcpip_data_req_prim->buflen = buffer_length; | |
1087 tcpip_data_req_prim->data=(U32) M_ALLOC(buffer_length); | |
1088 if(tcpip_data_req_prim->data ) | |
1089 { | |
1090 /* copy the user data buffer, | |
1091 the prim-data is freed by tcpip_clear_send_buffer() */ | |
1092 memcpy((char *)tcpip_data_req_prim->data,buffer,buffer_length); | |
1093 } | |
1094 else | |
1095 { | |
1096 PFREE(tcpip_data_req_prim); | |
1097 return SOCK_RESULT_OUT_OF_MEMORY; | |
1098 } | |
1099 | |
1100 sock_data->tx_window--; | |
1101 PSEND(api_data->hCommTCPIP, tcpip_data_req_prim); | |
1102 return SOCK_RESULT_OK; | |
1103 } | |
1104 else /* tx_window = 0 */ | |
1105 { | |
1106 sock_data->tx_flow_control = SOCK_FLOW_XOFF; | |
1107 return SOCK_RESULT_NO_BUFSPACE; | |
1108 } | |
1109 } | |
1110 | |
1111 | |
1112 /******************************************************************************* | |
1113 ** Function : sock_mtu_size_cnf | |
1114 ** Parameter : T_SOCK_MTU_SIZE_CNF * | |
1115 ** T_SOCK_API_INSTANCE | |
1116 *******************************************************************************/ | |
1117 LOCAL void sock_mtu_size_cnf(T_TCPIP_MTU_SIZE_CNF *tcpip_mtu_size_cnf , | |
1118 T_SOCK_API_INSTANCE api_instance ) | |
1119 { | |
1120 T_SOCK_SOCKET_DATA *sock_data; | |
1121 T_SOCK_MTU_SIZE_CNF sock_mtu_size_cnf; | |
1122 T_SOCK_API_INSTANCE_DATA *api_data; | |
1123 | |
1124 TRACE_FUNCTION("[Socket API] sock_mtu_size_cnf()"); | |
1125 | |
1126 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1127 | |
1128 sock_data = FindSocketData(api_data ,tcpip_mtu_size_cnf->socket); | |
1129 if(sock_data == NULL) | |
1130 { | |
1131 PFREE(tcpip_mtu_size_cnf); | |
1132 return; | |
1133 } | |
1134 | |
1135 sock_mtu_size_cnf.event_type = (T_SOCK_EVENTTYPE)tcpip_mtu_size_cnf->event_type; | |
1136 sock_mtu_size_cnf.result = (T_SOCK_RESULT)tcpip_mtu_size_cnf->result; | |
1137 sock_mtu_size_cnf.socket = (T_SOCK_SOCKET)sock_data; | |
1138 sock_mtu_size_cnf.mtu_size = tcpip_mtu_size_cnf->mtu_size; | |
1139 | |
1140 sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_mtu_size_cnf,sock_data->context); | |
1141 | |
1142 PFREE(tcpip_mtu_size_cnf); | |
1143 } /* sock_mtu_size_cnf */ | |
1144 | |
1145 | |
1146 | |
1147 /******************************************************************************* | |
1148 ** Function : sock_connect_ind | |
1149 ** Parameter : T_SOCK_CONNECT_IND * | |
1150 ** T_SOCK_API_INSTANCE | |
1151 ** Description : new socket_data will be linked to current socket_data(listening socke_data) | |
1152 *******************************************************************************/ | |
1153 LOCAL void sock_connect_ind(T_TCPIP_CONNECT_IND *tcpip_connect_ind , | |
1154 T_SOCK_API_INSTANCE api_instance ) | |
1155 { | |
1156 T_SOCK_SOCKET_DATA *cur_sock_data; /* listening socket_data */ | |
1157 T_SOCK_SOCKET_DATA *new_sock_data; /* connected socket_data */ | |
1158 T_SOCK_CONNECT_IND sock_connect_ind; | |
1159 T_SOCK_API_INSTANCE_DATA *api_data; | |
1160 | |
1161 TRACE_FUNCTION("[Socket API] sock_connect_ind()"); | |
1162 | |
1163 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1164 | |
1165 /* find listening socket_data | |
1166 * tcpip_connent_ind->socket is listening socket descrpitor | |
1167 */ | |
1168 cur_sock_data = FindSocketData(api_data ,tcpip_connect_ind->socket); | |
1169 if(cur_sock_data == NULL) | |
1170 { | |
1171 PFREE(tcpip_connect_ind); | |
1172 return; | |
1173 } | |
1174 | |
1175 /* allocate socket data */ | |
1176 MALLOC(new_sock_data, sizeof(T_SOCK_SOCKET_DATA)); | |
1177 | |
1178 /* put socket data in linked list */ | |
1179 new_sock_data->next_socket_data = NULL; | |
1180 cur_sock_data->next_socket_data = new_sock_data; | |
1181 | |
1182 /* initialize socket data */ | |
1183 new_sock_data->api_data = api_data; | |
1184 new_sock_data->tcpip_socket = tcpip_connect_ind->new_socket; | |
1185 /* server must register callback using socket_get_callback() after receiving */ | |
1186 /* connect ind event. */ | |
1187 new_sock_data->callback = NULL; | |
1188 new_sock_data->context = NULL; | |
1189 new_sock_data->rx_flow_control = SOCK_FLOW_XON; | |
1190 new_sock_data->tx_flow_control = SOCK_FLOW_XON; | |
1191 new_sock_data->rx_window = 1; | |
1192 new_sock_data->tx_window = 1; | |
1193 | |
1194 /* fill confirm struct */ | |
1195 sock_connect_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_connect_ind->event_type; | |
1196 sock_connect_ind.result = (T_SOCK_RESULT)tcpip_connect_ind->result; | |
1197 /* Check !!! why cur_sock data become new_sock_data */ | |
1198 /* sock_connect_ind.socket = (T_SOCK_SOCKET)cur_sock_data;*/ | |
1199 sock_connect_ind.socket = (T_SOCK_SOCKET)new_sock_data; | |
1200 sock_connect_ind.new_socket = tcpip_connect_ind->new_socket; | |
1201 sock_connect_ind.peer_ipaddr = tcpip_connect_ind->ipaddr; | |
1202 sock_connect_ind.peer_port = tcpip_connect_ind->port; | |
1203 | |
1204 cur_sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_connect_ind,cur_sock_data->context); | |
1205 | |
1206 PFREE(tcpip_connect_ind); | |
1207 } /* sock_connect_ind */ | |
1208 | |
1209 | |
1210 /******************************************************************************* | |
1211 ** Function : sock_conn_closed_ind | |
1212 ** Parameter : T_SOCK_CONN_CLOSED_IND * | |
1213 ** T_SOCK_API_INSTANCE | |
1214 ** Release closed socket data | |
1215 *******************************************************************************/ | |
1216 LOCAL void sock_conn_closed_ind(T_TCPIP_CONN_CLOSED_IND *tcpip_conn_closed_ind, | |
1217 T_SOCK_API_INSTANCE api_instance) | |
1218 { | |
1219 T_SOCK_SOCKET_DATA *sock_data; | |
1220 T_SOCK_CONN_CLOSED_IND sock_conn_closed_ind; | |
1221 T_SOCK_API_INSTANCE_DATA *api_data; | |
1222 | |
1223 TRACE_FUNCTION("[Socket API] sock_closed_ind()"); | |
1224 | |
1225 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1226 | |
1227 sock_data = FindSocketData(api_data, tcpip_conn_closed_ind->socket); | |
1228 if(sock_data != NULL) | |
1229 { | |
1230 sock_conn_closed_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_conn_closed_ind->event_type; | |
1231 sock_conn_closed_ind.result = (T_SOCK_RESULT)tcpip_conn_closed_ind->result; | |
1232 sock_conn_closed_ind.socket = (T_SOCK_SOCKET)sock_data; | |
1233 | |
1234 sock_data->callback(&sock_conn_closed_ind,sock_data->context); | |
1235 | |
1236 ReleaseSocketData(sock_data->api_data,sock_data); | |
1237 } | |
1238 else {;} | |
1239 | |
1240 PFREE(tcpip_conn_closed_ind); | |
1241 } /* sock_conn_closed_ind */ | |
1242 | |
1243 | |
1244 /******************************************************************************* | |
1245 ** Function : sock_error_ind | |
1246 ** Parameter : T_SOCK_ERROR_IND * | |
1247 ** T_SOCK_API_INSTANCE | |
1248 *******************************************************************************/ | |
1249 LOCAL void sock_error_ind(T_TCPIP_ERROR_IND* tcpip_error_ind , | |
1250 T_SOCK_API_INSTANCE api_instance) | |
1251 { | |
1252 T_SOCK_SOCKET_DATA* sock_data; | |
1253 T_SOCK_ERROR_IND sock_error_ind; | |
1254 T_SOCK_API_INSTANCE_DATA *api_data; | |
1255 | |
1256 TRACE_FUNCTION("[Socket API] sock_error_ind()"); | |
1257 | |
1258 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1259 | |
1260 sock_data = FindSocketData(api_data , tcpip_error_ind->socket); | |
1261 if(sock_data != NULL) | |
1262 { | |
1263 /* fill confirm struct */ | |
1264 sock_error_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_error_ind->event_type; | |
1265 sock_error_ind.result = (T_SOCK_RESULT)tcpip_error_ind->result; | |
1266 sock_error_ind.socket = (T_SOCK_SOCKET)sock_data; | |
1267 | |
1268 sock_data->callback(&sock_error_ind,sock_data->context); | |
1269 } | |
1270 else {;} | |
1271 | |
1272 PFREE(tcpip_error_ind); | |
1273 } /* sock_error_ind */ | |
1274 | |
1275 | |
1276 /******************************************************************************/ | |
1277 T_SOCK_RESULT sock_gethostbyaddr(T_SOCK_API_INSTANCE api_instance, | |
1278 T_SOCK_IPADDR ipaddr, | |
1279 T_SOCK_CALLBACK callback, | |
1280 void* context ) | |
1281 { | |
1282 T_SOCK_API_INSTANCE_DATA* api_data; | |
1283 T_SOCK_SOCKET_DATA* socket_data; | |
1284 | |
1285 TRACE_FUNCTION("[Socket API] sock_gethostbyaddr()"); | |
1286 | |
1287 if(callback EQ NULL) | |
1288 return SOCK_RESULT_INVALID_PARAMETER; | |
1289 | |
1290 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1291 | |
1292 MALLOC(socket_data, sizeof(T_SOCK_SOCKET_DATA)); | |
1293 | |
1294 /* put socket data in linked list */ | |
1295 socket_data->next_socket_data = api_data->socket_data; | |
1296 api_data->socket_data = socket_data; | |
1297 | |
1298 /* initialize socket data */ | |
1299 socket_data->api_data = api_data; | |
1300 socket_data->tcpip_socket = 0; | |
1301 socket_data->callback = callback; | |
1302 socket_data->context = context; | |
1303 socket_data->rx_flow_control = SOCK_FLOW_XON; | |
1304 socket_data->tx_flow_control = SOCK_FLOW_XON; | |
1305 socket_data->rx_window = 1; | |
1306 socket_data->tx_window = 1; | |
1307 | |
1308 { | |
1309 PALLOC (tcpip_hostinfo_req_prim ,TCPIP_HOSTINFO_REQ); | |
1310 tcpip_hostinfo_req_prim->app_handle = api_data->hCommAPP; | |
1311 tcpip_hostinfo_req_prim->ipaddr = ipaddr; | |
1312 *tcpip_hostinfo_req_prim->hostname = 0; | |
1313 tcpip_hostinfo_req_prim->request_id = (T_SOCK_SOCKET)socket_data; | |
1314 PSEND(api_data->hCommTCPIP, tcpip_hostinfo_req_prim); | |
1315 } | |
1316 return SOCK_RESULT_OK; | |
1317 } /* sock_gethostbyaddr */ | |
1318 | |
1319 | |
1320 /******************************************************************************* | |
1321 Function : sock_recv_ind | |
1322 Parameter : T_TCPIP_DATA_IND* | |
1323 T_SOCK_API_INSTANCE | |
1324 Return : VOID | |
1325 Return Event : None | |
1326 *******************************************************************************/ | |
1327 static void sock_recv_ind(T_TCPIP_DATA_IND* tcpip_data_ind, | |
1328 T_SOCK_API_INSTANCE api_instance) | |
1329 { | |
1330 T_SOCK_SOCKET_DATA* sock_data; | |
1331 T_SOCK_RECV_IND sock_receive_ind; | |
1332 T_SOCK_API_INSTANCE_DATA *api_data; | |
1333 | |
1334 TRACE_FUNCTION("[Socket API] sock_recv_ind()"); | |
1335 | |
1336 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1337 | |
1338 sock_data = FindSocketData(api_data , tcpip_data_ind->socket); | |
1339 if(sock_data == NULL) | |
1340 { | |
1341 MFREE(tcpip_data_ind->data); | |
1342 PFREE(tcpip_data_ind); | |
1343 return; | |
1344 } | |
1345 | |
1346 sock_data->rx_window--; /* when data received, window size will be descreased..*/ | |
1347 | |
1348 if(sock_data->rx_flow_control == SOCK_FLOW_XOFF ) | |
1349 { | |
1350 /* case sock flow xoff, sock_data will be stored and send to the application | |
1351 with sock_flow_xon() */ | |
1352 sock_data->recv_ind.socket = tcpip_data_ind->socket; | |
1353 sock_data->recv_ind.result = (T_SOCK_RESULT)tcpip_data_ind->result; | |
1354 sock_data->recv_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_data_ind->event_type; | |
1355 sock_data->recv_ind.data_length = tcpip_data_ind->buflen; | |
1356 sock_data->recv_ind.data_buffer = (char*)tcpip_data_ind->data; | |
1357 } | |
1358 else | |
1359 { | |
1360 /* case sock flow xon , sock_data will be sent to application...*/ | |
1361 sock_receive_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_data_ind->event_type; | |
1362 sock_receive_ind.result = (T_SOCK_RESULT)tcpip_data_ind->result; | |
1363 sock_receive_ind.socket = (T_SOCK_SOCKET)sock_data; | |
1364 sock_receive_ind.data_length = tcpip_data_ind->buflen; | |
1365 sock_receive_ind.data_buffer = (char *)tcpip_data_ind->data; | |
1366 | |
1367 sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_receive_ind,sock_data->context); | |
1368 | |
1369 /* send primitive */ | |
1370 if( (sock_data->rx_flow_control != SOCK_FLOW_XOFF) && | |
1371 (sock_data->rx_window == 0) ) | |
1372 { | |
1373 PALLOC(tcpip_data_res_prim,TCPIP_DATA_RES); | |
1374 tcpip_data_res_prim->app_handle = api_data->hCommAPP; | |
1375 ACI_ASSERT(sock_data->tcpip_socket == tcpip_data_ind->socket); | |
1376 tcpip_data_res_prim->socket = tcpip_data_ind->socket ; | |
1377 tcpip_data_res_prim->window = 1; | |
1378 sock_data->rx_window = 1; | |
1379 PSEND(api_data->hCommTCPIP, tcpip_data_res_prim); | |
1380 } | |
1381 } | |
1382 PFREE(tcpip_data_ind); | |
1383 } /* sock_recv_ind */ | |
1384 | |
1385 | |
1386 /******************************************************************************* | |
1387 ** Function : sock_send_cnf | |
1388 ** Parameter : T_TCPIP_DATA_CNF * | |
1389 ** T_SOCK_API_INSTANCE | |
1390 *******************************************************************************/ | |
1391 static void sock_send_cnf(T_TCPIP_DATA_CNF* tcpip_data_cnf, | |
1392 T_SOCK_API_INSTANCE api_instance) | |
1393 { | |
1394 T_SOCK_SOCKET_DATA *sock_data; | |
1395 T_SOCK_API_INSTANCE_DATA *api_data; | |
1396 T_SOCK_FLOW_READY_IND sock_flow_ready_ind; | |
1397 | |
1398 TRACE_FUNCTION("[Socket API] sock_send_cnf()"); | |
1399 | |
1400 api_data = (T_SOCK_API_INSTANCE_DATA*)api_instance; | |
1401 sock_data = FindSocketData(api_data , tcpip_data_cnf->socket); | |
1402 | |
1403 if(sock_data == NULL) | |
1404 { | |
1405 PFREE(tcpip_data_cnf); | |
1406 return; | |
1407 } | |
1408 /* if tcpip_data_cnf->window is 0,*/ | |
1409 /* this value will be 1 because 0 and 1 is the same meaning in the Rnet TCPIP.*/ | |
1410 if( tcpip_data_cnf->window == 0 ) | |
1411 { | |
1412 sock_data->tx_window = 1; | |
1413 } | |
1414 else | |
1415 { | |
1416 sock_data->tx_window = tcpip_data_cnf->window; | |
1417 } | |
1418 | |
1419 sock_flow_ready_ind.event_type = (T_SOCK_EVENTTYPE)tcpip_data_cnf->event_type; | |
1420 sock_flow_ready_ind.result = (T_SOCK_RESULT)tcpip_data_cnf->result; | |
1421 sock_flow_ready_ind.socket = (T_SOCK_SOCKET)sock_data; | |
1422 /* permit next packet to be send */ | |
1423 sock_data->tx_flow_control = SOCK_FLOW_XON; | |
1424 | |
1425 sock_data->callback(&sock_flow_ready_ind,sock_data->context); | |
1426 | |
1427 PFREE(tcpip_data_cnf); | |
1428 } | |
1429 | |
1430 | |
1431 /******************************************************************************/ | |
1432 T_SOCK_RESULT sock_set_callback(T_SOCK_SOCKET socket ,T_SOCK_CALLBACK new_callback, | |
1433 void* new_context) | |
1434 { | |
1435 T_SOCK_SOCKET_DATA* sock_data; | |
1436 | |
1437 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1438 | |
1439 if(new_callback EQ NULL) | |
1440 return SOCK_RESULT_INVALID_PARAMETER; | |
1441 | |
1442 if(sock_data == NULL) | |
1443 { | |
1444 return SOCK_RESULT_INVALID_PARAMETER; | |
1445 } | |
1446 | |
1447 sock_data->callback = new_callback; | |
1448 sock_data->context = new_context; | |
1449 | |
1450 return SOCK_RESULT_OK; | |
1451 } | |
1452 | |
1453 | |
1454 /******************************************************************************/ | |
1455 T_SOCK_RESULT sock_get_callback(T_SOCK_SOCKET socket, T_SOCK_CALLBACK *callback_p, | |
1456 void **context_p) | |
1457 { | |
1458 T_SOCK_SOCKET_DATA* sock_data; | |
1459 | |
1460 TRACE_FUNCTION("[Socket API] sock_get_callback()"); | |
1461 | |
1462 /* get current callback,context */ | |
1463 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1464 if(sock_data == NULL) | |
1465 { | |
1466 return SOCK_RESULT_INVALID_PARAMETER; | |
1467 } | |
1468 if(callback_p != NULL) | |
1469 { | |
1470 callback_p = &sock_data->callback; | |
1471 } | |
1472 if(context_p != NULL) | |
1473 { | |
1474 context_p = &sock_data->context; | |
1475 } | |
1476 return SOCK_RESULT_OK; | |
1477 } /* socket_get_callback */ | |
1478 | |
1479 | |
1480 /******************************************************************************/ | |
1481 T_SOCK_RESULT sock_flow_xoff(T_SOCK_SOCKET socket) | |
1482 { | |
1483 T_SOCK_SOCKET_DATA* sock_data; | |
1484 | |
1485 TRACE_FUNCTION("[Socket API] sock_flow_xoff()"); | |
1486 | |
1487 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1488 if(sock_data == NULL) | |
1489 { | |
1490 return SOCK_RESULT_INVALID_PARAMETER; | |
1491 } | |
1492 | |
1493 sock_data->rx_flow_control = SOCK_FLOW_XOFF; | |
1494 | |
1495 return SOCK_RESULT_OK; | |
1496 | |
1497 } /* sock_flow_xoff */ | |
1498 | |
1499 | |
1500 /******************************************************************************/ | |
1501 T_SOCK_RESULT sock_flow_xon(T_SOCK_SOCKET socket) | |
1502 { | |
1503 T_SOCK_SOCKET_DATA* sock_data; | |
1504 T_SOCK_RECV_IND sock_receive_ind; | |
1505 T_SOCK_API_INSTANCE_DATA *api_data; | |
1506 | |
1507 TRACE_FUNCTION("[Socket API] sock_flow_xon()"); | |
1508 | |
1509 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1510 | |
1511 if(sock_data == NULL) | |
1512 { | |
1513 return SOCK_RESULT_INVALID_PARAMETER; | |
1514 } | |
1515 | |
1516 api_data = sock_data->api_data; | |
1517 sock_data->rx_flow_control = SOCK_FLOW_XON; | |
1518 | |
1519 if(sock_data->recv_ind.data_length != 0) | |
1520 { | |
1521 sock_receive_ind.event_type = sock_data->recv_ind.event_type; | |
1522 sock_receive_ind.result = sock_data->recv_ind.result; | |
1523 sock_receive_ind.socket = (T_SOCK_SOCKET)sock_data; | |
1524 sock_receive_ind.data_length = sock_data->recv_ind.data_length; | |
1525 sock_receive_ind.data_buffer = sock_data->recv_ind.data_buffer; | |
1526 | |
1527 /* clear recv_ind struct, buffer is freed by application */ | |
1528 memset(&sock_data->recv_ind, 0x00 , sizeof(T_SOCK_RECV_IND)); | |
1529 | |
1530 sock_data->callback((T_SOCK_EVENTSTRUCT*)&sock_receive_ind,sock_data->context); | |
1531 } | |
1532 | |
1533 if((sock_data->rx_flow_control != SOCK_FLOW_XOFF) && (sock_data->rx_window == 0)) | |
1534 { | |
1535 PALLOC(tcpip_data_res_prim,TCPIP_DATA_RES); | |
1536 tcpip_data_res_prim->app_handle = api_data->hCommAPP; | |
1537 tcpip_data_res_prim->socket = sock_data->tcpip_socket; | |
1538 tcpip_data_res_prim->window = 1; | |
1539 sock_data->rx_window = 1; | |
1540 | |
1541 PSEND(api_data->hCommTCPIP, tcpip_data_res_prim); | |
1542 } | |
1543 return SOCK_RESULT_OK; | |
1544 } /* sock_flow_xon */ | |
1545 | |
1546 | |
1547 /******************************************************************************/ | |
1548 T_SOCK_RESULT sock_get_mtu_size(T_SOCK_SOCKET socket) | |
1549 { | |
1550 T_SOCK_API_INSTANCE_DATA* api_data; | |
1551 T_SOCK_SOCKET_DATA* sock_data; | |
1552 | |
1553 TRACE_FUNCTION("[Socket API] sock_get_mtu_size()"); | |
1554 | |
1555 sock_data = (T_SOCK_SOCKET_DATA*)socket; | |
1556 | |
1557 /* check whether sock_data is NULL or not */ | |
1558 if(sock_data == NULL) | |
1559 { | |
1560 return SOCK_RESULT_INVALID_PARAMETER; | |
1561 } | |
1562 | |
1563 api_data = sock_data->api_data; | |
1564 | |
1565 /* send primitive */ | |
1566 { | |
1567 PALLOC (tcpip_mtu_size_req_prim, TCPIP_MTU_SIZE_REQ); | |
1568 tcpip_mtu_size_req_prim->app_handle = api_data->hCommAPP; | |
1569 tcpip_mtu_size_req_prim->socket = sock_data->tcpip_socket; | |
1570 PSEND(api_data->hCommTCPIP, tcpip_mtu_size_req_prim); | |
1571 } | |
1572 return SOCK_RESULT_OK; | |
1573 } /* sock_get_mtu_size */ | |
1574 | |
1575 | |
1576 /******************************************************************************/ | |
1577 LOCAL void pei_not_supported (void *data) | |
1578 { | |
1579 TRACE_FUNCTION ("pei_not_supported()"); | |
1580 | |
1581 PFREE (data); | |
1582 } | |
1583 | |
1584 | |
1585 /******************************************************************************/ | |
1586 BOOL sock_api_handles_primitive( T_SOCK_API_INSTANCE api_instance, T_PRIM* prim) | |
1587 { | |
1588 LOCAL const T_FUNC tcpip_table[] = | |
1589 { | |
1590 MAK_FUNC_N( pei_not_supported, 0 /*TCPIP_INITIALIZE_CNF*/ ), /* 0x00 */ | |
1591 MAK_FUNC_N( pei_not_supported, 0 /*TCPIP_SHUTDOWN_CNF*/ ), /* 0x01 */ | |
1592 MAK_FUNC_N( pei_not_supported, 0 /*TCPIP_IFCONFIG_CNF */ ), /* 0x02 */ | |
1593 MAK_FUNC_N( pei_not_supported, 0 /*TCPIP_DTI_CNF*/ ), /* 0x03 */ | |
1594 MAK_FUNC_0( sock_create_cnf, TCPIP_CREATE_CNF ), /* 0x04 */ | |
1595 MAK_FUNC_0( sock_close_cnf, TCPIP_CLOSE_CNF ), /* 0x05 */ | |
1596 MAK_FUNC_0( sock_bind_cnf, TCPIP_BIND_CNF ), /* 0x06 */ | |
1597 MAK_FUNC_0( sock_listen_cnf, TCPIP_LISTEN_CNF ), /* 0x07 */ | |
1598 MAK_FUNC_0( sock_connect_cnf, TCPIP_CONNECT_CNF ), /* 0x08 */ | |
1599 MAK_FUNC_0( sock_send_cnf, TCPIP_DATA_CNF ), /* 0x09 */ | |
1600 MAK_FUNC_0( sock_recv_ind, TCPIP_DATA_IND ), /* 0x0a */ | |
1601 MAK_FUNC_0( sock_sockname_cnf, TCPIP_SOCKNAME_CNF ), /* 0x0b */ | |
1602 MAK_FUNC_0( sock_peername_cnf, TCPIP_PEERNAME_CNF ), /* 0x0c */ | |
1603 MAK_FUNC_0( sock_hostinfo_cnf, TCPIP_HOSTINFO_CNF ), /* 0x0d */ | |
1604 MAK_FUNC_0( sock_mtu_size_cnf, TCPIP_MTU_SIZE_CNF ), /* 0x0e */ | |
1605 MAK_FUNC_0( sock_connect_ind, TCPIP_CONNECT_IND ), /* 0x0f */ | |
1606 MAK_FUNC_0( sock_conn_closed_ind, TCPIP_CONN_CLOSED_IND ), /* 0x10 */ | |
1607 MAK_FUNC_0( sock_error_ind, TCPIP_ERROR_IND ), /* 0x11 */ | |
1608 }; | |
1609 | |
1610 LOCAL const T_FUNC dcm_table[] = | |
1611 { | |
1612 MAK_FUNC_0( sock_open_bearer_cnf, DCM_OPEN_CONN_CNF ), | |
1613 MAK_FUNC_0( sock_close_bearer_cnf, DCM_CLOSE_CONN_CNF ), | |
1614 MAK_FUNC_0( sock_bearer_info_cnf, DCM_GET_CURRENT_CONN_CNF), | |
1615 MAK_FUNC_0( sock_dcm_error_ind, DCM_ERROR_IND ), | |
1616 }; | |
1617 | |
1618 TRACE_FUNCTION("sock_api_handles_primitive()"); | |
1619 | |
1620 if(prim NEQ NULL) | |
1621 { | |
1622 ULONG opc = prim->custom.opc; | |
1623 USHORT tabsize; | |
1624 const T_FUNC *table = 0; | |
1625 | |
1626 switch( SAP_NR(opc) ) | |
1627 { | |
1628 case SAP_NR(TCPIP_DL): | |
1629 table = tcpip_table; | |
1630 tabsize = TAB_SIZE (tcpip_table); | |
1631 break; | |
1632 case SAP_NR(DCM_UL): | |
1633 table = dcm_table; | |
1634 tabsize = TAB_SIZE(dcm_table); | |
1635 break; | |
1636 default: | |
1637 /* Primitive is not for these SAP's */ | |
1638 return FALSE; | |
1639 } | |
1640 | |
1641 if (PRIM_NR(opc) < tabsize) | |
1642 { | |
1643 table += PRIM_NR(opc); | |
1644 { | |
1645 TRACE_EVENT_P1( "sock_api_handles_primitive: %d", PRIM_NR(opc) ); | |
1646 } | |
1647 JUMP (table->func) (P2D(prim),api_instance); | |
1648 } | |
1649 else | |
1650 { | |
1651 TRACE_ERROR("PRIM_NR(opc) >= tabsize"); | |
1652 return FALSE; | |
1653 } | |
1654 } | |
1655 return TRUE; | |
1656 } /* sock_api_handles_primitive */ |