1 /*
2 * Copyright (c) 2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * ======== NameServer.c ========
34 */
35 #include <Std.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <errno.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44 #include <time.h>
46 #include <ti/ipc/NameServer.h>
47 #include <_IpcLog.h>
48 #include <_MultiProc.h>
49 #include <ti/syslink/inc/IoctlDefs.h>
50 #include <ti/syslink/inc/usr/Qnx/NameServerDrv.h>
51 #include <ti/syslink/inc/NameServerDrvDefs.h>
53 static Bool verbose = FALSE;
56 /*
57 * The NameServer_*() APIs are reproduced here. These versions are just
58 * front-ends for communicating with the actual NameServer module (currently
59 * implemented in the IPC driver process acting as a daemon).
60 */
62 Int NameServer_setup(Void)
63 {
64 Int status;
65 NameServerDrv_CmdArgs cmdArgs;
67 status = NameServerDrv_ioctl (CMD_NAMESERVER_SETUP, &cmdArgs);
68 if (status < 0) {
69 PRINTVERBOSE1("NameServer_setup: API (through IOCTL) failed, \
70 status=%d\n", status)
71 }
73 return status;
74 }
76 Int NameServer_destroy(Void)
77 {
78 Int status;
80 NameServerDrv_CmdArgs cmdArgs;
82 PRINTVERBOSE0("NameServer_destroy: entered\n")
84 status = NameServerDrv_ioctl (CMD_NAMESERVER_DESTROY, &cmdArgs);
86 if (status < 0) {
87 PRINTVERBOSE1("NameServer_destroy: API (through IOCTL) failed, \
88 status=%d\n", status)
89 }
91 return status;
92 }
94 Void NameServer_Params_init(NameServer_Params *params)
95 {
96 Int status;
97 NameServerDrv_CmdArgs cmdArgs;
99 cmdArgs.args.ParamsInit.params = params;
100 status = NameServerDrv_ioctl (CMD_NAMESERVER_PARAMS_INIT, &cmdArgs);
102 if (status < 0) {
103 PRINTVERBOSE1("NameServer_Params_init: API (through IOCTL) failed, \
104 status=%d\n", status)
105 return;
106 }
108 return;
109 }
111 NameServer_Handle NameServer_create(String name,
112 const NameServer_Params *params)
113 {
114 Int status;
115 NameServerDrv_CmdArgs cmdArgs;
117 cmdArgs.args.create.name = name;
118 cmdArgs.args.create.nameLen = strlen (name) + 1;
119 cmdArgs.args.create.params = (NameServer_Params *) params;
121 status = NameServerDrv_ioctl (CMD_NAMESERVER_CREATE, &cmdArgs);
123 if (status < 0) {
124 PRINTVERBOSE1("NameServer_create: API (through IOCTL) failed, \
125 status=%d\n", status)
126 return NULL;
127 }
129 return cmdArgs.args.create.handle;
130 }
132 Ptr NameServer_addUInt32(NameServer_Handle nsHandle, String name, UInt32 value)
133 {
134 Int status;
135 NameServerDrv_CmdArgs cmdArgs;
137 cmdArgs.args.addUInt32.handle = nsHandle;
138 cmdArgs.args.addUInt32.name = name;
139 cmdArgs.args.addUInt32.nameLen = strlen(name) + 1;
140 cmdArgs.args.addUInt32.value = value;
141 status = NameServerDrv_ioctl(CMD_NAMESERVER_ADDUINT32, &cmdArgs);
143 if (status < 0) {
144 PRINTVERBOSE1("NameServer_addUInt32: API (through IOCTL) failed, \
145 status=%d\n", status)
146 return NULL;
147 }
149 return cmdArgs.args.addUInt32.entry;
150 }
152 Int NameServer_getUInt32(NameServer_Handle nsHandle, String name, Ptr buf,
153 UInt16 procId[])
154 {
155 Int status;
156 UInt32 *val;
157 NameServerDrv_CmdArgs cmdArgs;
159 cmdArgs.args.getUInt32.name = name;
160 cmdArgs.args.getUInt32.handle = nsHandle;
161 if (procId != NULL) {
162 memcpy(cmdArgs.args.getUInt32.procId, procId,
163 sizeof(UInt16) * MultiProc_MAXPROCESSORS);
164 }
165 else {
166 cmdArgs.args.getUInt32.procId[0] = (UInt16)-1;
167 }
168 status = NameServerDrv_ioctl (CMD_NAMESERVER_GETUINT32, &cmdArgs);
170 if (status < 0) {
171 PRINTVERBOSE1("NameServer_getUInt32: API (through IOCTL) failed, \
172 status=%d\n", status)
173 return status;
174 }
176 val = (UInt32 *)buf;
177 *val = cmdArgs.args.getUInt32.value;
179 return status;
180 }
182 Int NameServer_remove(NameServer_Handle nsHandle, String name)
183 {
184 Int status;
185 NameServerDrv_CmdArgs cmdArgs;
187 cmdArgs.args.remove.handle = nsHandle;
188 cmdArgs.args.remove.name = name;
189 cmdArgs.args.remove.nameLen = strlen(name) + 1;
190 status = NameServerDrv_ioctl(CMD_NAMESERVER_REMOVE, &cmdArgs);
192 if (status < 0) {
193 PRINTVERBOSE1("NameServer_remove: API (through IOCTL) failed, \
194 status=%d\n", status)
195 }
197 return status;
198 }
200 Int NameServer_removeEntry(NameServer_Handle nsHandle, Ptr entry)
201 {
202 Int status;
203 NameServerDrv_CmdArgs cmdArgs;
205 cmdArgs.args.removeEntry.handle = nsHandle;
206 cmdArgs.args.removeEntry.entry = entry;
207 status = NameServerDrv_ioctl (CMD_NAMESERVER_REMOVEENTRY, &cmdArgs);
209 if (status < 0) {
210 PRINTVERBOSE1("NameServer_removeEntry: API (through IOCTL) failed, \
211 status=%d\n", status)
212 }
214 return status;
215 }
217 Int NameServer_delete(NameServer_Handle *nsHandle)
218 {
219 Int status;
220 NameServerDrv_CmdArgs cmdArgs;
222 cmdArgs.args.delete.handle = *nsHandle;
223 status = NameServerDrv_ioctl (CMD_NAMESERVER_DELETE, &cmdArgs);
225 if (status < 0) {
226 PRINTVERBOSE1("NameServer_delete: API (through IOCTL) failed, \
227 status=%d\n", status)
228 return status;
229 }
231 *nsHandle = cmdArgs.args.delete.handle;
233 return status;
234 }