]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - packages/ti/ipc/mm/MmRpc.c
MmRpc: Add Input Paramter Checking to APIs
[ipc/ipcdev.git] / packages / ti / ipc / mm / MmRpc.c
index e6f0c119671eb9cf3b32b086e53bdb1b7a49071a..410851d63536bf2424c82556c782c41e84148111 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define _linux_ linux
 #undef linux
 #endif
+
+#define linux_version_include(kd) <kd/include/generated/uapi/linux/version.h>
+#include linux_version_include(KERNEL_INSTALL_DIR)
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
 #define linux_include(kd,m) <kd/include/linux/m.h>
+#else
+#define linux_include(kd,m) <kd/include/uapi/linux/m.h>
+#endif
+
 #include linux_include(KERNEL_INSTALL_DIR,rpmsg_rpc)
+
 #ifdef _linux_
 #define linux _linux
 #undef _linux_
 #endif
 
-#elif defined(SYSLINK_BUILDOS_QNX)
+#elif defined(IPC_BUILDOS_QNX)
 
 #include <ti/ipc/rpmsg_rpc.h>
 
 #elif defined(IPC_BUILDOS_ANDROID)
-#include <linux/rpmsg_rpc.h>
+#include <uapi/linux/rpmsg_rpc.h>
 
 #else
 #error Unsupported Operating System
 
 #include "MmRpc.h"
 
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+static int MmRpc_bufHandle(MmRpc_Handle handle, int cmd, int num,
+        MmRpc_BufDesc *desc);
+#endif
+
 
 /*
  *  ======== MmRpc_Object ========
@@ -101,6 +116,11 @@ int MmRpc_create(const char *service, const MmRpc_Params *params,
     MmRpc_Object *  obj;
     char            cbuf[RPPC_MAX_INST_NAMELEN+16];
 
+    if (service == NULL || handlePtr == NULL) {
+        status = MmRpc_E_INVALIDPARAM;
+        goto leave;
+    }
+
     /* allocate the instance object */
     obj = (MmRpc_Object *)calloc(1, sizeof(MmRpc_Object));
 
@@ -139,7 +159,9 @@ leave:
         if (obj != NULL) {
             free(obj);
         }
-        *handlePtr = NULL;
+        if (handlePtr) {
+            *handlePtr = NULL;
+        }
     }
     else {
         *handlePtr = (MmRpc_Handle)obj;
@@ -156,6 +178,10 @@ int MmRpc_delete(MmRpc_Handle *handlePtr)
     int status = MmRpc_S_SUCCESS;
     MmRpc_Object *obj;
 
+    if (handlePtr == NULL) {
+        return MmRpc_E_INVALIDPARAM;
+    }
+
     obj = (MmRpc_Object *)(*handlePtr);
 
     /* close the device */
@@ -184,6 +210,11 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
     int len;
     int i;
 
+    if (handle == NULL || ctx == NULL || ret == NULL) {
+        status = MmRpc_E_INVALIDPARAM;
+        goto leave;
+    }
+
     /* combine params and translation array into one contiguous message */
     len = sizeof(struct rppc_function) +
                 (ctx->num_xlts * sizeof(struct rppc_param_translation));
@@ -209,7 +240,7 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
                 rpfxn->params[i].size = param->param.scalar.size;
                 rpfxn->params[i].data = param->param.scalar.data;
                 rpfxn->params[i].base = 0;
-                rpfxn->params[i].reserved = 0;
+                rpfxn->params[i].fd = 0;
                 break;
 
             case MmRpc_ParamType_Ptr:
@@ -217,7 +248,7 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
                 rpfxn->params[i].size = param->param.ptr.size;
                 rpfxn->params[i].data = param->param.ptr.addr;
                 rpfxn->params[i].base = param->param.ptr.addr;
-                rpfxn->params[i].reserved = param->param.ptr.handle;
+                rpfxn->params[i].fd = param->param.ptr.handle;
                 break;
 
             case MmRpc_ParamType_OffPtr:
@@ -226,7 +257,7 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
                 rpfxn->params[i].data = param->param.offPtr.base +
                         param->param.offPtr.offset;
                 rpfxn->params[i].base = param->param.offPtr.base;
-                rpfxn->params[i].reserved = param->param.offPtr.handle;
+                rpfxn->params[i].fd = param->param.offPtr.handle;
                 break;
 
             default:
@@ -242,10 +273,10 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
 
     for (i = 0; i < ctx->num_xlts; i++) {
         /* pack the pointer translation entry */
-        rpfxn->translations[i].index    = ctx->xltAry[i].index;
-        rpfxn->translations[i].offset   = ctx->xltAry[i].offset;
-        rpfxn->translations[i].base     = ctx->xltAry[i].base;
-        rpfxn->translations[i].reserved = ctx->xltAry[i].handle;
+        rpfxn->translations[i].index = ctx->xltAry[i].index;
+        rpfxn->translations[i].offset = ctx->xltAry[i].offset;
+        rpfxn->translations[i].base = ctx->xltAry[i].base;
+        rpfxn->translations[i].fd = (int32_t)ctx->xltAry[i].handle;
     }
 
     /* send message for remote execution */
@@ -284,3 +315,109 @@ leave:
 
     return(status);
 }
