1 /*
2 * netapp.c - CC31xx/CC32xx Host Driver Implementation
3 *
4 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 *
19 * Neither the name of Texas Instruments Incorporated nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37
38
39 /*****************************************************************************/
40 /* Include files */
41 /*****************************************************************************/
42 #include <ti/drivers/net/wifi/simplelink.h>
43 #include <ti/drivers/net/wifi/source/protocol.h>
44 #include <ti/drivers/net/wifi/source/driver.h>
45
46 /*****************************************************************************/
47 /* Macro declarations */
48 /*****************************************************************************/
49
50 /*****************************************************************************/
51 /* Functions prototypes */
52 /*****************************************************************************/
53 _SlReturnVal_t _SlNetAppHandleAsync_DnsGetHostByName(void *pVoidBuf);
54
55 _SlReturnVal_t _SlNetAppHandleAsync_DnsGetHostByService(void *pVoidBuf);
56 _SlReturnVal_t _SlNetAppHandleAsync_PingResponse(void *pVoidBuf);
57 static void _SlNetAppCopyPingResultsToReport(SlPingReportResponse_t *pResults,SlNetAppPingReport_t *pReport);
58
59 _i16 _SlNetAppMDNSRegisterUnregisterService(const _i8* pServiceName,
60 const _u8 ServiceNameLen,
61 const _i8* pText,
62 const _u8 TextLen,
63 const _u16 Port,
64 const _u32 TTL,
65 const _u32 Options);
66
67
68 _u16 _SlNetAppSendTokenValue(SlNetAppHttpServerData_t * Token);
69
70 _u16 _SlNetAppSendResponse( _u16 handle, SlNetAppResponse_t *NetAppResponse);
71
72 #define SL_NETAPP_SERVICE_SIZE_MASK (0x7)
73 #define SL_NETAPP_PING_GUARD_INTERVAL (20000)
74
75 static _u16 NetAppServiceSizeLUT[] =
76 {
77 (_u16)sizeof(_BasicResponse_t), /* 0 - Default value */
78 (_u16)sizeof(SlNetAppGetFullServiceWithTextIpv4List_t), /* 1 - SL_NETAPP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE */
79 (_u16)sizeof(SlNetAppGetFullServiceIpv4List_t), /* 2 - SL_NETAPP_FULL_SERVICE_IPV4_TYPE */
80 (_u16)sizeof(SlNetAppGetShortServiceIpv4List_t), /* 3 - SL_NETAPP_SHORT_SERVICE_IPV4_TYPE */
81 (_u16)sizeof(SlNetAppGetFullServiceWithTextIpv6List_t), /* 4 - SL_NETAPP_FULL_SERVICE_WITH_TEXT_IPV6_TYPE */
82 (_u16)sizeof(SlNetAppGetFullServiceIpv6List_t), /* 5 - SL_NETAPP_FULL_SERVICE_IPV6_TYPE */
83 (_u16)sizeof(SlNetAppGetShortServiceIpv6List_t), /* 6 - SL_NETAPP_SHORT_SERVICE_IPV6_TYPE */
84 (_u16)sizeof(_BasicResponse_t), /* 7 - Default value */
85 };
86
87 typedef union
88 {
89 _NetAppStartStopCommand_t Cmd;
90 _NetAppStartStopResponse_t Rsp;
91 }_SlNetAppStartStopMsg_u;
92
93
94 #if _SL_INCLUDE_FUNC(sl_NetAppStart)
95
96 static const _SlCmdCtrl_t _SlNetAppStartCtrl =
97 {
98 SL_OPCODE_NETAPP_START_COMMAND,
99 (_SlArgSize_t)sizeof(_NetAppStartStopCommand_t),
100 (_SlArgSize_t)sizeof(_NetAppStartStopResponse_t)
101 };
102
sl_NetAppStart(const _u32 AppBitMap)103 _i16 sl_NetAppStart(const _u32 AppBitMap)
104 {
105 _SlNetAppStartStopMsg_u Msg;
106 Msg.Cmd.AppId = AppBitMap;
107
108 /* verify that this api is allowed. if not allowed then
109 ignore the API execution and return immediately with an error */
110 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
111 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStartCtrl, &Msg, NULL));
112
113 return Msg.Rsp.status;
114 }
115 #endif
116
117 /*****************************************************************************
118 sl_NetAppStop
119 *****************************************************************************/
120 #if _SL_INCLUDE_FUNC(sl_NetAppStop)
121
122 static const _SlCmdCtrl_t _SlNetAppStopCtrl =
123 {
124 SL_OPCODE_NETAPP_STOP_COMMAND,
125 (_SlArgSize_t)sizeof(_NetAppStartStopCommand_t),
126 (_SlArgSize_t)sizeof(_NetAppStartStopResponse_t)
127 };
128
sl_NetAppStop(const _u32 AppBitMap)129 _i16 sl_NetAppStop(const _u32 AppBitMap)
130 {
131 _SlNetAppStartStopMsg_u Msg;
132
133 /* verify that this api is allowed. if not allowed then
134 ignore the API execution and return immediately with an error */
135 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
136 Msg.Cmd.AppId = AppBitMap;
137 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStopCtrl, &Msg, NULL));
138
139 return Msg.Rsp.status;
140 }
141 #endif
142
143
144 /*****************************************************************************
145 sl_NetAppArpFlush
146 *****************************************************************************/
147
148 #if _SL_INCLUDE_FUNC(sl_NetAppArpFlush)
149
150
sl_NetAppArpFlush(void)151 _i16 sl_NetAppArpFlush(void)
152 {
153 /* verify that this api is allowed. if not allowed then
154 ignore the API execution and return immediately with an error */
155 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
156
157 return _SlDrvBasicCmd(SL_OPCODE_NETAPP_ARPFLUSH);
158 }
159 #endif
160
161 /*****************************************************************************
162 sl_NetAppNdFlush
163 *****************************************************************************/
164
165 #if _SL_INCLUDE_FUNC(sl_NetAppNdFlush)
166
167
sl_NetAppNdFlush(void)168 _i16 sl_NetAppNdFlush(void)
169 {
170 /* verify that this api is allowed. if not allowed then
171 ignore the API execution and return immediately with an error */
172 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
173
174 return _SlDrvBasicCmd(SL_OPCODE_NETAPP_NDFLUSH_V6);
175 }
176 #endif
177
178 /******************************************************************************/
179 /* sl_NetAppGetServiceList */
180 /******************************************************************************/
181 typedef struct
182 {
183 _u8 IndexOffest;
184 _u8 MaxServiceCount;
185 _u8 Flags;
186 _i8 Padding;
187 }NetappGetServiceListCMD_t;
188
189 typedef union
190 {
191 NetappGetServiceListCMD_t Cmd;
192 _BasicResponse_t Rsp;
193 }_SlNetappGetServiceListMsg_u;
194
195
196 #if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList)
197
198 static const _SlCmdCtrl_t _SlGetServiceListeCtrl =
199 {
200 SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE,
201 (_SlArgSize_t)sizeof(NetappGetServiceListCMD_t),
202 (_SlArgSize_t)sizeof(_BasicResponse_t)
203 };
204
sl_NetAppGetServiceList(const _u8 IndexOffest,const _u8 MaxServiceCount,const _u8 Flags,_i8 * pBuffer,const _u32 BufferLength)205 _i16 sl_NetAppGetServiceList(const _u8 IndexOffest,
206 const _u8 MaxServiceCount,
207 const _u8 Flags,
208 _i8 *pBuffer,
209 const _u32 BufferLength
210 )
211 {
212
213 _i32 retVal= 0;
214 _SlNetappGetServiceListMsg_u Msg;
215 _SlCmdExt_t CmdExt;
216 _u16 ServiceSize = 0;
217 _u16 BufferSize = 0;
218
219 /* verify that this api is allowed. if not allowed then
220 ignore the API execution and return immediately with an error */
221 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
222
223 /*
224 Calculate RX pBuffer size
225 WARNING:
226 if this size is BufferSize than 1480 error should be returned because there
227 is no place in the RX packet.
228 */
229 ServiceSize = NetAppServiceSizeLUT[Flags & SL_NETAPP_SERVICE_SIZE_MASK];
230 BufferSize = MaxServiceCount * ServiceSize;
231
232 /* Check the size of the requested services is smaller than size of the user buffer.
233 If not an error is returned in order to avoid overwriting memory. */
234 if(BufferLength < BufferSize)
235 {
236 return SL_ERROR_NET_APP_RX_BUFFER_LENGTH;
237 }
238
239 _SlDrvResetCmdExt(&CmdExt);
240 CmdExt.RxPayloadLen = (_i16)BufferSize;
241 CmdExt.pRxPayload = (_u8 *)pBuffer;
242
243 Msg.Cmd.IndexOffest = IndexOffest;
244 Msg.Cmd.MaxServiceCount = MaxServiceCount;
245 Msg.Cmd.Flags = Flags;
246 Msg.Cmd.Padding = 0;
247
248 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetServiceListeCtrl, &Msg, &CmdExt));
249 retVal = Msg.Rsp.status;
250
251 return (_i16)retVal;
252 }
253
254 #endif
255
256 /*****************************************************************************/
257 /* sl_mDNSRegisterService */
258 /*****************************************************************************/
259 /*
260 * The below struct depicts the constant parameters of the command/API RegisterService.
261 *
262 1. ServiceLen - The length of the service should be smaller than SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
263 2. TextLen - The length of the text should be smaller than SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
264 3. port - The port on this target host.
265 4. TTL - The TTL of the service
266 5. Options - bitwise parameters:
267 bit 0 - is unique (means if the service needs to be unique)
268 bit 31 - for internal use if the service should be added or deleted (set means ADD).
269 bit 1-30 for future.
270
271 NOTE:
272
273 1. There are another variable parameter is this API which is the service name and the text.
274 2. According to now there is no warning and Async event to user on if the service is a unique.
275 *
276 */
277
278 typedef struct
279 {
280 _u8 ServiceNameLen;
281 _u8 TextLen;
282 _u16 Port;
283 _u32 TTL;
284 _u32 Options;
285 }NetappMdnsSetService_t;
286
287 typedef union
288 {
289 NetappMdnsSetService_t Cmd;
290 _BasicResponse_t Rsp;
291 }_SlNetappMdnsRegisterServiceMsg_u;
292
293 #if (_SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService) || _SL_INCLUDE_FUNC(sl_NetAppMDNSUnregisterService))
294
295 static const _SlCmdCtrl_t _SlRegisterServiceCtrl =
296 {
297 SL_OPCODE_NETAPP_MDNSREGISTERSERVICE,
298 (_SlArgSize_t)sizeof(NetappMdnsSetService_t),
299 (_SlArgSize_t)sizeof(_BasicResponse_t)
300 };
301
302 /******************************************************************************
303
304 sl_NetAppMDNSRegisterService
305
306 CALLER user from its host
307
308
309 DESCRIPTION:
310 Add/delete service
311 The function manipulates the command that register the service and call
312 to the NWP in order to add/delete the service to/from the mDNS package and to/from the DB.
313
314 This register service is a service offered by the application.
315 This unregister service is a service offered by the application before.
316
317 The service name should be full service name according to RFC
318 of the DNS-SD - means the value in name field in SRV answer.
319
320 Example for service name:
321 1. PC1._ipp._tcp.local
322 2. PC2_server._ftp._tcp.local
323
324 If the option is_unique is set, mDNS probes the service name to make sure
325 it is unique before starting to announce the service on the network.
326 Instance is the instance portion of the service name.
327
328
329
330
331 PARAMETERS:
332
333 The command is from constant parameters and variables parameters.
334
335 Constant parameters are:
336
337 ServiceLen - The length of the service.
338 TextLen - The length of the service should be smaller than 64.
339 port - The port on this target host.
340 TTL - The TTL of the service
341 Options - bitwise parameters:
342 bit 0 - is unique (means if the service needs to be unique)
343 bit 31 - for internal use if the service should be added or deleted (set means ADD).
344 bit 1-30 for future.
345
346 The variables parameters are:
347
348 Service name(full service name) - The service name.
349 Example for service name:
350 1. PC1._ipp._tcp.local
351 2. PC2_server._ftp._tcp.local
352
353 Text - The description of the service.
354 should be as mentioned in the RFC
355 (according to type of the service IPP,FTP...)
356
357 NOTE - pay attention
358
359 1. Temporary - there is an allocation on stack of internal buffer.
360 Its size is SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
361 It means that the sum of the text length and service name length cannot be bigger than
362 SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
363 If it is - An error is returned.
364
365 2. According to now from certain constraints the variables parameters are set in the
366 attribute part (contain constant parameters)
367
368
369
370 RETURNS: Status - the immediate response of the command status.
371 0 means success.
372
373 ******************************************************************************/
_SlNetAppMDNSRegisterUnregisterService(const _i8 * pServiceName,const _u8 ServiceNameLen,const _i8 * pText,const _u8 TextLen,const _u16 Port,const _u32 TTL,const _u32 Options)374 _i16 _SlNetAppMDNSRegisterUnregisterService(const _i8* pServiceName,
375 const _u8 ServiceNameLen,
376 const _i8* pText,
377 const _u8 TextLen,
378 const _u16 Port,
379 const _u32 TTL,
380 const _u32 Options)
381 {
382 _SlNetappMdnsRegisterServiceMsg_u Msg;
383 _SlCmdExt_t CmdExt ;
384 _i8 ServiceNameAndTextBuffer[SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH];
385 _i8 *TextPtr;
386
387 /* verify that this api is allowed. if not allowed then
388 ignore the API execution and return immediately with an error */
389 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
390 /*
391
392 NOTE - pay attention
393
394 1. Temporary - there is an allocation on stack of internal buffer.
395 Its size is SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
396 It means that the sum of the text length and service name length cannot be bigger than
397 SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
398 If it is - An error is returned.
399
400 2. According to now from certain constraints the variables parameters are set in the
401 attribute part (contain constant parameters)
402
403 */
404
405 /*build the attribute part of the command.
406 It contains the constant parameters of the command*/
407
408 Msg.Cmd.ServiceNameLen = ServiceNameLen;
409 Msg.Cmd.Options = Options;
410 Msg.Cmd.Port = Port;
411 Msg.Cmd.TextLen = TextLen;
412 Msg.Cmd.TTL = TTL;
413
414 /*Build the payload part of the command
415 Copy the service name and text to one buffer.
416 NOTE - pay attention
417 The size of the service length + the text length should be smaller than 255,
418 Until the simplelink drive supports to variable length through SPI command. */
419 if(TextLen + ServiceNameLen > (SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH - 1 )) /*-1 is for giving a place to set null termination at the end of the text*/
420 {
421 return -1;
422 }
423
424 _SlDrvMemZero(ServiceNameAndTextBuffer, (_u16)SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH);
425
426 /*Copy the service name*/
427 sl_Memcpy(ServiceNameAndTextBuffer,
428 pServiceName,
429 ServiceNameLen);
430
431 if(TextLen > 0 )
432 {
433 TextPtr = &ServiceNameAndTextBuffer[ServiceNameLen];
434 /*Copy the text just after the service name*/
435 sl_Memcpy(TextPtr,
436 pText,
437 TextLen);
438 }
439
440 _SlDrvResetCmdExt(&CmdExt);
441 CmdExt.TxPayload1Len = (TextLen + ServiceNameLen);
442 CmdExt.pTxPayload1 = (_u8 *)ServiceNameAndTextBuffer;
443
444 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRegisterServiceCtrl, &Msg, &CmdExt));
445
446 return (_i16)Msg.Rsp.status;
447 }
448 #endif
449
450 /**********************************************************************************************/
451 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService)
452
sl_NetAppMDNSRegisterService(const _i8 * pServiceName,const _u8 ServiceNameLen,const _i8 * pText,const _u8 TextLen,const _u16 Port,const _u32 TTL,_u32 Options)453 _i16 sl_NetAppMDNSRegisterService(const _i8* pServiceName,
454 const _u8 ServiceNameLen,
455 const _i8* pText,
456 const _u8 TextLen,
457 const _u16 Port,
458 const _u32 TTL,
459 _u32 Options)
460 {
461 /* verify that this api is allowed. if not allowed then
462 ignore the API execution and return immediately with an error */
463 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
464
465 /*
466
467 NOTE - pay attention
468
469 1. Temporary - there is an allocation on stack of internal buffer.
470 Its size is SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
471 It means that the sum of the text length and service name length cannot be bigger than
472 SL_NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
473 If it is - An error is returned.
474
475 2. According to now from certain constraints the variables parameters are set in the
476 attribute part (contain constant parameters)
477
478 */
479
480 /*Set the add service bit in the options parameter.
481 In order not use different opcodes for the register service and unregister service
482 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added
483 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName
484 and ServiceNameLen values. */
485 Options |= SL_NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT;
486
487 return _SlNetAppMDNSRegisterUnregisterService(pServiceName,
488 ServiceNameLen,
489 pText,
490 TextLen,
491 Port,
492 TTL,
493 Options);
494 }
495 #endif
496 /**********************************************************************************************/
497
498
499 /**********************************************************************************************/
500 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService)
501
sl_NetAppMDNSUnRegisterService(const _i8 * pServiceName,const _u8 ServiceNameLen,_u32 Options)502 _i16 sl_NetAppMDNSUnRegisterService(const _i8* pServiceName,
503 const _u8 ServiceNameLen,_u32 Options)
504 {
505
506 /* verify that this api is allowed. if not allowed then
507 ignore the API execution and return immediately with an error */
508 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
509
510 /*
511
512 NOTE - pay attention
513
514 The size of the service length should be smaller than 255,
515 Until the simplelink drive supports to variable length through SPI command.
516
517
518 */
519
520 /*Clear the add service bit in the options parameter.
521 In order not use different opcodes for the register service and unregister service
522 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added
523 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName
524 and ServiceNameLen values.*/
525
526 Options &= (~SL_NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT);
527
528 return _SlNetAppMDNSRegisterUnregisterService( pServiceName,
529 ServiceNameLen,
530 NULL,
531 0,
532 0,
533 0,
534 Options);
535
536
537 }
538 #endif
539 /**********************************************************************************************/
540
541
542 /*****************************************************************************/
543 /* sl_DnsGetHostByService */
544 /*****************************************************************************/
545 /*
546 * The below struct depicts the constant parameters of the command/API sl_DnsGetHostByService.
547 *
548 1. ServiceLen - The length of the service should be smaller than 255.
549 2. AddrLen - TIPv4 or IPv6 (SL_AF_INET , SL_AF_INET6).
550 *
551 */
552
553 typedef struct
554 {
555 _u8 ServiceLen;
556 _u8 AddrLen;
557 _u16 Padding;
558 }_GetHostByServiceCommand_t;
559
560 /*
561 * The below structure depict the constant parameters that are returned in the Async event answer
562 * according to command/API sl_DnsGetHostByService for IPv4 and IPv6.
563 *
564 1Status - The status of the response.
565 2.Address - Contains the IP address of the service.
566 3.Port - Contains the port of the service.
567 4.TextLen - Contains the max length of the text that the user wants to get.
568 it means that if the test of service is bigger that its value than
569 the text is cut to inout_TextLen value.
570 Output: Contain the length of the text that is returned. Can be full text or part
571 of the text (see above).
572 *
573 */
574
575 typedef struct
576 {
577 _u16 Status;
578 _u16 TextLen;
579 _u32 Port;
580 _u32 Address[4];
581 }_GetHostByServiceIPv6AsyncResponse_t;
582
583 /*
584 * The below struct contains pointers to the output parameters that the user gives
585 *
586 */
587 typedef struct
588 {
589 _i16 Status;
590 _u32 *out_pAddr;
591 _u32 *out_pPort;
592 _u16 *inout_TextLen; /* in: max len , out: actual len */
593 _i8 *out_pText;
594 }_GetHostByServiceAsyncResponse_t;
595
596 typedef union
597 {
598 _GetHostByServiceCommand_t Cmd;
599 _BasicResponse_t Rsp;
600 }_SlGetHostByServiceMsg_u;
601
602 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService)
603
604 static const _SlCmdCtrl_t _SlGetHostByServiceCtrl =
605 {
606 SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE,
607 (_SlArgSize_t)sizeof(_GetHostByServiceCommand_t),
608 (_SlArgSize_t)sizeof(_BasicResponse_t)
609 };
610
611 /******************************************************************************/
612
sl_NetAppDnsGetHostByService(_i8 * pServiceName,const _u8 ServiceLen,const _u8 Family,_u32 pAddr[],_u32 * pPort,_u16 * pTextLen,_i8 * pText)613 _i16 sl_NetAppDnsGetHostByService(_i8 *pServiceName, /* string containing all (or only part): name + subtype + service */
614 const _u8 ServiceLen,
615 const _u8 Family, /* 4-IPv4 , 16-IPv6 */
616 _u32 pAddr[],
617 _u32 *pPort,
618 _u16 *pTextLen, /* in: max len , out: actual len */
619 _i8 *pText
620 )
621 {
622 _SlGetHostByServiceMsg_u Msg;
623 _SlCmdExt_t CmdExt ;
624 _GetHostByServiceAsyncResponse_t AsyncRsp;
625 _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
626 _i16 RetVal = 0;
627
628 /* verify that this api is allowed. if not allowed then
629 ignore the API execution and return immediately with an error */
630 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
631 _SlDrvMemZero(&AsyncRsp, sizeof(_GetHostByServiceAsyncResponse_t));
632
633 /*
634 Note:
635 1. The return's attributes are belonged to first service that is found.
636 It can be other services with the same service name will response to
637 the query. The results of these responses are saved in the peer cache of the NWP, and
638 should be read by another API.
639
640 2. Text length can be 120 bytes only - not more
641 It is because of constraints in the NWP on the buffer that is allocated for the Async event.
642
643 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event
644 is sent by the NWP.
645
646 4.No rolling option!!! - only PTR type is sent.
647
648 */
649 /*build the attribute part of the command.
650 It contains the constant parameters of the command */
651
652 Msg.Cmd.ServiceLen = ServiceLen;
653 Msg.Cmd.AddrLen = Family;
654
655 /*Build the payload part of the command
656 Copy the service name and text to one buffer.*/
657
658 _SlDrvResetCmdExt(&CmdExt);
659 CmdExt.TxPayload1Len = ServiceLen;
660 CmdExt.pTxPayload1 = (_u8 *)pServiceName;
661
662 /*set pointers to the output parameters (the returned parameters).
663 This pointers are belonged to local struct that is set to global Async response parameter.
664 It is done in order not to run more than one sl_DnsGetHostByService at the same time.
665 The API should be run only if global parameter is pointed to NULL. */
666 AsyncRsp.out_pText = pText;
667 AsyncRsp.inout_TextLen = (_u16* )pTextLen;
668 AsyncRsp.out_pPort = pPort;
669 AsyncRsp.out_pAddr = (_u32 *)&pAddr[0];
670
671 ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, GETHOSYBYSERVICE_ID, SL_MAX_SOCKETS);
672
673 if (ObjIdx < 0)
674 {
675 return ObjIdx;
676 }
677
678 if (SL_AF_INET6 == Family)
679 {
680 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK;
681 }
682 /* Send the command */
683 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt));
684
685 /* If the immediate reponse is O.K. than wait for aSYNC event response. */
686 if(SL_RET_CODE_OK == Msg.Rsp.status)
687 {
688 RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0);
689
690 /* If we are - it means that Async event was sent.
691 The results are copied in the Async handle return functions */
692
693 Msg.Rsp.status = AsyncRsp.Status;
694 }
695
696 _SlDrvReleasePoolObj(ObjIdx);
697 if(RetVal < 0)
698 {
699 return RetVal;
700 }
701 else
702 {
703 return Msg.Rsp.status;
704 }
705 }
706 #endif
707
708 /******************************************************************************/
709
710 /******************************************************************************
711 _SlNetAppHandleAsync_DnsGetHostByService
712
713 CALLER NWP - Async event on sl_DnsGetHostByService with IPv4 Family
714
715
716 DESCRIPTION:
717
718 Async event on sl_DnsGetHostByService command with IPv4 Family.
719 Return service attributes like IP address, port and text according to service name.
720 The user sets a service name Full/Part (see example below), and should get the:
721 1. IP of the service
722 2. The port of service.
723 3. The text of service.
724
725 Hence it can make a connection to the specific service and use it.
726 It is similar to get host by name method.
727
728 It is done by a single shot query with PTR type on the service name.
729
730
731
732 Note:
733 1. The return's attributes are belonged to first service that is found.
734 It can be other services with the same service name will response to
735 the query. The results of these responses are saved in the peer cache of the NWP, and
736 should be read by another API.
737
738
739 PARAMETERS:
740
741 pVoidBuf - is point to opcode of the event.
742 it contains the outputs that are given to the user
743
744 outputs description:
745
746 1.out_pAddr[] - output: Contain the IP address of the service.
747 2.out_pPort - output: Contain the port of the service.
748 3.inout_TextLen - Input: Contain the max length of the text that the user wants to get.
749 it means that if the test of service is bigger that its value than
750 the text is cut to inout_TextLen value.
751 Output: Contain the length of the text that is returned. Can be full text or part
752 of the text (see above).
753
754 4.out_pText - Contain the text of the service (full or part see above- inout_TextLen description).
755
756 *
757
758
759 RETURNS: success or fail.
760
761 ******************************************************************************/
_SlNetAppHandleAsync_DnsGetHostByService(void * pVoidBuf)762 _SlReturnVal_t _SlNetAppHandleAsync_DnsGetHostByService(void *pVoidBuf)
763 {
764 _u16 TextLen;
765 _u16 UserTextLen;
766 _GetHostByServiceAsyncResponse_t* Res= NULL;
767 _GetHostByServiceIPv6AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv6AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
768
769 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
770 /*Res pointed to mDNS global object struct */
771 Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs;
772 /*IPv6*/
773 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK)
774 {
775 Res->out_pAddr[1] = pMsgArgs->Address[1]; /* Copy data from IPv6 address to Host user's pAddr. The array must be at least 4 cells of _u32 */
776 Res->out_pAddr[2] = pMsgArgs->Address[2];
777 Res->out_pAddr[3] = pMsgArgs->Address[3];
778 }
779
780 TextLen = pMsgArgs->TextLen;
781
782 /*It is 4 bytes so we avoid from memcpy*/
783 Res->out_pAddr[0] = pMsgArgs->Address[0]; /* Copy first cell data from IPv4/6 address to Host user's pAddr */
784 Res->out_pPort[0] = pMsgArgs->Port;
785 Res->Status = (_i16)pMsgArgs->Status;
786 /*set to TextLen the text length of the user (input fromthe user).*/
787 UserTextLen = Res->inout_TextLen[0];
788
789 /*Cut the service text if the user requested for smaller text.*/
790 UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen;
791 Res->inout_TextLen[0] = UserTextLen ;
792
793 /**************************************************************************************************
794
795 2. Copy the payload part of the evnt (the text) to the payload part of the response
796 the lenght of the copy is according to the text length in the attribute part. */
797
798 /*IPv6*/
799 if (g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK)
800 {
801 sl_Memcpy(Res->out_pText,
802 (_i8 *)(& pMsgArgs[1]), /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/
803 UserTextLen);
804 }
805 else
806 {
807 sl_Memcpy(Res->out_pText,
808 (_i8 *)(& pMsgArgs->Address[1]), /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/
809 UserTextLen);
810 }
811
812 SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
813
814 return SL_OS_RET_CODE_OK;
815 }
816
817 /*****************************************************************************/
818 /* _SlNetAppHandleAsync_DnsGetHostByAddr */
819 /*****************************************************************************/
_SlNetAppHandleAsync_DnsGetHostByAddr(void * pVoidBuf)820 _SlReturnVal_t _SlNetAppHandleAsync_DnsGetHostByAddr(void *pVoidBuf)
821 {
822 SL_TRACE0(DBG_MSG, MSG_303, "STUB: _SlNetAppHandleAsync_DnsGetHostByAddr not implemented yet!");
823 return SL_OS_RET_CODE_OK;
824 }
825
826 /*****************************************************************************/
827 /* sl_DnsGetHostByName */
828 /*****************************************************************************/
829 typedef union
830 {
831 NetAppGetHostByNameIPv4AsyncResponse_t IpV4;
832 NetAppGetHostByNameIPv6AsyncResponse_t IpV6;
833 }_GetHostByNameAsyncResponse_u;
834
835 typedef union
836 {
837 NetAppGetHostByNameCommand_t Cmd;
838 _BasicResponse_t Rsp;
839 }_SlGetHostByNameMsg_u;
840
841 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName)
842 static const _SlCmdCtrl_t _SlGetHostByNameCtrl =
843 {
844 SL_OPCODE_NETAPP_DNSGETHOSTBYNAME,
845 (_SlArgSize_t)sizeof(NetAppGetHostByNameCommand_t),
846 (_SlArgSize_t)sizeof(_BasicResponse_t)
847 };
848
sl_NetAppDnsGetHostByName(_i8 * pHostName,const _u16 NameLen,_u32 * OutIpAddr,const _u8 Family)849 _i16 sl_NetAppDnsGetHostByName(_i8 * pHostName,const _u16 NameLen, _u32* OutIpAddr,const _u8 Family )
850 {
851 _SlGetHostByNameMsg_u Msg;
852 _SlCmdExt_t ExtCtrl;
853 _GetHostByNameAsyncResponse_u AsyncRsp;
854 _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
855 _i16 RetVal=0;
856
857 /* verify that this api is allowed. if not allowed then
858 ignore the API execution and return immediately with an error */
859 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
860
861 _SlDrvResetCmdExt(&ExtCtrl);
862 ExtCtrl.TxPayload1Len = NameLen;
863 ExtCtrl.pTxPayload1 = (_u8 *)pHostName;
864
865 Msg.Cmd.Len = NameLen;
866 Msg.Cmd.Family = Family;
867
868 /*Use Obj to issue the command, if not available try later */
869 ObjIdx = _SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS);
870 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
871 {
872 return SL_POOL_IS_EMPTY;
873 }
874 if (SL_RET_CODE_STOP_IN_PROGRESS == ObjIdx)
875 {
876 return SL_RET_CODE_STOP_IN_PROGRESS;
877 }
878
879 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
880
881 g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp;
882 /*set bit to indicate IPv6 address is expected */
883 if (SL_AF_INET6 == Family)
884 {
885 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK;
886 }
887
888 SL_DRV_PROTECTION_OBJ_UNLOCK();
889
890 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl));
891
892 if(SL_RET_CODE_OK == Msg.Rsp.status)
893 {
894 // VERIFY_RET_OK(_SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0));
895 RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0);
896
897 Msg.Rsp.status = (_i16)AsyncRsp.IpV4.Status;
898
899 if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
900 {
901 sl_Memcpy((_i8 *)OutIpAddr,
902 (_i8 *)&AsyncRsp.IpV4.Ip0,
903 (SL_AF_INET == Family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE);
904 }
905 }
906
907 _SlDrvReleasePoolObj(ObjIdx);
908 if(RetVal < 0)
909 {
910 return RetVal;
911 }
912 else
913 {
914 return Msg.Rsp.status;
915 }
916 }
917 #endif
918
919
920 /******************************************************************************/
921 /* _SlNetAppHandleAsync_DnsGetHostByName */
922 /******************************************************************************/
_SlNetAppHandleAsync_DnsGetHostByName(void * pVoidBuf)923 _SlReturnVal_t _SlNetAppHandleAsync_DnsGetHostByName(void *pVoidBuf)
924 {
925 NetAppGetHostByNameIPv4AsyncResponse_t *pMsgArgs = (NetAppGetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
926
927 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
928
929 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
930
931 /*IPv6 */
932 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK)
933 {
934 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(NetAppGetHostByNameIPv6AsyncResponse_t));
935 }
936 /*IPv4 */
937 else
938 {
939 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(NetAppGetHostByNameIPv4AsyncResponse_t));
940 }
941
942 SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
943 SL_DRV_PROTECTION_OBJ_UNLOCK();
944 return SL_OS_RET_CODE_OK;
945 }
946
_SlNetAppCopyPingResultsToReport(SlPingReportResponse_t * pResults,SlNetAppPingReport_t * pReport)947 static void _SlNetAppCopyPingResultsToReport(SlPingReportResponse_t *pResults,SlNetAppPingReport_t *pReport)
948 {
949 pReport->PacketsSent = pResults->NumSendsPings;
950 pReport->PacketsReceived = pResults->NumSuccsessPings;
951 pReport->MinRoundTime = pResults->RttMin;
952 pReport->MaxRoundTime = pResults->RttMax;
953 pReport->AvgRoundTime = pResults->RttAvg;
954 pReport->TestTime = pResults->TestTime;
955 }
956
957 /*****************************************************************************/
958 /* _SlNetAppHandleAsync_PingResponse */
959 /*****************************************************************************/
_SlNetAppHandleAsync_PingResponse(void * pVoidBuf)960 _SlReturnVal_t _SlNetAppHandleAsync_PingResponse(void *pVoidBuf)
961 {
962 SlPingReportResponse_t *pMsgArgs = (SlPingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
963 SlNetAppPingReport_t pingReport;
964
965 if(pPingCallBackFunc)
966 {
967 _SlNetAppCopyPingResultsToReport(pMsgArgs,&pingReport);
968 pPingCallBackFunc(&pingReport);
969 }
970 else
971 {
972 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
973
974 VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp);
975
976 if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs)
977 {
978 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(SlPingReportResponse_t));
979 SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
980 }
981 SL_DRV_PROTECTION_OBJ_UNLOCK();
982 }
983
984 return SL_OS_RET_CODE_OK;
985 }
986
987 /*****************************************************************************/
988 /* sl_NetAppPing */
989 /*****************************************************************************/
990 typedef union
991 {
992 SlNetAppPingCommand_t Cmd;
993 SlPingReportResponse_t Rsp;
994 }_SlPingStartMsg_u;
995
996 typedef enum
997 {
998 CMD_PING_TEST_RUNNING = 0,
999 CMD_PING_TEST_STOPPED
1000 }_SlPingStatus_e;
1001
1002 #if _SL_INCLUDE_FUNC(sl_NetAppPing)
sl_NetAppPing(const SlNetAppPingCommand_t * pPingParams,const _u8 Family,SlNetAppPingReport_t * pReport,const P_SL_DEV_PING_CALLBACK pPingCallback)1003 _i16 sl_NetAppPing(const SlNetAppPingCommand_t* pPingParams, const _u8 Family, SlNetAppPingReport_t *pReport, const P_SL_DEV_PING_CALLBACK pPingCallback)
1004 {
1005 _SlCmdCtrl_t CmdCtrl = {0, (_SlArgSize_t)sizeof(SlNetAppPingCommand_t), (_SlArgSize_t)sizeof(_BasicResponse_t)};
1006 _SlPingStartMsg_u Msg;
1007 SlPingReportResponse_t PingRsp;
1008 _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
1009 _u32 PingTimeout = 0;
1010 _i16 RetVal=0;
1011
1012
1013 /* verify that this api is allowed. if not allowed then
1014 ignore the API execution and return immediately with an error */
1015 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
1016
1017 if(NULL != pPingParams)
1018 {
1019 if(SL_AF_INET == Family)
1020 {
1021 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART;
1022 sl_Memcpy(&Msg.Cmd.Ip, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE);
1023 }
1024 else
1025 {
1026 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6;
1027 sl_Memcpy(&Msg.Cmd.Ip, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE);
1028 }
1029
1030 Msg.Cmd.PingIntervalTime = pPingParams->PingIntervalTime;
1031 Msg.Cmd.PingSize = pPingParams->PingSize;
1032 Msg.Cmd.PingRequestTimeout = pPingParams->PingRequestTimeout;
1033 Msg.Cmd.TotalNumberOfAttempts = pPingParams->TotalNumberOfAttempts;
1034 Msg.Cmd.Flags = pPingParams->Flags;
1035
1036
1037 /* calculate the ping timeout according to the parmas + the guard interval */
1038 PingTimeout = SL_NETAPP_PING_GUARD_INTERVAL + (pPingParams->PingIntervalTime * pPingParams->TotalNumberOfAttempts);
1039
1040 if (Msg.Cmd.Ip != 0)
1041 {
1042 /* If the following conditions are met, return an error
1043 Wrong ping parameters - ping cannot be called with the following parameters:
1044 1. infinite ping packet
1045 2. report only when finished
1046 3. no callback supplied */
1047 if ((pPingCallback == NULL) && (pPingParams->Flags == 0) && (pPingParams->TotalNumberOfAttempts == 0))
1048 {
1049 return SL_RET_CODE_NET_APP_PING_INVALID_PARAMS;
1050 }
1051
1052 if( pPingCallback )
1053 {
1054 pPingCallBackFunc = pPingCallback;
1055 }
1056 else
1057 {
1058 /* Use Obj to issue the command, if not available try later */
1059 ObjIdx = _SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS);
1060 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
1061 {
1062 return SL_POOL_IS_EMPTY;
1063 }
1064 if (SL_RET_CODE_STOP_IN_PROGRESS == ObjIdx)
1065 {
1066 return SL_RET_CODE_STOP_IN_PROGRESS;
1067 }
1068 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));
1069 /* async response handler for non callback mode */
1070 g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&PingRsp;
1071 pPingCallBackFunc = NULL;
1072 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj));
1073 }
1074 }
1075 }
1076 /* Issue Stop Command */
1077 else
1078 {
1079 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART;
1080 Msg.Cmd.Ip = 0;
1081 }
1082 /* send the command */
1083 VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
1084 if (Msg.Cmd.Ip != 0)
1085 {
1086 if(CMD_PING_TEST_RUNNING == (_i16)Msg.Rsp.Status || CMD_PING_TEST_STOPPED == (_i16)Msg.Rsp.Status )
1087 {
1088 /* block waiting for results if no callback function is used */
1089 if( NULL == pPingCallback )
1090 {
1091 // VERIFY_RET_OK(_SlDrvWaitForInternalAsyncEvent(ObjIdx, PingTimeout, SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE));
1092 RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx, PingTimeout, SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE);
1093
1094 if( SL_OS_RET_CODE_OK == (_i16)PingRsp.Status )
1095 {
1096 _SlNetAppCopyPingResultsToReport(&PingRsp,pReport);
1097 }
1098
1099 _SlDrvReleasePoolObj(ObjIdx);
1100 if(RetVal < 0)
1101 {
1102 return RetVal;
1103 }
1104 }
1105 }
1106 else
1107 { /* ping failure, no async response */
1108 if( NULL == pPingCallback )
1109 {
1110 _SlDrvReleasePoolObj(ObjIdx);
1111 }
1112 }
1113 }
1114 return (_i16)Msg.Rsp.Status;
1115 }
1116 #endif
1117
1118 /*****************************************************************************/
1119 /* sl_NetAppSet */
1120 /*****************************************************************************/
1121 typedef union
1122 {
1123 SlNetAppSetGet_t Cmd;
1124 _BasicResponse_t Rsp;
1125 }_SlNetAppMsgSet_u;
1126
1127 #if _SL_INCLUDE_FUNC(sl_NetAppSet)
1128
1129 static const _SlCmdCtrl_t _SlNetAppSetCmdCtrl =
1130 {
1131 SL_OPCODE_NETAPP_NETAPPSET,
1132 (_SlArgSize_t)sizeof(SlNetAppSetGet_t),
1133 (_SlArgSize_t)sizeof(_BasicResponse_t)
1134 };
1135
sl_NetAppSet(const _u8 AppId,const _u8 Option,const _u8 OptionLen,const _u8 * pOptionValue)1136 _i16 sl_NetAppSet(const _u8 AppId ,const _u8 Option, const _u8 OptionLen, const _u8 *pOptionValue)
1137 {
1138 _SlNetAppMsgSet_u Msg;
1139 _SlCmdExt_t CmdExt;
1140
1141 /* verify that this api is allowed. if not allowed then
1142 ignore the API execution and return immediately with an error */
1143 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
1144
1145 _SlDrvResetCmdExt(&CmdExt);
1146 CmdExt.TxPayload1Len = (OptionLen+3) & (~3);
1147 CmdExt.pTxPayload1 = (_u8 *)pOptionValue;
1148
1149 Msg.Cmd.AppId = AppId;
1150 Msg.Cmd.ConfigLen = OptionLen;
1151 Msg.Cmd.ConfigOpt = Option;
1152
1153 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSetCmdCtrl, &Msg, &CmdExt));
1154
1155 return (_i16)Msg.Rsp.status;
1156 }
1157 #endif
1158
1159 /*****************************************************************************/
1160 /* sl_NetAppSendTokenValue */
1161 /*****************************************************************************/
1162 typedef union
1163 {
1164 SlNetAppHttpServerSendToken_t Cmd;
1165 _BasicResponse_t Rsp;
1166 }_SlNetAppMsgSendTokenValue_u;
1167
1168 const _SlCmdCtrl_t _SlNetAppSendTokenValueCmdCtrl =
1169 {
1170 SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE,
1171 (_SlArgSize_t)sizeof(SlNetAppHttpServerSendToken_t),
1172 (_SlArgSize_t)sizeof(_BasicResponse_t)
1173 };
1174
_SlNetAppSendTokenValue(SlNetAppHttpServerData_t * Token_value)1175 _u16 _SlNetAppSendTokenValue(SlNetAppHttpServerData_t * Token_value)
1176 {
1177 _SlNetAppMsgSendTokenValue_u Msg;
1178 _SlCmdExt_t CmdExt;
1179
1180 _SlDrvMemZero(&CmdExt, (_u16)sizeof(_SlCmdExt_t));
1181
1182 CmdExt.TxPayload1Len = (Token_value->ValueLen+3) & (~3);
1183 CmdExt.pTxPayload1 = (_u8 *) Token_value->pTokenValue;
1184
1185 Msg.Cmd.TokenValueLen = Token_value->ValueLen;
1186 Msg.Cmd.TokenNameLen = Token_value->NameLen;
1187 sl_Memcpy(&Msg.Cmd.TokenName[0], Token_value->pTokenName, Token_value->NameLen);
1188
1189 VERIFY_RET_OK(_SlDrvCmdSend_noLock((_SlCmdCtrl_t *)&_SlNetAppSendTokenValueCmdCtrl, &Msg, &CmdExt));
1190
1191 return Msg.Rsp.status;
1192 }
1193
1194 /*****************************************************************************/
1195 /* sl_NetAppSendResponse */
1196 /*****************************************************************************/
1197 typedef union
1198 {
1199 SlProtocolNetAppResponse_t Cmd;
1200 _BasicResponse_t Rsp;
1201 }_SlNetAppMsgSendResponse_u;
1202
1203 const _SlCmdCtrl_t _SlNetAppSendResponseCmdCtrl =
1204 {
1205 SL_OPCODE_NETAPP_RESPONSE,
1206 sizeof(SlProtocolNetAppResponse_t),
1207 sizeof(_BasicResponse_t)
1208 };
1209
_SlNetAppSendResponse(_u16 handle,SlNetAppResponse_t * NetAppResponse)1210 _u16 _SlNetAppSendResponse( _u16 handle, SlNetAppResponse_t *NetAppResponse)
1211 {
1212 _SlNetAppMsgSendResponse_u Msg;
1213 _SlCmdExt_t CmdExt;
1214 _SlReturnVal_t RetVal;
1215 _u16 dataLen;
1216
1217 _SlDrvMemZero(&CmdExt, (_u16)sizeof(_SlCmdExt_t));
1218
1219 dataLen = NetAppResponse->ResponseData.MetadataLen + NetAppResponse->ResponseData.PayloadLen;
1220
1221 if ((NetAppResponse->ResponseData.MetadataLen <= SL_NETAPP_REQUEST_MAX_METADATA_LEN) && (dataLen <= SL_NETAPP_REQUEST_MAX_DATA_LEN))
1222 {
1223 if (dataLen > 0)
1224 {
1225 /* Zero copy of the two parts: metadata + payload */
1226 CmdExt.pTxPayload1 = NetAppResponse->ResponseData.pMetadata;
1227 CmdExt.TxPayload1Len = NetAppResponse->ResponseData.MetadataLen;
1228
1229 CmdExt.pTxPayload2 = NetAppResponse->ResponseData.pPayload;
1230 CmdExt.TxPayload2Len = NetAppResponse->ResponseData.PayloadLen;
1231 }
1232 else
1233 {
1234 CmdExt.pTxPayload1 = NULL;
1235 CmdExt.pTxPayload2 = NULL;
1236 }
1237
1238 CmdExt.RxPayloadLen = 0;
1239 CmdExt.pRxPayload = NULL;
1240
1241 Msg.Cmd.Handle = handle;
1242 Msg.Cmd.status = NetAppResponse->Status;
1243 Msg.Cmd.MetadataLen = NetAppResponse->ResponseData.MetadataLen;
1244 Msg.Cmd.PayloadLen = NetAppResponse->ResponseData.PayloadLen;
1245 Msg.Cmd.Flags = NetAppResponse->ResponseData.Flags;
1246
1247 RetVal = _SlDrvCmdSend_noLock((_SlCmdCtrl_t *)&_SlNetAppSendResponseCmdCtrl, &Msg, &CmdExt);
1248 }
1249 else
1250 {
1251 /* TODO: how to return the error code asynchronously? */
1252 RetVal = SL_ERROR_BSD_ENOMEM;
1253 }
1254
1255 return RetVal;
1256 }
1257
1258 /*****************************************************************************/
1259 /* sl_NetAppRecv */
1260 /*****************************************************************************/
1261 typedef union
1262 {
1263 SlProtocolNetAppReceiveRequest_t Cmd;
1264 _BasicResponse_t Rsp; /* Not used. do we need it? */
1265 }_SlNetAppReceiveMsg_u;
1266
1267 #if _SL_INCLUDE_FUNC(sl_NetAppRecv)
1268
1269 const _SlCmdCtrl_t _SlNetAppReceiveCmdCtrl =
1270 {
1271 SL_OPCODE_NETAPP_RECEIVEREQUEST,
1272 sizeof(SlProtocolNetAppReceiveRequest_t),
1273 sizeof(_BasicResponse_t) /* Where is this used? */
1274 };
1275
sl_NetAppRecv(_u16 Handle,_u16 * DataLen,_u8 * pData,_u32 * Flags)1276 _SlReturnVal_t sl_NetAppRecv( _u16 Handle, _u16 *DataLen, _u8 *pData, _u32 *Flags)
1277 {
1278 _SlNetAppReceiveMsg_u Msg;
1279 _SlCmdExt_t CmdExt;
1280 SlProtocolNetAppReceive_t AsyncRsp; /* Will be filled when SL_OPCODE_NETAPP_RECEIVE async event is arrived */
1281
1282 _SlReturnVal_t RetVal;
1283 _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
1284 _SlArgsData_t pArgsData;
1285
1286 /* Validate input arguments */
1287 if ((NULL == pData) || (0==DataLen))
1288 {
1289 return SL_ERROR_BSD_EINVAL;
1290 }
1291
1292 /* Save the user RX bufer. Rx data will be copied into it on the SL_OPCODE_NETAPP_RECEIVE async event */
1293 _SlDrvResetCmdExt(&CmdExt);
1294 CmdExt.RxPayloadLen = *DataLen;
1295 CmdExt.pRxPayload = pData;
1296
1297 /* Prepare the command args */
1298 Msg.Cmd.Handle = Handle;
1299 Msg.Cmd.MaxBufferLen = *DataLen;
1300 Msg.Cmd.Flags = *Flags;
1301
1302 /* Use Obj to issue the command, if not available try later */
1303 ObjIdx = _SlDrvWaitForPoolObj(NETAPP_RECEIVE_ID, SL_MAX_SOCKETS);
1304
1305 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
1306 {
1307 return SL_POOL_IS_EMPTY;
1308 }
1309 if (SL_RET_CODE_STOP_IN_PROGRESS == ObjIdx)
1310 {
1311 return SL_RET_CODE_STOP_IN_PROGRESS;
1312 }
1313
1314 /* Save the AsyncRsp and cmdExt information for the SL_OPCODE_NETAPP_RECEIVE async event */
1315 AsyncRsp.Handle = Handle; /* Handle we are waiting for */
1316 AsyncRsp.Flags = 0;
1317 AsyncRsp.PayloadLen = 0; /* 0 will indicate an error in the SL_OPCODE_NETAPP_RECEIVE async event and that no data arrived. */
1318
1319 _SlDrvProtectionObjLockWaitForever();
1320
1321 pArgsData.pData = (_u8 *) &CmdExt;
1322 pArgsData.pArgs = (_u8 *) &AsyncRsp;
1323
1324 g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&pArgsData;
1325
1326 _SlDrvProtectionObjUnLock();
1327
1328 /* Send the command */
1329 RetVal = _SlDrvCmdSend((_SlCmdCtrl_t *)&_SlNetAppReceiveCmdCtrl, &Msg, &CmdExt);
1330
1331 if(SL_OS_RET_CODE_OK == RetVal)
1332 {
1333 /* Wait for SL_OPCODE_NETAPP_RECEIVE async event. Will be signaled by _SlNetAppHandleAsync_NetAppReceive. */
1334 // VERIFY_RET_OK(_SlDrvWaitForInternalAsyncEvent(ObjIdx, 0, 0));
1335 RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx, 0, 0);
1336
1337 /* Update information for the user */
1338 *DataLen = AsyncRsp.PayloadLen;
1339 *Flags = AsyncRsp.Flags;
1340 }
1341
1342 _SlDrvReleasePoolObj(ObjIdx);
1343
1344 return RetVal;
1345 }
1346
1347
1348 /*****************************************************************************/
1349 /* _SlNetAppHandleAsync_NetAppReceive */
1350 /*****************************************************************************/
_SlNetAppHandleAsync_NetAppReceive(void * pVoidBuf)1351 void _SlNetAppHandleAsync_NetAppReceive(void *pVoidBuf)
1352 {
1353 _u8 *pData;
1354 _u16 len;
1355 SlProtocolNetAppReceive_t *AsyncRsp;
1356 _SlCmdExt_t *CmdExt;
1357 SlProtocolNetAppReceive_t *pMsgArgs = (SlProtocolNetAppReceive_t *)_SL_RESP_ARGS_START(pVoidBuf);
1358
1359 pData = (_u8 *)((SlProtocolNetAppReceive_t *)pMsgArgs + 1); /* Points to the netapp receive payload */
1360
1361 _SlDrvProtectionObjLockWaitForever();
1362
1363 if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs)
1364 {
1365 AsyncRsp = (SlProtocolNetAppReceive_t *) ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))-> pArgs;
1366 CmdExt = (_SlCmdExt_t *) ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))-> pData;
1367
1368 if (pMsgArgs->Handle == AsyncRsp->Handle)
1369 {
1370 if (pMsgArgs->PayloadLen <= CmdExt->RxPayloadLen)
1371 {
1372 len = pMsgArgs->PayloadLen;
1373 }
1374 else
1375 {
1376 len = CmdExt->RxPayloadLen;
1377 }
1378
1379 /* Copy the data to the user buffer */
1380 sl_Memcpy (CmdExt->pRxPayload, pData, len);
1381
1382 /* Update len and flags */
1383 AsyncRsp->PayloadLen = len;
1384 AsyncRsp->Flags = pMsgArgs->Flags;
1385 }
1386 }
1387
1388 _SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
1389 _SlDrvProtectionObjUnLock();
1390
1391 return;
1392 }
1393
1394 #endif
1395
1396 /*****************************************************************************/
1397 /* sl_NetAppSend */
1398 /*****************************************************************************/
1399 typedef union
1400 {
1401 SlProtocolNetAppSend_t Cmd;
1402 _BasicResponse_t Rsp;
1403 }_SlNetAppMsgSend_u;
1404
1405 const _SlCmdCtrl_t _SlNetAppSendCmdCtrl =
1406 {
1407 SL_OPCODE_NETAPP_SEND,
1408 sizeof(SlProtocolNetAppSend_t),
1409 sizeof(_BasicResponse_t)
1410 };
1411
sl_NetAppSend(_u16 Handle,_u16 DataLen,_u8 * pData,_u32 Flags)1412 _u16 sl_NetAppSend( _u16 Handle, _u16 DataLen, _u8* pData, _u32 Flags)
1413 {
1414 _SlNetAppMsgSend_u Msg;
1415 _SlCmdExt_t CmdExt;
1416
1417 _SlDrvMemZero(&CmdExt, (_u16)sizeof(_SlCmdExt_t));
1418
1419 if ((((Flags & SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA) == SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA) && (DataLen <= SL_NETAPP_REQUEST_MAX_METADATA_LEN)) ||
1420 (((Flags & SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA) == 0) && (DataLen <= SL_NETAPP_REQUEST_MAX_DATA_LEN)))
1421 {
1422 CmdExt.TxPayload1Len = (DataLen+3) & (~3);
1423 CmdExt.pTxPayload1 = (_u8 *) pData;
1424
1425 Msg.Cmd.Handle = Handle;
1426 Msg.Cmd.DataLen = DataLen;
1427 Msg.Cmd.Flags = Flags;
1428
1429 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSendCmdCtrl, &Msg, &CmdExt));
1430 }
1431 else
1432 {
1433 Msg.Rsp.status = SL_ERROR_BSD_ENOMEM;
1434 }
1435
1436 return Msg.Rsp.status;
1437 }
1438
1439 /*****************************************************************************/
1440 /* sl_NetAppGet */
1441 /*****************************************************************************/
1442 typedef union
1443 {
1444 SlNetAppSetGet_t Cmd;
1445 SlNetAppSetGet_t Rsp;
1446 }_SlNetAppMsgGet_u;
1447
1448 #if _SL_INCLUDE_FUNC(sl_NetAppGet)
1449 static const _SlCmdCtrl_t _SlNetAppGetCmdCtrl =
1450 {
1451 SL_OPCODE_NETAPP_NETAPPGET,
1452 (_SlArgSize_t)sizeof(SlNetAppSetGet_t),
1453 (_SlArgSize_t)sizeof(SlNetAppSetGet_t)
1454 };
1455
sl_NetAppGet(const _u8 AppId,const _u8 Option,_u8 * pOptionLen,_u8 * pOptionValue)1456 _i16 sl_NetAppGet(const _u8 AppId, const _u8 Option,_u8 *pOptionLen, _u8 *pOptionValue)
1457 {
1458 _SlNetAppMsgGet_u Msg;
1459 _SlCmdExt_t CmdExt;
1460
1461 /* verify that this api is allowed. if not allowed then
1462 ignore the API execution and return immediately with an error */
1463 VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETAPP);
1464
1465 if (*pOptionLen == 0)
1466 {
1467 return SL_EZEROLEN;
1468 }
1469
1470 _SlDrvResetCmdExt(&CmdExt);
1471 CmdExt.RxPayloadLen = (_i16)(*pOptionLen);
1472 CmdExt.pRxPayload = (_u8 *)pOptionValue;
1473
1474 Msg.Cmd.AppId = AppId;
1475 Msg.Cmd.ConfigOpt = Option;
1476 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppGetCmdCtrl, &Msg, &CmdExt));
1477
1478
1479 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
1480 {
1481 *pOptionLen = (_u8)CmdExt.RxPayloadLen;
1482 return SL_ESMALLBUF;
1483 }
1484 else
1485 {
1486 *pOptionLen = (_u8)CmdExt.ActualRxPayloadLen;
1487 }
1488
1489 return (_i16)Msg.Rsp.Status;
1490 }
1491 #endif
1492
1493 /*****************************************************************************/
1494 /* _SlNetAppEventHandler */
1495 /*****************************************************************************/
_SlNetAppEventHandler(void * pArgs)1496 _SlReturnVal_t _SlNetAppEventHandler(void* pArgs)
1497 {
1498 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
1499 #if defined(slcb_NetAppHttpServerHdlr) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
1500 SlNetAppHttpServerEvent_t httpServerEvent;
1501 SlNetAppHttpServerResponse_t httpServerResponse;
1502 #endif
1503 switch(pHdr->GenHeader.Opcode)
1504 {
1505 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE:
1506 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6:
1507 _SlNetAppHandleAsync_DnsGetHostByName(pArgs);
1508 break;
1509 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE:
1510 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6:
1511 _SlNetAppHandleAsync_DnsGetHostByService(pArgs);
1512 break;
1513 case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE:
1514 _SlNetAppHandleAsync_PingResponse(pArgs);
1515 break;
1516
1517 case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE:
1518 {
1519 #if defined(slcb_NetAppHttpServerHdlr) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
1520 _u8 *pTokenName;
1521 SlNetAppHttpServerData_t Token_value;
1522 SlNetAppHttpServerGetToken_t *httpGetToken = (SlNetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr);
1523 pTokenName = (_u8 *)((SlNetAppHttpServerGetToken_t *)httpGetToken + 1);
1524
1525 httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE;
1526 httpServerResponse.ResponseData.TokenValue.Len = SL_NETAPP_MAX_TOKEN_VALUE_LEN;
1527
1528 /* Reuse the async buffer for getting the token value response from the user */
1529 httpServerResponse.ResponseData.TokenValue.pData = (_u8 *)_SL_RESP_ARGS_START(pHdr) + SL_NETAPP_MAX_TOKEN_NAME_LEN;
1530
1531 httpServerEvent.Event = SL_NETAPP_EVENT_HTTP_TOKEN_GET;
1532 httpServerEvent.EventData.HttpTokenName.Len = httpGetToken->TokenNameLen;
1533 httpServerEvent.EventData.HttpTokenName.pData = pTokenName;
1534
1535 Token_value.pTokenName = pTokenName;
1536
1537 _SlDrvDispatchHttpServerEvents (&httpServerEvent, &httpServerResponse);
1538
1539 Token_value.ValueLen = httpServerResponse.ResponseData.TokenValue.Len;
1540 Token_value.NameLen = httpServerEvent.EventData.HttpTokenName.Len;
1541 Token_value.pTokenValue = httpServerResponse.ResponseData.TokenValue.pData;
1542
1543 _SlNetAppSendTokenValue(&Token_value);
1544 #else
1545
1546 _u8 *pTokenName;
1547 SlNetAppHttpServerData_t Token_value;
1548 SlNetAppHttpServerGetToken_t *httpGetToken = (SlNetAppHttpServerGetToken_t*)_SL_RESP_ARGS_START(pHdr);
1549 pTokenName = (_u8 *)((SlNetAppHttpServerGetToken_t *)httpGetToken + 1);
1550
1551 Token_value.pTokenName = pTokenName;
1552 Token_value.ValueLen = 0;
1553 Token_value.NameLen = httpGetToken->TokenNameLen;
1554 Token_value.pTokenValue = NULL;
1555
1556 _SlNetAppSendTokenValue(&Token_value);
1557 #endif
1558 }
1559 break;
1560
1561 case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE:
1562 {
1563 #if defined(slcb_NetAppHttpServerHdlr) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
1564 _u8 *pPostParams;
1565
1566 SlNetAppHttpServerPostToken_t *httpPostTokenArgs = (SlNetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr);
1567 pPostParams = (_u8 *)((SlNetAppHttpServerPostToken_t *)httpPostTokenArgs + 1);
1568
1569 httpServerEvent.Event = SL_NETAPP_EVENT_HTTP_TOKEN_POST;
1570
1571 httpServerEvent.EventData.HttpPostData.Action.Len = httpPostTokenArgs->PostActionLen;
1572 httpServerEvent.EventData.HttpPostData.Action.pData = pPostParams;
1573 pPostParams+=httpPostTokenArgs->PostActionLen;
1574
1575 httpServerEvent.EventData.HttpPostData.TokenName.Len = httpPostTokenArgs->TokenNameLen;
1576 httpServerEvent.EventData.HttpPostData.TokenName.pData = pPostParams;
1577 pPostParams+=httpPostTokenArgs->TokenNameLen;
1578
1579 httpServerEvent.EventData.HttpPostData.TokenValue.Len = httpPostTokenArgs->TokenValueLen;
1580 httpServerEvent.EventData.HttpPostData.TokenValue.pData = pPostParams;
1581
1582 httpServerResponse.Response = SL_NETAPP_HTTPRESPONSE_NONE;
1583
1584 _SlDrvDispatchHttpServerEvents (&httpServerEvent, &httpServerResponse);
1585 #endif
1586 }
1587 break;
1588
1589 case SL_OPCODE_NETAPP_REQUEST:
1590 {
1591 #if defined(slcb_NetAppRequestHdlr) || defined(EXT_LIB_REGISTERED_NETAPP_REQUEST_EVENTS)
1592 _u8 *pData;
1593 SlNetAppRequest_t NetAppRequest;
1594 SlNetAppResponse_t NetAppResponse;
1595 _u16 status;
1596
1597 /* Points to the Netapp request Arguments */
1598 SlProtocolNetAppRequest_t *protocol_NetAppRequest = (SlProtocolNetAppRequest_t*)_SL_RESP_ARGS_START(pHdr);
1599
1600 NetAppRequest.AppId = protocol_NetAppRequest->AppId;
1601 NetAppRequest.Type = protocol_NetAppRequest->RequestType;
1602 NetAppRequest.Handle = protocol_NetAppRequest->Handle;
1603 NetAppRequest.requestData.Flags = protocol_NetAppRequest->Flags;
1604
1605 /* Prepare the Metadata*/
1606 pData = (_u8 *)((SlProtocolNetAppRequest_t *)protocol_NetAppRequest + 1);/* Points to the netapp request Data (start of Metadata + payload) */
1607 NetAppRequest.requestData.pMetadata = pData; /* Just pass the pointer */
1608 NetAppRequest.requestData.MetadataLen = protocol_NetAppRequest->MetadataLen;
1609
1610 /* Preare the Payload */
1611 pData+=protocol_NetAppRequest->MetadataLen;
1612 NetAppRequest.requestData.pPayload = pData; /* Just pass the pointer */
1613 NetAppRequest.requestData.PayloadLen = protocol_NetAppRequest->PayloadLen;
1614
1615 /* Just in case - clear the response outout data */
1616 sl_Memset(&NetAppResponse, 0, sizeof (NetAppResponse));
1617 NetAppResponse.Status = SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
1618
1619 /* Call the request handler dispatcher */
1620 _SlDrvDispatchNetAppRequestEvents (&NetAppRequest, &NetAppResponse);
1621
1622 /* Handle the response */
1623 status = _SlNetAppSendResponse(protocol_NetAppRequest->Handle, &NetAppResponse);
1624
1625 #if (defined(SL_RUNTIME_EVENT_REGISTERATION) || defined(slcb_NetAppRequestMemFree))
1626 if(1 == _SlIsEventRegistered(SL_EVENT_HDL_MEM_FREE))
1627 {
1628 if ((NetAppResponse.ResponseData.MetadataLen > 0) && (NetAppResponse.ResponseData.pMetadata != NULL))
1629 {
1630 _SlDrvHandleNetAppRequestMemFreeEvents (NetAppResponse.ResponseData.pMetadata);
1631 }
1632
1633 if ((NetAppResponse.ResponseData.PayloadLen > 0) && (NetAppResponse.ResponseData.pPayload != NULL))
1634 {
1635 _SlDrvHandleNetAppRequestMemFreeEvents (NetAppResponse.ResponseData.pPayload);
1636 }
1637 }
1638 #endif
1639
1640 if (status != 0 )
1641 {
1642 /* Error - just send resource not found */
1643 NetAppResponse.Status = SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
1644 NetAppResponse.ResponseData.pMetadata = NULL;
1645 NetAppResponse.ResponseData.MetadataLen = 0;
1646 NetAppResponse.ResponseData.pPayload = NULL;
1647 NetAppResponse.ResponseData.PayloadLen = 0;
1648 NetAppResponse.ResponseData.Flags = 0;
1649
1650 /* Handle the response */
1651 _SlNetAppSendResponse(protocol_NetAppRequest->Handle, &NetAppResponse);
1652 }
1653 #else
1654
1655 SlNetAppResponse_t NetAppResponse;
1656
1657 /* Points to the Netapp request Arguments */
1658 SlProtocolNetAppRequest_t *protocol_NetAppRequest = (SlProtocolNetAppRequest_t *)_SL_RESP_ARGS_START(pHdr);
1659
1660 /* Prepare the response */
1661 NetAppResponse.Status = SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
1662 NetAppResponse.ResponseData.pMetadata = NULL;
1663 NetAppResponse.ResponseData.MetadataLen = 0;
1664 NetAppResponse.ResponseData.pPayload = NULL;
1665 NetAppResponse.ResponseData.PayloadLen = 0;
1666 NetAppResponse.ResponseData.Flags = 0;
1667
1668 /* Handle the response */
1669 _SlNetAppSendResponse(protocol_NetAppRequest->Handle, &NetAppResponse);
1670 #endif
1671
1672 }
1673 break;
1674
1675 default:
1676 // SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlNetAppEventHandler : invalid opcode = 0x%x = %1", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
1677 VERIFY_PROTOCOL(0);
1678 }
1679
1680 return SL_OS_RET_CODE_OK;
1681 }
1682