]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/Qnx/Nameserver_devctl.c
Merge branch '3.30' into ipc-next
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / utils / hlos / knl / Qnx / Nameserver_devctl.c
1 /*
2  *  @file   Nameserver_devctl.c
3  *
4  *  @brief      OS-specific implementation of NameServer driver for Qnx
5  *
6  *
7  *  ============================================================================
8  *
9  *  Copyright (c) 2008-2015, Texas Instruments Incorporated
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *  *  Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *
18  *  *  Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *
22  *  *  Neither the name of Texas Instruments Incorporated nor the names of
23  *     its contributors may be used to endorse or promote products derived
24  *     from this software without specific prior written permission.
25  *
26  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *  Contact information for paper mail:
38  *  Texas Instruments
39  *  Post Office Box 655303
40  *  Dallas, Texas 75265
41  *  Contact information:
42  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
43  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
44  *  ============================================================================
45  *
46  */
48 /* Standard headers */
49 #include <ti/syslink/Std.h>
51 /* OSAL & Utils headers */
52 #include <ti/syslink/utils/List.h>
53 #include <ti/syslink/utils/Trace.h>
54 #include <ti/syslink/utils/Memory.h>
56 /* QNX specific header include */
57 #include <ti/syslink/build/Qnx/resmgr/proto.h>
58 #include <ti/syslink/build/Qnx/resmgr/dcmd_syslink.h>
60 /* Module specific header files */
61 #include <ti/ipc/NameServer.h>
62 #include <ti/syslink/inc/NameServerDrvDefs.h>
64 /* Function prototypes */
65 int ipc_nameserver_add(resmgr_context_t *ctp, io_devctl_t *msg,
66     ipc_ocb_t *ocb);
67 int ipc_nameserver_get(resmgr_context_t *ctp, io_devctl_t *msg,
68     ipc_ocb_t *ocb);
69 int ipc_nameserver_adduint32(resmgr_context_t *ctp, io_devctl_t *msg,
70     ipc_ocb_t *ocb);
71 int ipc_nameserver_getuint32(resmgr_context_t *ctp, io_devctl_t *msg,
72     ipc_ocb_t *ocb);
73 int ipc_nameserver_remove(resmgr_context_t *ctp, io_devctl_t *msg,
74     ipc_ocb_t *ocb);
75 int ipc_nameserver_removeentry(resmgr_context_t *ctp, io_devctl_t *msg,
76     ipc_ocb_t *ocb);
77 int ipc_nameserver_params_init(resmgr_context_t *ctp, io_devctl_t *msg,
78     ipc_ocb_t *ocb);
79 int ipc_nameserver_create(resmgr_context_t *ctp, io_devctl_t *msg,
80     ipc_ocb_t *ocb);
81 int ipc_nameserver_delete(resmgr_context_t *ctp, io_devctl_t *msg,
82     ipc_ocb_t *ocb);
83 int ipc_nameserver_setup(resmgr_context_t *ctp, io_devctl_t *msg,
84     ipc_ocb_t *ocb);
85 int ipc_nameserver_destroy(resmgr_context_t *ctp, io_devctl_t *msg,
86     ipc_ocb_t *ocb);
88 /**
89  * Handler for devctl() messages for MultiProc module.
90  *
91  * Handles special devctl() messages that we export for control.
92  *
93  * \param ctp   Thread's associated context information.
94  * \param msg   The actual devctl() message.
95  * \param ocb   OCB associated with client's session.
96  *
97  * \return POSIX errno value.
98  *
99  * \retval EOK      Success.
100  * \retval ENOTSUP  Unsupported devctl().
101  */
102 int ipc_nameserver_devctl(resmgr_context_t *ctp, io_devctl_t *msg,
103     ipc_ocb_t *ocb)
106     switch (msg->i.dcmd)
107     {
108       case DCMD_NAMESERVER_ADD:
109       {
110           return ipc_nameserver_add( ctp, msg, ocb);
111       }
112       break;
114       case DCMD_NAMESERVER_GET:
115       {
116           return ipc_nameserver_get( ctp, msg, ocb);
117       }
118       break;
119       case DCMD_NAMESERVER_ADDUINT32:
120       {
121           return ipc_nameserver_adduint32( ctp, msg, ocb);
122       }
123       break;
125       case DCMD_NAMESERVER_GETUINT32:
126       {
127           return ipc_nameserver_getuint32( ctp, msg, ocb);
128       }
129       break;
131       case DCMD_NAMESERVER_REMOVE:
132       {
133           return ipc_nameserver_remove( ctp, msg, ocb);
134       }
135       break;
137       case DCMD_NAMESERVER_REMOVEENTRY:
138       {
139           return ipc_nameserver_removeentry( ctp, msg, ocb);
140       }
141       break;
143       case DCMD_NAMESERVER_PARAMS_INIT:
144       {
145           return ipc_nameserver_params_init( ctp, msg, ocb);
146       }
147       break;
149       case DCMD_NAMESERVER_CREATE:
150       {
151           return ipc_nameserver_create( ctp, msg, ocb);
152       }
153       break;
155       case DCMD_NAMESERVER_DELETE:
156       {
157           return ipc_nameserver_delete( ctp, msg, ocb);
158       }
159       break;
161       case DCMD_NAMESERVER_SETUP:
162       {
163           return ipc_nameserver_setup( ctp, msg, ocb);
164       }
165       break;
167       case DCMD_NAMESERVER_DESTROY:
168       {
169           return ipc_nameserver_destroy( ctp, msg, ocb);
170       }
171       break;
173       default:
174           fprintf( stderr, "Invalid DEVCTL for nameserver 0x%x\n", msg->i.dcmd);
175           break;
177     }
179     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
180         sizeof(NameServerDrv_CmdArgs)));
183 /**
184  * Handler for nameserver add API.
185  *
186  * \param ctp   Thread's associated context information.
187  * \param msg   The actual devctl() message.
188  * \param ocb   OCB associated with client's session.
189  *
190  * \return POSIX errno value.
191  *
192  * \retval EOK      Success.
193  * \retval ENOTSUP  Unsupported devctl().
194  */
195 int ipc_nameserver_add(resmgr_context_t *ctp, io_devctl_t *msg,
196     ipc_ocb_t *ocb)
198     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
199         (_DEVCTL_DATA (msg->i));
200     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
201         (_DEVCTL_DATA (msg->o));
202     String name = (String)(cargs+1);
203     Ptr buf = (Ptr)((sizeof(char) * cargs->args.add.nameLen) + (char *)(name));
204     Ptr entry;
206     GT_assert (curTrace, (name != NULL));
208     entry = NameServer_add(cargs->args.add.handle,
209                            name,
210                            buf,
211                            cargs->args.add.len);
212     GT_assert (curTrace, (entry != NULL));
214     out->args.add.entry = entry;
216     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
217         sizeof(NameServerDrv_CmdArgs)));
220 /**
221  * Handler for nameserver get  API.
222  *
223  * \param ctp   Thread's associated context information.
224  * \param msg   The actual devctl() message.
225  * \param ocb   OCB associated with client's session.
226  *
227  * \return POSIX errno value.
228  *
229  * \retval EOK      Success.
230  * \retval ENOTSUP  Unsupported devctl().
231  */
232 int ipc_nameserver_get(resmgr_context_t *ctp, io_devctl_t *msg,
233     ipc_ocb_t *ocb)
235     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
236         (_DEVCTL_DATA (msg->i));
237     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
238         (_DEVCTL_DATA (msg->o));
240     char * buf = (char *)(cargs + 1);
241     char * name  = (char *)(buf + (sizeof(char) * cargs->args.get.len));
242     UInt16 * procId = NULL;
244     if (cargs->args.get.procLen > 0) {
245         procId = (UInt16 *)(name + (sizeof(char) * cargs->args.get.nameLen));
246     }
248     out->apiStatus = NameServer_get(cargs->args.get.handle,
249                              (String)name,
250                              (Ptr)buf,
251                              &cargs->args.get.len,
252                              procId);
254     SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) +
255         sizeof(NameServerDrv_CmdArgs));
256     SETIOV(&ctp->iov[1], (Ptr)buf, cargs->args.get.len);
258     return _RESMGR_NPARTS(2);
261 /**
262  * Handler for nameserver addunit32 API.
263  *
264  * \param ctp   Thread's associated context information.
265  * \param msg   The actual devctl() message.
266  * \param ocb   OCB associated with client's session.
267  *
268  * \return POSIX errno value.
269  *
270  * \retval EOK      Success.
271  * \retval ENOTSUP  Unsupported devctl().
272  */
273 int ipc_nameserver_adduint32(resmgr_context_t *ctp, io_devctl_t *msg,
274     ipc_ocb_t *ocb)
276     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
277         (_DEVCTL_DATA (msg->i));
278     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
279         (_DEVCTL_DATA (msg->o));
280     String name = (String)(cargs+1);
282     Ptr    entry;
284     GT_assert (curTrace, (name != NULL));
286     entry = NameServer_addUInt32 (cargs->args.addUInt32.handle,
287                                   name,
288                                   cargs->args.addUInt32.value);
289     GT_assert (curTrace, (entry != NULL));
291     out->args.addUInt32.entry = entry;
293     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
294         sizeof(NameServerDrv_CmdArgs)));
297 /**
298  * Handler for nameserver get  API.
299  *
300  * \param ctp   Thread's associated context information.
301  * \param msg   The actual devctl() message.
302  * \param ocb   OCB associated with client's session.
303  *
304  * \return POSIX errno value.
305  *
306  * \retval EOK      Success.
307  * \retval ENOTSUP  Unsupported devctl().
308  */
309 int ipc_nameserver_getuint32(resmgr_context_t *ctp, io_devctl_t *msg,
310     ipc_ocb_t *ocb)
312     UInt32                      value;
313     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
314         (_DEVCTL_DATA (msg->i));
315     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
316         (_DEVCTL_DATA (msg->o));
318     char * name  = (char *)(cargs + 1);
319     UInt16 * procId = NULL;
322     if (cargs->args.getUInt32.procId[0] != (UInt16)-1) {
323         procId = (UInt16 *)(name + (sizeof(char) * strlen(name)));
324     }
326     out->apiStatus = NameServer_getUInt32 (cargs->args.getUInt32.handle,
327                              (String)name,
328                              (Ptr)&value,
329                              procId);
331     out->args.getUInt32.value = value;
333     /* Do not assert. This can return NameServer_E_NOTFOUND
334      * as a valid runtime failure.
335      */
337     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
338         sizeof(NameServerDrv_CmdArgs)));
341 /**
342  * Handler for nameserver remove API.
343  *
344  * \param ctp   Thread's associated context information.
345  * \param msg   The actual devctl() message.
346  * \param ocb   OCB associated with client's session.
347  *
348  * \return POSIX errno value.
349  *
350  * \retval EOK      Success.
351  * \retval ENOTSUP  Unsupported devctl().
352  */
353 int ipc_nameserver_remove(resmgr_context_t *ctp, io_devctl_t *msg,
354     ipc_ocb_t *ocb)
356     NameServerDrv_CmdArgs * cargs = (NameServerDrv_CmdArgs *)
357         (_DEVCTL_DATA (msg->i));
358     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));
359     String name = (String)(cargs+1);
361     out->apiStatus = NameServer_remove (cargs->args.remove.handle, name);
363     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
364         sizeof(NameServerDrv_CmdArgs)));
367 /**
368  * Handler for nameserver remove entry API.
369  *
370  * \param ctp   Thread's associated context information.
371  * \param msg   The actual devctl() message.
372  * \param ocb   OCB associated with client's session.
373  *
374  * \return POSIX errno value.
375  *
376  * \retval EOK      Success.
377  * \retval ENOTSUP  Unsupported devctl().
378  */
379 int ipc_nameserver_removeentry(resmgr_context_t *ctp, io_devctl_t *msg,
380     ipc_ocb_t *ocb)
382     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
383         (_DEVCTL_DATA (msg->i));
384     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
385         (_DEVCTL_DATA (msg->o));
387     out->apiStatus = NameServer_removeEntry (cargs->args.removeEntry.handle,
388                                     cargs->args.removeEntry.entry);
390     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
391         sizeof(NameServerDrv_CmdArgs)));
394 /**
395  * Handler for nameserver params init API.
396  *
397  * \param ctp   Thread's associated context information.
398  * \param msg   The actual devctl() message.
399  * \param ocb   OCB associated with client's session.
400  *
401  * \return POSIX errno value.
402  *
403  * \retval EOK      Success.
404  * \retval ENOTSUP  Unsupported devctl().
405  */
406 int ipc_nameserver_params_init(resmgr_context_t *ctp, io_devctl_t *msg,
407     ipc_ocb_t *ocb)
409     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
410         (_DEVCTL_DATA (msg->i));
412     NameServer_Params *params = (NameServer_Params *)(cargs+1);
414     NameServer_Params_init (params);
416     SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) +
417         sizeof(NameServerDrv_CmdArgs));
418     SETIOV(&ctp->iov[1], params, sizeof(NameServer_Params));
420     return _RESMGR_NPARTS(2);
423 /**
424  * Handler for nameserver create API.
425  *
426  * \param ctp   Thread's associated context information.
427  * \param msg   The actual devctl() message.
428  * \param ocb   OCB associated with client's session.
429  *
430  * \return POSIX errno value.
431  *
432  * \retval EOK      Success.
433  * \retval ENOTSUP  Unsupported devctl().
434  */
435 int ipc_nameserver_create(resmgr_context_t *ctp, io_devctl_t *msg,
436     ipc_ocb_t *ocb)
438     NameServerDrv_CmdArgs *     cargs = (NameServerDrv_CmdArgs *)
439         (_DEVCTL_DATA (msg->i));
440     NameServerDrv_CmdArgs *     out  = (NameServerDrv_CmdArgs *)
441         (_DEVCTL_DATA (msg->o));
442     NameServer_Params *         params = (NameServer_Params *)(cargs+1);
443     String name = (String)(params+1);
445     out->args.create.handle = NameServer_create (name, params);
446     GT_assert (curTrace, (out->args.create.handle != NULL));
448     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
449         sizeof(NameServerDrv_CmdArgs)));
452 /**
453  * Handler for nameserver delete API.
454  *
455  * \param ctp   Thread's associated context information.
456  * \param msg   The actual devctl() message.
457  * \param ocb   OCB associated with client's session.
458  *
459  * \return POSIX errno value.
460  *
461  * \retval EOK      Success.
462  * \retval ENOTSUP  Unsupported devctl().
463  */
464 int ipc_nameserver_delete(resmgr_context_t *ctp, io_devctl_t *msg,
465     ipc_ocb_t *ocb)
467     NameServerDrv_CmdArgs * cargs = (NameServerDrv_CmdArgs *)
468         (_DEVCTL_DATA (msg->i));
469     NameServerDrv_CmdArgs * out  = (NameServerDrv_CmdArgs *)
470         (_DEVCTL_DATA (msg->o));
472     out->apiStatus = NameServer_delete (&(cargs->args.delete.handle));
473     GT_assert (curTrace, (out->apiStatus >= 0));
475     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
476         sizeof(NameServerDrv_CmdArgs)));
479 /**
480  * Handler for nameserver setup  API.
481  *
482  * \param ctp   Thread's associated context information.
483  * \param msg   The actual devctl() message.
484  * \param ocb   OCB associated with client's session.
485  *
486  * \return POSIX errno value.
487  *
488  * \retval EOK      Success.
489  * \retval ENOTSUP  Unsupported devctl().
490  */
491 int ipc_nameserver_setup(resmgr_context_t *ctp, io_devctl_t *msg,
492     ipc_ocb_t *ocb)
494     NameServerDrv_CmdArgs * out  = (NameServerDrv_CmdArgs *)
495         (_DEVCTL_DATA (msg->o));
497     out->apiStatus = NameServer_setup ();
498     GT_assert (curTrace, (out->apiStatus >= 0));
500     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
501         sizeof(NameServerDrv_CmdArgs)));
504 /**
505  * Handler for nameserver destroy API.
506  *
507  * \param ctp   Thread's associated context information.
508  * \param msg   The actual devctl() message.
509  * \param ocb   OCB associated with client's session.
510  *
511  * \return POSIX errno value.
512  *
513  * \retval EOK      Success.
514  * \retval ENOTSUP  Unsupported devctl().
515  */
516 int ipc_nameserver_destroy(resmgr_context_t *ctp, io_devctl_t *msg,
517     ipc_ocb_t *ocb)
519     NameServerDrv_CmdArgs * out  = (NameServerDrv_CmdArgs *)
520         (_DEVCTL_DATA (msg->o));
522     out->apiStatus = NameServer_destroy ();
523     GT_assert (curTrace, (out->apiStatus >= 0));
525     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
526         sizeof(NameServerDrv_CmdArgs)));