+
+/*
+ *  ======== MmRcp_release ========
+ */
+int MmRpc_release(MmRpc_Handle handle, MmRpc_BufType type, int num,
+        MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+
+    switch (type) {
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+        case MmRpc_BufType_Handle:
+            stat = MmRpc_bufHandle(handle, RPPC_IOC_BUFUNREGISTER, num, desc);
+            break;
+
+#elif defined(IPC_BUILDOS_QNX)
+        case MmRpc_BufType_Ptr:
+            break;
+#endif
+        default:
+            printf("MmRpc_release: Error: unsupported type value: %d\n", type);
+            stat = MmRpc_E_INVALIDPARAM;
+            break;
+    }
+
+    if (stat < 0) {
+        printf("MmRpc_release: Error: unable to release buffer\n");
+    }
+
+    return(stat);
+}
+
+/*
+ *  ======== MmRcp_use ========
+ */
+int MmRpc_use(MmRpc_Handle handle, MmRpc_BufType type, int num,
+        MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+
+    switch (type) {
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+        case MmRpc_BufType_Handle:
+            stat = MmRpc_bufHandle(handle, RPPC_IOC_BUFREGISTER, num, desc);
+            break;
+
+#elif defined(IPC_BUILDOS_QNX)
+        case MmRpc_BufType_Ptr:
+            break;
+#endif
+        default:
+            printf("MmRpc_use: Error: unsupported type value: %d\n", type);
+            stat = MmRpc_E_INVALIDPARAM;
+            break;
+    }
+
+    if (stat < 0) {
+        printf("MmRpc_use: Error: unable to declare buffer use\n");
+    }
+
+    return(stat);
+}
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+/*
+ *  ======== MmRpc_bufHandle ========
+ */
+int MmRpc_bufHandle(MmRpc_Handle handle, int cmd, int num, MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+    MmRpc_Object *obj = (MmRpc_Object *)handle;
+    int i;
+    struct rppc_buf_fds reg = { num, NULL };
+
+    if (handle == NULL || desc == NULL) {
+        stat = MmRpc_E_INVALIDPARAM;
+        goto leave;
+    }
+
+    reg.fds = (int32_t *)malloc(num * sizeof(int32_t));
+
+    if (reg.fds == NULL) {
+        stat = MmRpc_E_NOMEM;
+        goto leave;
+    }
+
+    for (i = 0; i < num; i++) {
+        reg.fds[i] = desc[i].handle;
+    }
+
+    stat = ioctl(obj->fd, cmd, &reg);
+
+    if (stat < 0) {
+        stat = MmRpc_E_SYS;
+    }
+
+leave:
+    if (reg.fds != NULL) {
+        free(reg.fds);
+    }
+
+    return(stat);
+}
+#endif