API naming convention cleanup, switch to strncpy, renamed resourceNode allocatedTo...
[keystone-rtos/rm-lld.git] / src / rm_transport.c
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_Transport *transportAdd(Rm_TransportCfg *transportCfg)\r
61 {\r
62     Rm_Inst      *rmInst = (Rm_Inst *) transportCfg->rmHandle;\r
63     Rm_Transport *transports = rmInst->transports;\r
64     Rm_Transport *newTransport = NULL;\r
65 \r
66     newTransport = Rm_osalMalloc (sizeof(Rm_Transport));\r
67 \r
68     if (newTransport) {\r
69         newTransport->rmHandle = transportCfg->rmHandle;\r
70         newTransport->remoteInstType = transportCfg->remoteInstType;\r
71         strncpy(&(newTransport->remoteInstName)[0], transportCfg->remoteInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
72         newTransport->nextTransport = NULL;\r
73 \r
74         if (transports) {\r
75             while (transports->nextTransport != NULL) {\r
76                 transports = transports->nextTransport;\r
77             }\r
78             transports->nextTransport = newTransport;\r
79         }\r
80         else {\r
81             rmInst->transports = (void *) newTransport;\r
82         }\r
83     }\r
84     return (newTransport);\r
85 }\r
86 \r
87 Rm_Transport *transportFindTransportHandle(Rm_Transport *transports, \r
88                                            Rm_TransportHandle transportHandle)\r
89 {\r
90     while (transports) {\r
91         if (transports == ((Rm_Transport *)transportHandle)) {\r
92             break;             \r
93         }\r
94         transports = transports->nextTransport;\r
95     }\r
96     return (transports);\r
97 }\r
98 \r
99 Rm_TransportResult transportDelete(Rm_Handle rmHandle, Rm_TransportHandle transportHandle)\r
100 {\r
101     Rm_Inst      *rmInst = (Rm_Inst *)rmHandle;\r
102     Rm_Transport *transport = (Rm_Transport *) rmInst->transports;\r
103     Rm_Transport *prevTransport = NULL;\r
104 \r
105     while (transport) {\r
106         if (transport == (Rm_Transport *)transportHandle) {\r
107             break;             \r
108         }\r
109         prevTransport = transport;\r
110         transport = transport->nextTransport;\r
111     }\r
112 \r
113     if (transport) {\r
114         if (prevTransport == NULL) {\r
115              rmInst->transports = (void *) transport->nextTransport;\r
116         }\r
117         else {\r
118              prevTransport->nextTransport = transport->nextTransport;\r
119         }\r
120         Rm_osalFree((void *) transport, sizeof(Rm_Transport));\r
121     }\r
122     else {\r
123         return (RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED);\r
124     }\r
125     return (RM_TRANSPORT_SUCCESSFUL);\r
126 }\r
127 \r
128 Rm_Transport *rmTransportFindRemoteName(Rm_Transport *transports, char *remoteName)\r
129 {\r
130     while (transports) {\r
131         if (strcmp(transports->remoteInstName, remoteName) == 0) {\r
132             break;             \r
133         }\r
134         transports = transports->nextTransport;\r
135     }\r
136     return (transports);\r
137 }\r
138 \r
139 Rm_Transport *rmTransportFindRemoteInstType(Rm_Transport *transports, Rm_InstType remoteInstType)\r
140 {\r
141     while (transports) {\r
142         if (transports->remoteInstType == remoteInstType) {\r
143             break;             \r
144         }\r
145         transports = transports->nextTransport;\r
146     }\r
147     return (transports);\r
148 }\r
149 \r
150 Rm_Packet *rmTransportCreateResourceReqPkt(Rm_Inst *rmInst, Rm_Transport *dstTransport,\r
151                                             Rm_Transaction *transaction)\r
152 {\r
153     Rm_Packet             *rmPkt = NULL;\r
154     Rm_ResourceRequestPkt *resourceReqPkt = NULL;\r
155 \r
156     if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransport, sizeof(Rm_Packet))) ==\r
157         NULL) {\r
158         transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
159         return (NULL);\r
160     }\r
161 \r
162     if (rmPkt->pktLenBytes < (sizeof(Rm_ResourceRequestPkt) + sizeof(uint32_t) + sizeof(Rm_pktType))) {   \r
163         transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
164         return (NULL);\r
165     }\r
166    \r
167     rmPkt->pktType = Rm_pktType_RESOURCE_REQUEST;\r
168     resourceReqPkt = (Rm_ResourceRequestPkt *) rmPkt->data;\r
169     resourceReqPkt->requestId = transaction->localId;\r
170     if (transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) {\r
171         resourceReqPkt->resourceReqType = Rm_resReqPktType_ALLOCATE_INIT;\r
172     }\r
173     else if (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) {\r
174         resourceReqPkt->resourceReqType = Rm_resReqPktType_ALLOCATE_USE;\r
175     }    \r
176     else if (transaction->type == Rm_service_RESOURCE_FREE) {\r
177         resourceReqPkt->resourceReqType = Rm_resReqPktType_FREE;\r
178     }\r
179     else if (transaction->type == Rm_service_RESOURCE_GET_BY_NAME) {\r
180         resourceReqPkt->resourceReqType = Rm_resReqPktType_GET_NAMED;\r
181     }\r
182     strncpy(resourceReqPkt->pktSrcInstName, rmInst->instName, RM_INSTANCE_NAME_MAX_CHARS);\r
183     strncpy(resourceReqPkt->serviceSrcInstName, transaction->serviceSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
184     memcpy ((void *)&(resourceReqPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
185             sizeof(Rm_ResourceInfo));\r
186     return (rmPkt);\r
187 }\r
188 \r
189 Rm_Packet *rmTransportCreateResourceResponsePkt(Rm_Inst *rmInst, Rm_Transport *dstTransport,\r
190                                                  Rm_Transaction *transaction)\r
191 {\r
192     Rm_Packet              *rmPkt = NULL;\r
193     Rm_ResourceResponsePkt *resourceRespPkt = NULL;\r
194 \r
195     if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransport, sizeof(Rm_Packet))) ==\r
196         NULL) {\r
197         transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
198         return (NULL);\r
199     }\r
200 \r
201     if (rmPkt->pktLenBytes < (sizeof(Rm_ResourceResponsePkt) + sizeof(uint32_t) + sizeof(Rm_pktType))) {   \r
202         transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
203         return (NULL);\r
204     } \r
205     rmPkt->pktType = Rm_pktType_RESOURCE_RESPONSE;\r
206                           \r
207     resourceRespPkt = (Rm_ResourceResponsePkt *)rmPkt->data;\r
208     resourceRespPkt->responseId = transaction->remoteOriginatingId;\r
209     resourceRespPkt->requestState = transaction->state;\r
210     memcpy ((void *)&(resourceRespPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
211             sizeof(Rm_ResourceInfo));\r
212 \r
213     return (rmPkt);\r
214 }\r
215 \r
216 Rm_Packet *rmTransportCreateNsRequestPkt(Rm_Inst *rmInst, Rm_Transport *dstTransport,\r
217                                           Rm_Transaction *transaction)\r
218 {\r
219     Rm_Packet       *rmPkt = NULL;\r
220     Rm_NsRequestPkt *nsReqPkt = NULL;\r
221 \r
222     if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransport, sizeof(Rm_Packet))) ==\r
223         NULL) {\r
224         transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
225         return (NULL);\r
226     }\r
227 \r
228     if (rmPkt->pktLenBytes < (sizeof(Rm_NsRequestPkt) + sizeof(uint32_t) + sizeof(Rm_pktType))) {   \r
229         transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
230         return (NULL);\r
231     }\r
232     rmPkt->pktType = Rm_pktType_NAMESERVER_REQUEST;\r
233                           \r
234     nsReqPkt = (Rm_NsRequestPkt *)rmPkt->data;\r
235     nsReqPkt->requestId = transaction->localId;\r
236     if (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME) {\r
237         nsReqPkt->nsRequestType = Rm_nsReqPktType_MAP_RESOURCE;\r
238     }\r
239     else if (transaction->type == Rm_service_RESOURCE_UNMAP_NAME) {\r
240         nsReqPkt->nsRequestType = Rm_nsReqPktType_UNMAP_RESOURCE;\r
241     }\r
242     strncpy(nsReqPkt->pktSrcInstName, rmInst->instName, RM_INSTANCE_NAME_MAX_CHARS);\r
243     strncpy(nsReqPkt->serviceSrcInstName, transaction->serviceSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
244     memcpy ((void *)&(nsReqPkt->resourceInfo), (void *)&(transaction->resourceInfo),\r
245             sizeof(Rm_ResourceInfo));\r
246 \r
247     return (rmPkt);\r
248 }\r
249 \r
250 Rm_Packet *rmTransportCreateNsResponsePkt(Rm_Inst *rmInst, Rm_Transport *dstTransport,\r
251                                            Rm_Transaction *transaction)\r
252 {\r
253     Rm_Packet        *rmPkt = NULL;\r
254     Rm_NsResponsePkt *nsRespPkt = NULL;\r
255 \r
256     if ((rmPkt = rmInst->transport.rmAllocPkt((Rm_TransportHandle)dstTransport, sizeof(Rm_Packet))) ==\r
257         NULL) {\r
258         transaction->state = RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR;\r
259         return (NULL);\r
260     }\r
261 \r
262     if (rmPkt->pktLenBytes < (sizeof(Rm_NsResponsePkt) + sizeof(uint32_t) + sizeof(Rm_pktType))) {   \r
263         transaction->state = RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL;\r
264         return (NULL);\r
265     }  \r
266     rmPkt->pktType = Rm_pktType_NAMESERVER_RESPONSE;\r
267                           \r
268     nsRespPkt = (Rm_NsResponsePkt *)rmPkt->data;\r
269     nsRespPkt->responseId = transaction->remoteOriginatingId;\r
270     nsRespPkt->requestState = transaction->state;\r
271 \r
272     return (rmPkt);\r
273 }\r
274 \r
275 /**********************************************************************\r
276  ********************* Application visible APIs ***********************\r
277  **********************************************************************/\r
278 \r
279 Rm_TransportHandle Rm_transportRegister (Rm_TransportCfg *transportCfg, int32_t *result)\r
280 {\r
281     Rm_Inst          *rmInst = (Rm_Inst *) transportCfg->rmHandle;\r
282     Rm_Transport *transport = NULL;\r
283 \r
284     /* RM Servers cannot connect to other Servers.  RM Client Delegates cannot\r
285      * connect to other Client Delegates. */\r
286     if (((rmInst->instType == Rm_instType_SERVER) &&\r
287          (transportCfg->remoteInstType == Rm_instType_SERVER)) ||\r
288         ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
289          (transportCfg->remoteInstType == Rm_instType_CLIENT_DELEGATE))) {\r
290         *result = -500;\r
291         return(NULL);\r
292     }\r
293 \r
294     /* Verify Clients are not registering with more than one Client Delegate or Server. And\r
295      * that Client Delegate is not registering with more than one Server. */\r
296     if (rmInst->registeredWithDelegateOrServer &&\r
297         (((rmInst->instType == Rm_instType_CLIENT) &&\r
298           (transportCfg->remoteInstType == Rm_instType_CLIENT_DELEGATE)) || \r
299          ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
300           (transportCfg->remoteInstType == Rm_instType_SERVER)))) {\r
301         *result = -501;\r
302         return(NULL);\r
303     }         \r
304 \r
305     if (transportCfg->transportCalloutsValid &&\r
306         ((transportCfg->transportCallouts.rmAllocPkt == NULL) ||\r
307          (transportCfg->transportCallouts.rmFreePkt == NULL) ||\r
308          (transportCfg->transportCallouts.rmSend == NULL) ||\r
309          (transportCfg->transportCallouts.rmReceive == NULL) ||\r
310          (transportCfg->transportCallouts.rmNumPktsReceived == NULL))) {\r
311         *result = -502;\r
312         return(NULL);\r
313     }\r
314     else {\r
315         rmInst->transport.rmAllocPkt = transportCfg->transportCallouts.rmAllocPkt;\r
316         rmInst->transport.rmFreePkt = transportCfg->transportCallouts.rmFreePkt;\r
317         rmInst->transport.rmSend = transportCfg->transportCallouts.rmSend;\r
318         rmInst->transport.rmReceive = transportCfg->transportCallouts.rmReceive;\r
319         rmInst->transport.rmNumPktsReceived = transportCfg->transportCallouts.rmNumPktsReceived;\r
320     }\r
321     transport = transportAdd(transportCfg);\r
322 \r
323     if ((transport->remoteInstType == Rm_instType_CLIENT_DELEGATE) ||\r
324         (transport->remoteInstType == Rm_instType_SERVER)) {\r
325         rmInst->registeredWithDelegateOrServer = true;\r
326     }\r
327 \r
328     *result = 0; /* TEMP */\r
329     return ((Rm_TransportHandle) transport);\r
330 }\r
331 \r
332 Rm_TransportResult Rm_transportUnregister (Rm_Handle rmHandle, Rm_TransportHandle transportHandle)\r
333 {\r
334     Rm_Inst            *rmInst = (Rm_Inst *) rmHandle;\r
335     Rm_Transport       *transport = transportFindTransportHandle((Rm_Transport *)rmInst->transports, \r
336                                                                  transportHandle);\r
337     Rm_TransportResult  retVal = RM_TRANSPORT_SUCCESSFUL;  \r
338 \r
339     if (transport == NULL) {\r
340         retVal = RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED;\r
341     }\r
342     else {\r
343         if ((transport->remoteInstType == Rm_instType_CLIENT_DELEGATE) ||\r
344             (transport->remoteInstType == Rm_instType_SERVER)) {\r
345             rmInst->registeredWithDelegateOrServer = false;\r
346         }\r
347         retVal = transportDelete(rmHandle, transportHandle);\r
348     }\r
349 \r
350     return (retVal);\r
351 }\r
352 \r
353 /* Used by the application to pass RM packets received from a transport to RM.\r
354  * CODE THE FUNCTION SUCH THAT IT CAN BE CALLED DIRECTLY BY APP OR BE PLUGGED\r
355  * AS PART OF AN ISR HANDLER FOR THE TRANSACTION RECEIVE */\r
356 int32_t Rm_receivePktIsr(Rm_TransportHandle transportHandle, Rm_Packet *pkt)\r
357 {\r\r\r
358     Rm_Inst        *rmInst = (Rm_Inst *)((Rm_Transport *)transportHandle)->rmHandle;\r
359     Rm_Transaction *transaction;\r
360 \r
361     if (transportFindTransportHandle((Rm_Transport *)rmInst->transports, transportHandle) == NULL) {\r
362         return (RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED);\r
363     }\r
364 \r
365     switch (pkt->pktType) {\r
366         case Rm_pktType_RESOURCE_REQUEST:\r
367         {\r
368             Rm_ResourceRequestPkt *resourceReqPkt = (Rm_ResourceRequestPkt *)pkt->data;\r
369 \r
370             transaction = rmTransactionQueueAdd(rmInst);\r
371             transaction->remoteOriginatingId = resourceReqPkt->requestId;\r
372             if (resourceReqPkt->resourceReqType == Rm_resReqPktType_ALLOCATE_INIT) {\r
373                 transaction->type = Rm_service_RESOURCE_ALLOCATE_INIT;\r
374             }\r
375             else if (resourceReqPkt->resourceReqType == Rm_resReqPktType_ALLOCATE_USE) {\r
376                 transaction->type = Rm_service_RESOURCE_ALLOCATE_USE;\r
377             }            \r
378             else if (resourceReqPkt->resourceReqType == Rm_resReqPktType_FREE) {\r
379                 transaction->type = Rm_service_RESOURCE_FREE;\r
380             }\r
381             else if (resourceReqPkt->resourceReqType == Rm_resReqPktType_GET_NAMED) {\r
382                 transaction->type = Rm_service_RESOURCE_GET_BY_NAME;\r
383             }            \r
384             strncpy(transaction->pktSrcInstName, resourceReqPkt->pktSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
385             strncpy(transaction->serviceSrcInstName, resourceReqPkt->serviceSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
386             transaction->state = RM_SERVICE_PROCESSING;\r
387             memcpy ((void *)&(transaction->resourceInfo), (void *)&(resourceReqPkt->resourceInfo),\r
388                     sizeof(Rm_ResourceInfo));\r
389             rmTransactionProcessor(rmInst, transaction);\r
390             break;\r
391         }\r
392         case Rm_pktType_RESOURCE_RESPONSE:\r
393         {\r
394             Rm_ResourceResponsePkt *resourceRespPkt = (Rm_ResourceResponsePkt *)pkt->data;\r
395 \r
396             if (transaction = rmTransactionQueueFind(rmInst,resourceRespPkt->responseId)) {\r
397                 transaction->state = resourceRespPkt->requestState;\r
398 \r
399                 if ((transaction->state == RM_SERVICE_APPROVED_AND_COMPLETED) &&\r
400                     ((transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) ||\r
401                      (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) ||\r
402                      (transaction->type == Rm_service_RESOURCE_GET_BY_NAME))) {\r
403                     memcpy ((void *)&(transaction->resourceInfo), (void *)&(resourceRespPkt->resourceInfo),\r
404                             sizeof(Rm_ResourceInfo));\r
405                 }\r
406                 rmTransactionProcessor(rmInst, transaction);\r
407             }\r
408             else {\r
409                 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
410                 return (RM_TRANSPORT_ERROR_MATCHING_RESOURCE_REQUEST_NOT_FOUND);\r
411             }\r
412             break;\r
413         }\r
414         case Rm_pktType_NAMESERVER_REQUEST:\r
415         {\r
416             Rm_NsRequestPkt *nsRequestPkt = (Rm_NsRequestPkt *)pkt->data;\r
417 \r
418             transaction = rmTransactionQueueAdd(rmInst);\r
419             transaction->remoteOriginatingId = nsRequestPkt->requestId;\r
420 \r
421             if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_MAP_RESOURCE) {\r
422                 transaction->type = Rm_service_RESOURCE_MAP_TO_NAME;\r
423             }\r
424             else if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_UNMAP_RESOURCE) {\r
425                 transaction->type = Rm_service_RESOURCE_UNMAP_NAME;\r
426             }\r
427 \r
428             strncpy(transaction->pktSrcInstName, nsRequestPkt->pktSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
429             strncpy(transaction->serviceSrcInstName, nsRequestPkt->serviceSrcInstName, RM_INSTANCE_NAME_MAX_CHARS);\r
430             transaction->state = RM_SERVICE_PROCESSING;\r
431             memcpy ((void *)&(transaction->resourceInfo), (void *)&(nsRequestPkt->resourceInfo),\r
432                     sizeof(Rm_ResourceInfo));\r
433             rmTransactionProcessor(rmInst, transaction);            \r
434             break;\r
435         }\r
436         case Rm_pktType_NAMESERVER_RESPONSE:\r
437         {\r
438             Rm_NsResponsePkt *nsResponsePkt = (Rm_NsResponsePkt *)pkt->data;\r
439 \r
440             if (transaction = rmTransactionQueueFind(rmInst, nsResponsePkt->responseId)) {\r
441                 transaction->state = nsResponsePkt->requestState;            \r
442                 rmTransactionProcessor(rmInst, transaction);\r
443             }\r
444             else {\r
445                 rmInst->transport.rmFreePkt(transportHandle, pkt);\r
446                 return (RM_TRANSPORT_ERROR_MATCHING_NAME_SERVER_REQUEST_NOT_FOUND);\r
447             }\r
448             break;\r
449         }\r
450         case Rm_pktType_POLICY_REQUEST:\r
451         {\r
452             Rm_PolicyRequestPkt *policyRequestPkt = (Rm_PolicyRequestPkt *)pkt->data;\r
453 \r
454             /* TODO: FILL IN POLICY API INFORMATION */\r
455             break;  \r
456         }\r
457         case Rm_pktType_POLICY_CHANGE:\r
458         {\r
459             Rm_PolicyChangePkt *policyChangePkt = (Rm_PolicyChangePkt *)pkt->data;\r
460 \r
461             /* TODO: FILL IN POLICY API INFORMATION */\r
462             break;\r
463         }\r
464         case Rm_pktType_RESOURCE_POOL_MODIFICATION_REQUEST:\r
465         {\r
466             Rm_ResourcePoolModRequestPkt *resPoolModReqPkt = (Rm_ResourcePoolModRequestPkt *)pkt->data;\r
467 \r
468             /* TODO: FILL IN RESOURCE POOL MODIFICATION API */\r
469             /* Rm_resourcePoolModRequestHandler(...); Server only - needs to allocate resources to\r
470              * the Client Delegate based on the policy and return those resources to the Client Delegate */\r
471             break;\r
472         }\r
473         case Rm_pktType_RESOURCE_POOL_MODIFICATION_RESPONSE:\r
474         {\r
475             Rm_ResourcePoolModResponsePkt *resPoolModRespPkt = (Rm_ResourcePoolModResponsePkt *)pkt->data;\r
476 \r
477             /* TODO: FILL IN RESOURCE POOL MODIFICAITON API */\r
478             /* Rm_resourcePoolModResponseHandler(...);  Handler needs to populate allocator with\r
479              * new resources provided in the response and then handle any request transactions waiting on\r
480              * the resource pool modification */\r
481             break;\r
482         }\r
483         default:\r
484             rmInst->transport.rmFreePkt(transportHandle, pkt);\r
485             return (RM_TRANSPORT_ERROR_INVALID_PACKET_TYPE);\r
486       }\r
487 \r
488     rmInst->transport.rmFreePkt(transportHandle, pkt);\r
489     return (RM_TRANSPORT_SUCCESSFUL);\r
490 }\r
491 \r
492 /* Application can call this API so that RM handles reception of packets based on\r
493  * the RM handle and transport handle provided */\r
494 int32_t Rm_receivePktPolling(Rm_TransportHandle transportHandle)\r
495 {\r
496     Rm_Inst   *rmInst = (Rm_Inst *)((Rm_Transport *)transportHandle)->rmHandle;\r
497     Rm_Packet *pkt = NULL;\r
498     int32_t    retVal = RM_TRANSPORT_OK_BASE;\r
499 \r
500     if (transportFindTransportHandle((Rm_Transport *)rmInst->transports, transportHandle) != NULL) {\r
501         while (rmInst->transport.rmNumPktsReceived(transportHandle) > 0) {\r
502             pkt = rmInst->transport.rmReceive(transportHandle);\r
503 \r
504             if (pkt == NULL) {\r
505                 retVal = RM_TRANSPORT_ERROR_PACKET_RECEPTION_ERROR;\r
506                 break;\r
507             }\r
508 \r
509             /* Pass packet to RM.  Packet will be freed within PktIsr API */\r
510             if (retVal = Rm_receivePktIsr(transportHandle, pkt) <= RM_SERVICE_ERROR_BASE) {\r
511                 break;\r
512             }\r
513         }\r
514     }\r
515     else {\r
516         retVal = RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED;\r
517     }\r
518 \r
519     return (retVal); \r
520 }\r
521 \r
522 /**\r
523 @}\r
524 */\r