091870522ade5d9e4dd986ff638a3d65f31a1254
1 /**\r
2 * @file rm.c\r
3 *\r
4 * @brief \r
5 * This is the Resource Manager source.\r
6 *\r
7 * \par\r
8 * ============================================================================\r
9 * @n (C) Copyright 2012, Texas Instruments, Inc.\r
10 * \r
11 * Redistribution and use in source and binary forms, with or without \r
12 * modification, are permitted provided that the following conditions \r
13 * are met:\r
14 *\r
15 * Redistributions of source code must retain the above copyright \r
16 * notice, this list of conditions and the following disclaimer.\r
17 *\r
18 * Redistributions in binary form must reproduce the above copyright\r
19 * notice, this list of conditions and the following disclaimer in the \r
20 * documentation and/or other materials provided with the \r
21 * distribution.\r
22 *\r
23 * Neither the name of Texas Instruments Incorporated nor the names of\r
24 * its contributors may be used to endorse or promote products derived\r
25 * from this software without specific prior written permission.\r
26 *\r
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
38 *\r
39 * \par\r
40 */\r
41 \r
42 /* RM Types */\r
43 #include <ti/drv/rm/rm_types.h>\r
44 \r
45 /* RM external includes */\r
46 #include <ti/drv/rm/rm.h>\r
47 #include <ti/drv/rm/rm_transport.h>\r
48 \r
49 /* RM internal includes */\r
50 #include <ti/drv/rm/include/rm_loc.h>\r
51 #include <ti/drv/rm/include/rm_transportloc.h>\r
52 \r
53 /* RM OSAL layer */\r
54 #include <rm_osal.h>\r
55 \r
56 /**********************************************************************\r
57 ********************** Internal Functions ****************************\r
58 **********************************************************************/\r
59 \r
60 Rm_TransportNode *Rm_transportNodeAdd(Rm_Inst *rmInst, Rm_TransportCfg *transportCfg)\r
61 {\r
62 Rm_TransportNode *routeMap = (Rm_TransportNode *)rmInst->routeMap;\r
63 Rm_TransportNode *newTransportNode = NULL;\r
64 \r
65 /* Get memory for a new transport node from local memory */\r
66 newTransportNode = Rm_osalMalloc (sizeof(Rm_TransportNode));\r
67 \r
68 /* Return if the memory allocated for the transport node is NULL */\r
69 if (newTransportNode != NULL)\r
70 {\r
71 /* Populate the new entry */\r
72 newTransportNode->rmHandle = (Rm_Handle) rmInst;\r
73 newTransportNode->remoteInstType = transportCfg->remoteInstType;\r
74 strcpy(&(newTransportNode->remoteInstName)[0], transportCfg->remoteInstName);\r
75 newTransportNode->nextNode = NULL; /* New node will always be NULL */\r
76 \r
77 /* Check if there are any nodes in the transport routing map */\r
78 if (routeMap)\r
79 {\r
80 /* At least one node in the routing map. Add the new node to the end of the\r
81 * routing map */\r
82 while (routeMap->nextNode != NULL)\r
83 {\r
84 /* Traverse the list until arriving at the last node */\r
85 routeMap = (Rm_TransportNode *)routeMap->nextNode;\r
86 }\r
87 \r
88 /* Add the new node to the end of the list */\r
89 routeMap->nextNode = (void *)newTransportNode;\r
90 }\r
91 else\r
92 {\r
93 /* The transport routing map does not currently exist. The new node is the first node */\r
94 rmInst->routeMap = (void *)newTransportNode;\r
95 }\r
96 }\r
97 \r
98 return (newTransportNode);\r
99 }\r
100 \r
101 Rm_TransportNode *Rm_transportNodeFindTransportHandle(Rm_Inst *rmInst, \r
102 Rm_TransportHandle transportHandle)\r
103 {\r
104 Rm_TransportNode *transportNode = (Rm_TransportNode *)rmInst->routeMap;\r
105 \r
106 /* Make sure there is at least one node in the route map */\r
107 if (transportNode != NULL)\r
108 {\r
109 /* Find the transport node with the transport handle within the RM instance's\r
110 * route map. If the end of the route map is reached without finding the node the \r
111 * node pointer will be NULL */\r
112 while (transportNode != NULL)\r
113 {\r
114 /* The transport handle is the address of the transport node */\r
115 if (transportNode == ((Rm_TransportNode *)transportHandle))\r
116 {\r
117 /* Match: break out of loop and return the node */\r
118 break; \r
119 }\r
120 transportNode = (Rm_TransportNode *)transportNode->nextNode;\r
121 }\r
122 }\r
123 \r
124 return (transportNode);\r
125 }\r
126 \r
127 Rm_TransportNode *Rm_transportNodeFindRemoteName(Rm_Inst *rmInst, char *remoteName)\r
128 {\r
129 Rm_TransportNode *transportNode = (Rm_TransportNode *)rmInst->routeMap;\r
130 \r
131 /* Make sure there is at least one node in the route map */\r
132 if (transportNode != NULL)\r
133 {\r
134 /* Find the transport node with the provided remote instance name.\r
135 * If the end of the route map is reached without finding the node the \r
136 * node pointer will be NULL */\r
137 while (transportNode != NULL)\r
138 {\r
139 /* The transport handle is the address of the transport node */\r
140 if (strcmp(&(transportNode->remoteInstName)[0], remoteName) == 0)\r
141 {\r
142 /* Match: break out of loop and return the node */\r
143 break; \r
144 }\r
145 transportNode = (Rm_TransportNode *)transportNode->nextNode;\r
146 }\r
147 }\r
148 \r
149 return (transportNode);\r
150 }\r
151 \r
152 Rm_TransportNode *Rm_transportNodeFindRemoteInstType(Rm_Inst *rmInst,\r
153 Rm_InstType remoteInstType)\r
154 {\r
155 Rm_TransportNode *transportNode = (Rm_TransportNode *)rmInst->routeMap;\r
156 \r
157 /* Make sure there is at least one node in the route map */\r
158 if (transportNode != NULL)\r
159 {\r
160 /* Find the transport node with the provided remote instance type.\r
161 * If the end of the route map is reached without finding the node the \r
162 * node pointer will be NULL */\r
163 while (transportNode != NULL)\r
164 {\r
165 if (transportNode->remoteInstType == remoteInstType)\r
166 {\r
167 /* Match: break out of loop and return the node */\r
168 break; \r
169 }\r
170 transportNode = (Rm_TransportNode *)transportNode->nextNode;\r
171 }\r
172 }\r
173 \r
174 return (transportNode);\r
175 }\r
176 \r
177 Rm_TransportResult Rm_transportNodeDelete(Rm_Inst *rmInst, Rm_TransportHandle transportHandle)\r
178 {\r
179 Rm_TransportNode *transportNode = (Rm_TransportNode *)rmInst->routeMap;\r
180 Rm_TransportNode *prevNode = NULL;\r
181 \r
182 /* Make sure there is at least one entry in the transaction queue */\r
183 if (transportNode == NULL)\r
184 {\r
185 return (RM_TRANSPORT_ERROR_NO_TRANSPORTS_REGISTERED);\r
186 }\r
187 \r
188 /* Find the transport handle within the RM instance's route map. */\r
189 while (transportNode != NULL)\r
190 {\r
191 if (transportNode == (Rm_TransportNode *) transportHandle)\r
192 {\r
193 /* Match: break out of loop and delete the entry */\r
194 break; \r
195 }\r
196 \r
197 prevNode = transportNode;\r
198 transportNode = (Rm_TransportNode *)transportNode->nextNode;\r
199 }\r
200 \r
201 /* Traversed entire queue but did not find transaction */\r
202 if (transportNode == NULL)\r
203 {\r
204 return (RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED);\r
205 }\r
206 else\r
207 {\r
208 /* Delete the transport node */\r
209 if (prevNode == NULL)\r
210 {\r
211 /* Node to be deleted exists at start of route map. Map second\r
212 * node to be start of route map as long as there are more than\r
213 * one nodes */\r
214 rmInst->routeMap = transportNode->nextNode;\r
215 }\r
216 else\r
217 {\r
218 /* Node to be deleted is in the middle or at end of the route map. Adjust adjacent\r
219 * node pointers. This covers the case where the node to be removed is at the\r
220 * end of the route map. */\r
221 prevNode->nextNode = transportNode->nextNode;\r
222 }\r
223 \r
224 /* Free the memory associated with the node. */\r
225 Rm_osalFree((void *) transportNode, sizeof(Rm_TransportNode));\r
226 }\r
227 \r
228 return (RM_TRANSPORT_SUCCESSFUL);\r
229 }\r
230 \r
231 Rm_Packet *Rm_transportCreateResourceReqPkt(Rm_Inst *rmInst, Rm_TransportNode *dstTransportNode,\r
232 Rm_Transaction *transaction)\r
233 {\r
234 Rm_Packet *rmPkt = NULL;\r
235 Rm_ResourceRequestPkt *resourceReqPkt = NULL;\r
236 \r
237 /* Make sure a buffer for the packet was allocated */\r
238 if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransportNode, sizeof(Rm_Packet))) ==\r
239 NULL)\r
240 {\r
241 transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
242 return (NULL);\r
243 }\r
244 \r
245 /* Make sure allocated buffer is large enough to fit the request packet plus the \r
246 * rmPktLen and Rm_PktType fields */\r
247 if (rmPkt->pktLenBytes < (sizeof(Rm_ResourceRequestPkt) + sizeof(uint32_t) + sizeof(Rm_pktType)))\r
248 { \r
249 transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
250 return (NULL);\r
251 }\r
252 \r
253 /* Set the Rm Packet type */ \r
254 rmPkt->pktType = Rm_pktType_RESOURCE_REQUEST;\r
255 \r
256 /* Assign the packet's data field to be the start of the resource request packet */\r
257 resourceReqPkt = (Rm_ResourceRequestPkt *) rmPkt->data;\r
258 /* Populate the resource request packet using the transaction information */\r
259 resourceReqPkt->requestId = transaction->localId;\r
260 if (transaction->type == Rm_service_RESOURCE_ALLOCATE)\r
261 {\r
262 resourceReqPkt->resourceReqType = Rm_resReqPktType_ALLOCATE;\r
263 }\r
264 else if (transaction->type == Rm_service_RESOURCE_FREE)\r
265 {\r
266 resourceReqPkt->resourceReqType = Rm_resReqPktType_FREE;\r
267 }\r
268 else if (transaction->type == Rm_service_RESOURCE_GET_BY_NAME)\r
269 {\r
270 resourceReqPkt->resourceReqType = Rm_resReqPktType_GET_NAMED;\r
271 }\r
272 /* Pass along the packet source and service source information */\r
273 strcpy(resourceReqPkt->pktSrcInstName, rmInst->name);\r
274 strcpy(resourceReqPkt->serviceSrcInstName, transaction->serviceSrcInstName);\r
275 /* Copy the resource data */\r
276 memcpy ((void *)&(resourceReqPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
277 sizeof(Rm_ResourceInfo));\r
278 \r
279 return (rmPkt);\r
280 }\r
281 \r
282 Rm_Packet *Rm_transportCreateResourceResponsePkt(Rm_Inst *rmInst, Rm_TransportNode *dstTransportNode,\r
283 Rm_Transaction *transaction)\r
284 {\r
285 Rm_Packet *rmPkt = NULL;\r
286 Rm_ResourceResponsePkt *resourceRespPkt = NULL;\r
287 \r
288 /* Make sure a buffer for the packet was allocated */\r
289 if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransportNode, sizeof(Rm_Packet))) ==\r
290 NULL)\r
291 {\r
292 transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
293 return (NULL);\r
294 }\r
295 \r
296 /* Make sure allocated buffer is large enough to fit the request packet plus the \r
297 * rmPktLen and Rm_PktType fields */\r
298 if (rmPkt->pktLenBytes < (sizeof(Rm_ResourceResponsePkt) + sizeof(uint32_t) + sizeof(Rm_pktType)))\r
299 { \r
300 transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
301 return (NULL);\r
302 }\r
303 \r
304 /* Set the Rm Packet type */ \r
305 rmPkt->pktType = Rm_pktType_RESOURCE_RESPONSE;\r
306 \r
307 /* Assign the packet's data field to be the start of the resource response packet */\r
308 resourceRespPkt = (Rm_ResourceResponsePkt *)rmPkt->data;\r
309 /* Populate the resource response packet using the transaction information. The\r
310 * responseId is the remoteOriginatingId. The responseId must match the local ID \r
311 * of the transaction that originated the request */\r
312 resourceRespPkt->responseId = transaction->remoteOriginatingId;\r
313 resourceRespPkt->requestState = transaction->state;\r
314 /* Copy the resource data */\r
315 memcpy ((void *)&(resourceRespPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
316 sizeof(Rm_ResourceInfo));\r
317 \r
318 return (rmPkt);\r
319 }\r
320 \r
321 Rm_Packet *Rm_transportCreateNsRequestPkt(Rm_Inst *rmInst, Rm_TransportNode *dstTransportNode,\r
322 Rm_Transaction *transaction)\r
323 {\r
324 Rm_Packet *rmPkt = NULL;\r
325 Rm_NsRequestPkt *nsReqPkt = NULL;\r
326 \r
327 /* Make sure a buffer for the packet was allocated */\r
328 if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransportNode, sizeof(Rm_Packet))) ==\r
329 NULL)\r
330 {\r
331 transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
332 return (NULL);\r
333 }\r
334 \r
335 /* Make sure allocated buffer is large enough to fit the request packet plus the \r
336 * rmPktLen and Rm_PktType fields */\r
337 if (rmPkt->pktLenBytes < (sizeof(Rm_NsRequestPkt) + sizeof(uint32_t) + sizeof(Rm_pktType)))\r
338 { \r
339 transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
340 return (NULL);\r
341 }\r
342 \r
343 /* Set the Rm Packet type */ \r
344 rmPkt->pktType = Rm_pktType_NAMESERVER_REQUEST;\r
345 \r
346 /* Assign the packet's data field to be the start of the NameServer request packet */\r
347 nsReqPkt = (Rm_NsRequestPkt *)rmPkt->data;\r
348 /* Populate the NameServer request packet using the transaction information */\r
349 nsReqPkt->requestId = transaction->localId;\r
350 if (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME)\r
351 {\r
352 nsReqPkt->nsRequestType = Rm_nsReqPktType_MAP_RESOURCE;\r
353 }\r
354 else if (transaction->type == Rm_service_RESOURCE_UNMAP_NAME)\r
355 {\r
356 nsReqPkt->nsRequestType = Rm_nsReqPktType_UNMAP_RESOURCE;\r
357 }\r
358 /* Pass along the packet source and service source information */\r
359 strcpy(nsReqPkt->pktSrcInstName, rmInst->name);\r
360 strcpy(nsReqPkt->serviceSrcInstName, transaction->serviceSrcInstName);\r
361 /* Copy the NameServer request data */\r
362 memcpy ((void *)&(nsReqPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
363 sizeof(Rm_ResourceInfo));\r
364 \r
365 return (rmPkt);\r
366 }\r
367 \r
368 Rm_Packet *Rm_transportCreateNsResponsePkt(Rm_Inst *rmInst, Rm_TransportNode *dstTransportNode,\r
369 Rm_Transaction *transaction)\r
370 {\r
371 Rm_Packet *rmPkt = NULL;\r
372 Rm_NsResponsePkt *nsRespPkt = NULL;\r
373 \r
374 /* Make sure a buffer for the packet was allocated */\r
375 if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransportNode, sizeof(Rm_Packet))) ==\r
376 NULL)\r
377 {\r
378 transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
379 return (NULL);\r
380 }\r
381 \r
382 /* Make sure allocated buffer is large enough to fit the response packet plus the \r
383 * rmPktLen and Rm_PktType fields */\r
384 if (rmPkt->pktLenBytes < (sizeof(Rm_NsResponsePkt) + sizeof(uint32_t) + sizeof(Rm_pktType)))\r
385 { \r
386 transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
387 return (NULL);\r
388 }\r
389 \r
390 /* Set the Rm Packet type */ \r
391 rmPkt->pktType = Rm_pktType_NAMESERVER_RESPONSE;\r
392 \r
393 /* Assign the packet's data field to be the start of the NameServer response packet */\r
394 nsRespPkt = (Rm_NsResponsePkt *)rmPkt->data;\r
395 /* Populate the NameServer response packet using the transaction information. The\r
396 * responseId is the remoteOriginatingId. The responseId must match the local ID \r
397 * of the transaction that originated the request */\r
398 nsRespPkt->responseId = transaction->remoteOriginatingId;\r
399 nsRespPkt->requestState = transaction->state;\r
400 \r
401 return (rmPkt);\r
402 }\r
403 \r
404 /**********************************************************************\r
405 ********************* Application visible APIs ***********************\r
406 **********************************************************************/\r
407 \r
408 Rm_TransportHandle Rm_transportRegister (Rm_Handle rmHandle, Rm_TransportCfg *transportCfg)\r
409 {\r
410 Rm_Inst *rmInst = (Rm_Inst *) rmHandle;\r
411 Rm_TransportNode *transportNode = NULL;\r
412 void *key;\r
413 \r
414 /* Lock access to the RM instance */\r
415 key = Rm_osalMtCsEnter();\r
416 \r
417 /* RM Servers cannot connect to other Servers. RM Client Delegates cannot\r
418 * connect to other Client Delegates. */\r
419 if (((rmInst->instType == Rm_instType_SERVER) &&\r
420 (transportCfg->remoteInstType == Rm_instType_SERVER)) ||\r
421 ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
422 (transportCfg->remoteInstType == Rm_instType_CLIENT_DELEGATE)))\r
423 {\r
424 goto exitCs; /* Error - return null */\r
425 }\r
426 \r
427 /* Verify Clients are not registering with more than one Client Delegate or Server. And\r
428 * that Client Delegate are not registering with more than one Server. */\r
429 if (rmInst->registeredWithDelegateOrServer &&\r
430 (((rmInst->instType == Rm_instType_CLIENT) &&\r
431 (transportCfg->remoteInstType == Rm_instType_CLIENT_DELEGATE)) || \r
432 ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
433 (transportCfg->remoteInstType == Rm_instType_SERVER))))\r
434 {\r
435 goto exitCs; /* Error - return null */\r
436 } \r
437 \r
438 /* Copy the transport callout function pointers into the RM instance as long as they're\r
439 * valid or not NULL */\r
440 if (transportCfg->transportCalloutsValid)\r
441 {\r
442 /* The transport APIs must not be NULL */\r
443 if ((transportCfg->transportCallouts.rmAllocPkt == NULL) ||\r
444 (transportCfg->transportCallouts.rmFreePkt == NULL) ||\r
445 (transportCfg->transportCallouts.rmSend == NULL) ||\r
446 (transportCfg->transportCallouts.rmReceive == NULL) ||\r
447 (transportCfg->transportCallouts.rmNumPktsReceived == NULL))\r
448 {\r
449 goto exitCs; /* Error - return null */\r
450 }\r
451 \r
452 /* Populate the instance transport callouts */\r
453 rmInst->transport.rmAllocPkt = transportCfg->transportCallouts.rmAllocPkt;\r
454 rmInst->transport.rmFreePkt = transportCfg->transportCallouts.rmFreePkt;\r
455 rmInst->transport.rmSend = transportCfg->transportCallouts.rmSend;\r
456 rmInst->transport.rmReceive = transportCfg->transportCallouts.rmReceive;\r
457 rmInst->transport.rmNumPktsReceived = transportCfg->transportCallouts.rmNumPktsReceived;\r
458 }\r
459 \r
460 /* Error checks passed - Create a new transport handle for the specified RM instance and\r
461 * create a new node in the RM instance's routing map. */\r
462 transportNode = Rm_transportNodeAdd(rmInst, transportCfg);\r
463 \r
464 /* Specify RM instance has registered with a higher level agent */\r
465 if ((transportNode->remoteInstType == Rm_instType_CLIENT_DELEGATE) ||\r
466 (transportNode->remoteInstType == Rm_instType_SERVER))\r
467 {\r
468 rmInst->registeredWithDelegateOrServer = true;\r
469 }\r
470 \r
471 exitCs:\r
472 \r
473 Rm_osalMtCsExit(key);\r
474 return ((Rm_TransportHandle) transportNode);\r
475 }\r
476 \r
477 Rm_TransportResult Rm_transportUnregister (Rm_Handle rmHandle, Rm_TransportHandle transportHandle)\r
478 {\r
479 Rm_Inst *rmInst = (Rm_Inst *) rmHandle;\r
480 Rm_TransportNode *transportNode = NULL;\r
481 Rm_TransportResult retVal = RM_TRANSPORT_SUCCESSFUL;\r
482 void *key;\r
483 \r
484 /* Lock access to the RM instance */\r
485 key = Rm_osalMtCsEnter(); \r
486 \r
487 /* Check if the transportHandle exists in the RM instance's route map */\r
488 transportNode = Rm_transportNodeFindTransportHandle(rmInst, transportHandle);\r
489 \r
490 if (transportNode == NULL)\r
491 {\r
492 /* Error - transport node does not exist in RM instance route map */\r
493 retVal = RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED;\r
494 }\r
495 else\r
496 {\r
497 \r
498 /* Remove specification that RM instance has been connected to an upper level agent\r
499 * if the node to be deleted has a remote instance type of Client Delegate or Server */\r
500 if ((transportNode->remoteInstType == Rm_instType_CLIENT_DELEGATE) ||\r
501 (transportNode->remoteInstType == Rm_instType_SERVER))\r
502 {\r
503 rmInst->registeredWithDelegateOrServer = false;\r
504 }\r
505 \r
506 /* Delete the transport node */\r
507 retVal = Rm_transportNodeDelete(rmInst, transportHandle);\r
508 }\r
509 \r
510 Rm_osalMtCsExit(key);\r
511 return (retVal);\r
512 }\r
513 \r
514 /* Used by the application to pass RM packets received from a transport to RM.\r
515 * CODE THE FUNCTION SUCH THAT IT CAN BE CALLED DIRECTLY BY APP OR BE PLUGGED\r
516 * AS PART OF AN ISR HANDLER FOR THE TRANSACTION RECEIVE */\r
517 int32_t Rm_receivePktIsr(Rm_TransportHandle transportHandle, Rm_Packet *pkt)\r
519 Rm_Inst *rmInst = (Rm_Inst *)((Rm_TransportNode *)transportHandle)->rmHandle;\r
520 Rm_Transaction *transaction;\r
521 \r
522 /* Make sure the transport handle is registered with the provided RM instance */\r
523 if (Rm_transportNodeFindTransportHandle(rmInst, transportHandle) == NULL)\r
524 {\r
525 /* Transport is not registered with the RM instance. Return an error.\r
526 * The packet cannot be freed since the transport handle is not valid. */\r
527 return (RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED);\r
528 }\r
529 \r
530 /* Based on packet type transfer the data to a transaction or a policy structure */\r
531 switch (pkt->pktType)\r
532 {\r
533 case Rm_pktType_RESOURCE_REQUEST:\r
534 {\r
535 Rm_ResourceRequestPkt *resourceReqPkt = (Rm_ResourceRequestPkt *)pkt->data;\r
536 \r
537 /* Create the request transaction filling in the remoteOriginatingId using\r
538 * the request packet's ID. The request packet's ID will map to the \r
539 * the request transaction that issued the request packet. */\r
540 transaction = Rm_transactionQueueAdd(rmInst);\r
541 transaction->remoteOriginatingId = resourceReqPkt->requestId;\r
542 \r
543 /* Transfer the rest of the data into the transaction */\r
544 if (resourceReqPkt->resourceReqType == Rm_resReqPktType_ALLOCATE)\r
545 {\r
546 transaction->type = Rm_service_RESOURCE_ALLOCATE;\r
547 }\r
548 else if (resourceReqPkt->resourceReqType == Rm_resReqPktType_FREE)\r
549 {\r
550 transaction->type = Rm_service_RESOURCE_FREE;\r
551 }\r
552 else if (resourceReqPkt->resourceReqType == Rm_resReqPktType_GET_NAMED)\r
553 {\r
554 transaction->type = Rm_service_RESOURCE_GET_BY_NAME;\r
555 } \r
556 \r
557 strcpy(transaction->pktSrcInstName, resourceReqPkt->pktSrcInstName);\r
558 strcpy(transaction->serviceSrcInstName, resourceReqPkt->serviceSrcInstName);\r
559 transaction->state = RM_SERVICE_PROCESSING;\r
560 memcpy ((void *)&(transaction->resourceInfo), (void *)&(resourceReqPkt->resourceInfo),\r
561 sizeof(Rm_ResourceInfo));\r
562 \r
563 /* Process the transaction */\r
564 Rm_transactionProcessor(rmInst, transaction);\r
565 break;\r
566 }\r
567 case Rm_pktType_RESOURCE_RESPONSE:\r
568 {\r
569 Rm_ResourceResponsePkt *resourceRespPkt = (Rm_ResourceResponsePkt *)pkt->data;\r
570 \r
571 /* Find the transaction that is awaiting the response */\r
572 if (transaction = Rm_transactionQueueFind(rmInst,resourceRespPkt->responseId))\r
573 {\r
574 /* Transfer the result of the request to the transaction */\r
575 transaction->state = resourceRespPkt->requestState;\r
576 \r
577 if ((transaction->state == RM_SERVICE_APPROVED_AND_COMPLETED) &&\r
578 ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||\r
579 (transaction->type == Rm_service_RESOURCE_GET_BY_NAME)))\r
580 {\r
581 /* Copy resources from request for allocations since an allocation\r
582 * can be specified as unknown. If the request resources were unspecified\r
583 * the RM instance will specify the resources obtained */\r
584 memcpy ((void *)&(transaction->resourceInfo), (void *)&(resourceRespPkt->resourceInfo),\r
585 sizeof(Rm_ResourceInfo));\r
586 }\r
587 \r
588 /* Process the transaction */\r
589 Rm_transactionProcessor(rmInst, transaction);\r
590 }\r
591 else\r
592 {\r
593 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
594 return (RM_TRANSPORT_ERROR_MATCHING_RESOURCE_REQUEST_NOT_FOUND);\r
595 }\r
596 break;\r
597 }\r
598 case Rm_pktType_NAMESERVER_REQUEST:\r
599 {\r
600 Rm_NsRequestPkt *nsRequestPkt = (Rm_NsRequestPkt *)pkt->data;\r
601 \r
602 transaction = Rm_transactionQueueAdd(rmInst);\r
603 transaction->remoteOriginatingId = nsRequestPkt->requestId;\r
604 \r
605 if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_MAP_RESOURCE)\r
606 {\r
607 transaction->type = Rm_service_RESOURCE_MAP_TO_NAME;\r
608 }\r
609 else if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_UNMAP_RESOURCE)\r
610 {\r
611 transaction->type = Rm_service_RESOURCE_UNMAP_NAME;\r
612 }\r
613 \r
614 strcpy(transaction->pktSrcInstName, nsRequestPkt->pktSrcInstName);\r
615 strcpy(transaction->serviceSrcInstName, nsRequestPkt->serviceSrcInstName);\r
616 transaction->state = RM_SERVICE_PROCESSING;\r
617 memcpy ((void *)&(transaction->resourceInfo), (void *)&(nsRequestPkt->resourceInfo),\r
618 sizeof(Rm_ResourceInfo));\r
619 \r
620 /* Process the transaction */\r
621 Rm_transactionProcessor(rmInst, transaction); \r
622 break;\r
623 }\r
624 case Rm_pktType_NAMESERVER_RESPONSE:\r
625 {\r
626 Rm_NsResponsePkt *nsResponsePkt = (Rm_NsResponsePkt *)pkt->data;\r
627 \r
628 /* Find the transaction that is awaiting the response */\r
629 if (transaction = Rm_transactionQueueFind(rmInst, nsResponsePkt->responseId))\r
630 {\r
631 /* Transfer the state of the request to the transaction */\r
632 transaction->state = nsResponsePkt->requestState; \r
633 \r
634 /* Process the transaction */\r
635 Rm_transactionProcessor(rmInst, transaction);\r
636 }\r
637 else\r
638 {\r
639 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
640 return (RM_TRANSPORT_ERROR_MATCHING_NAME_SERVER_REQUEST_NOT_FOUND);\r
641 }\r
642 break;\r
643 }\r
644 case Rm_pktType_POLICY_REQUEST:\r
645 {\r
646 Rm_PolicyRequestPkt *policyRequestPkt = (Rm_PolicyRequestPkt *)pkt->data;\r
647 \r
648 /* FILL IN POLICY API INFORMATION */\r
649 break; \r
650 }\r
651 case Rm_pktType_POLICY_CHANGE:\r
652 {\r
653 Rm_PolicyChangePkt *policyChangePkt = (Rm_PolicyChangePkt *)pkt->data;\r
654 \r
655 /* FILL IN POLICY API INFORMATION */\r
656 break;\r
657 }\r
658 case Rm_pktType_RESOURCE_POOL_MODIFICATION_REQUEST:\r
659 {\r
660 Rm_ResourcePoolModRequestPkt *resPoolModReqPkt = (Rm_ResourcePoolModRequestPkt *)pkt->data;\r
661 \r
662 /* FILL IN RESOURCE POOL MODIFICATION API */\r
663 /* Rm_resourcePoolModRequestHandler(...); Server only - needs to allocate resources to\r
664 * the Client Delegate based on the policy and return those resources to the Client Delegate */\r
665 break;\r
666 }\r
667 case Rm_pktType_RESOURCE_POOL_MODIFICATION_RESPONSE:\r
668 {\r
669 Rm_ResourcePoolModResponsePkt *resPoolModRespPkt = (Rm_ResourcePoolModResponsePkt *)pkt->data;\r
670 \r
671 /* FILL IN RESOURCE POOL MODIFICAITON API */\r
672 /* Rm_resourcePoolModResponseHandler(...); Handler needs to populate allocator with\r
673 * new resources provided in the response and then handle any request transactions waiting on\r
674 * the resource pool modification */\r
675 break;\r
676 }\r
677 default:\r
678 /* Invalid packet type. Free the packet and return */\r
679 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
680 return (RM_TRANSPORT_ERROR_INVALID_PACKET_TYPE);\r
681 }\r
682 \r
683 /* Free the packet after it has been processed */\r
684 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
685 return (RM_TRANSPORT_SUCCESSFUL);\r
686 }\r
687 \r
688 /* Application can call this API so that RM handles reception of packets based on\r
689 * the RM handle and transport handle provided */\r
690 int32_t Rm_receivePktPolling(Rm_TransportHandle transportHandle)\r
691 {\r
692 Rm_Inst *rmInst = (Rm_Inst *)((Rm_TransportNode *)transportHandle)->rmHandle;\r
693 Rm_Packet *pkt = NULL;\r
694 int32_t retVal = RM_TRANSPORT_OK_BASE;\r
695 \r
696 /* Make sure the transport handle is registered with the provided RM instance */\r
697 if (Rm_transportNodeFindTransportHandle(rmInst, transportHandle) != NULL)\r
698 {\r
699 /* Check to see if any RM packets are available. Process any available packets. */\r
700 while (rmInst->transport.rmNumPktsReceived(transportHandle) > 0)\r
701 {\r
702 pkt = rmInst->transport.rmReceive(transportHandle);\r
703 \r
704 if (pkt == NULL)\r
705 {\r
706 retVal = RM_TRANSPORT_ERROR_PACKET_RECEPTION_ERROR;\r
707 break;\r
708 }\r
709 \r
710 /* Pass the packet to RM. The packet will be freed within the PktIsr API */\r
711 if (retVal = Rm_receivePktIsr(transportHandle, pkt) <= RM_SERVICE_ERROR_BASE)\r
712 {\r
713 /* Return if an error is encountered */\r
714 break;\r
715 }\r
716 }\r
717 }\r
718 else\r
719 {\r
720 /* Transport is not registered with the RM instance. Return an error.\r
721 * The packet cannot be freed since the transport handle is not valid. */\r
722 retVal = RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED;\r
723 }\r
724 \r
725 return (retVal); \r
726 }\r
727 \r
728 /**\r
729 @}\r
730 */\r