NETAPI integration with ipsecmgr
authorTinku Mannan <tmannan@ti.com>
Fri, 21 Jun 2013 18:33:05 +0000 (14:33 -0400)
committerTinku Mannan <tmannan@ti.com>
Wed, 10 Jul 2013 16:46:04 +0000 (12:46 -0400)
12 files changed:
ti/runtime/netapi/applications/ipsec_offload/config-app/build/Makefile [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/config-app/build/setup_shell_env.sh [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell.c [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_loc.h [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_main.c [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/build/Makefile [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c [new file with mode: 0755]
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.h [new file with mode: 0755]
ti/runtime/netapi/makefile_armv7
ti/runtime/netapi/netcp_cfg.h
ti/runtime/netapi/src/netapi_loc.h

diff --git a/ti/runtime/netapi/applications/ipsec_offload/config-app/build/Makefile b/ti/runtime/netapi/applications/ipsec_offload/config-app/build/Makefile
new file mode 100755 (executable)
index 0000000..9065562
--- /dev/null
@@ -0,0 +1,104 @@
+# Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+
+space =$(empty) $(empty)
+
+export ARMV7OBJDIR ?= ./obj
+export ARMV7BINDIR ?= ./bin
+export ARMV7LIBDIR ?= ./lib
+# INCLUDE Directories
+
+NETAPI_SRC_DIR ?= $(TRANS_SDK_INSTALL_PATH)/ti/runtime/netapi
+
+CSL_DEVICE ?= -DDEVICE_K2H
+
+
+ifdef CROSS_TOOL_INSTALL_PATH
+## Support backwards compatibility with KeyStone1 approach
+ CC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc
+ AC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)as
+ AR = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)ar
+ LD = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc
+endif
+
+#QUIET_CMD=@
+EXE_NAME_PRFX=ipsecmgr_cmd_shell
+
+###############################################################################
+# Set default options
+###############################################################################
+CFLAGS+= $(DEBUG_FLAG) -I../ -I. $(CSL_DEVICE) -D__ARMv7 -D_VIRTUAL_ADDR_SUPPORT -D__LINUX_USER_SPACE -D_LITTLE_ENDIAN=1 -DNWAL_ENABLE_SA -DMAKEFILE_BUILD -D _GNU_SOURCE
+
+OUTPUT_FILE_OPTION = -o
+
+EXE_NAME = $(EXE_NAME_PRFX).out
+
+ROOT_DIR = ..
+IPSECMGR_UTIL_IFACE_DIR?= ../../../utils/iface
+IPSECMGR_IFACE_DIR?= ../
+
+
+OBJ_DIR = obj
+NETAPI_LIB=netapi
+IPSECMGR_IPC_LIB=ipsecmgr_ipc
+IPSECMGR_SYSLOG_LIB=ipsecmgr_syslog
+IPSECMGR_SNOOP_LIB=ipsecmgr_snoop
+LD_OPTS += -pthread -lrt
+LD_OPTS += -L $(ARMV7LIBDIR) -L $(PDK_ARMV7LIBDIR) -L $(IPSECMGR_LIB_PATH) -l$(IPSECMGR_SNOOP_LIB) -l$(IPSECMGR_IPC_LIB) -l$(IPSECMGR_SYSLOG_LIB)
+
+###############################################################################
+# List of modules and their files
+###############################################################################
+CONFIG_APP_SRC_DIR ?=../src/
+CONFIG_APP_FILES = \
+        cmd_shell.c \
+        cmd_shell_main.c \
+        cmd_shell_loc.h
+
+VPATH = $(CONFIG_APP_SRC_DIR)
+FILES = $(CONFIG_APP_FILES)
+
+INCL_DIRS= $(IPSECMGR_IFACE_DIR) $(IPSECMGR_UTIL_IFACE_DIR)
+
+HEADERS = $(filter %.h, $(FILES))
+INCL = -I. $(patsubst %,-I%,$(INCL_DIRS))
+
+BIN_DIR = $(ARMV7BINDIR)/netapi/applications/ipsec_offload/config-app
+OBJ_DIR = $(ARMV7OBJDIR)/netapi/applications/ipsec_offload/config-app
+CONFIG_APP_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(filter %.c, $(FILES)))
+
+
+all: app install
+
+app: $(BIN_DIR)/.created $(BIN_DIR)/$(EXE_NAME)
+###############################################################################
+# Normal make process                                                         
+###############################################################################
+
+$(OBJ_DIR)/%.o: %.c $(OBJ_DIR)/.created
+       @echo compiling $<
+       $(CC) -c  $(CFLAGS) $(INCL)  $<  -o $@
+
+$(OBJ_DIR)/.created:
+       $(QUIET_CMD)@echo "making $@" 
+       @mkdir -p $(OBJ_DIR)
+
+$(BIN_DIR)/.created:
+       @mkdir -p $(BIN_DIR)
+
+$(BIN_DIR)/$(EXE_NAME): $(CONFIG_APP_OBJS) $(BIN_DIR)/.created
+       $(QUIET_CMD)@echo "linking $@" 
+       $(CC) $(CONFIG_APP_OBJS) $(LD_OPTS) -o $(BIN_DIR)/$(EXE_NAME)
+
+install:
+       install -d $(INSTALL_BIN_BASE_DIR)
+       install -c -m 755 $(BIN_DIR)/* $(INSTALL_BIN_BASE_DIR)
+       install -d $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi/applications/ipsec_offload/config-app/src
+       install -c -m 644 ../src/*.h $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi/applications/ipsec_offload/config-app/src
+
+clean:
+       rm -rf $(OBJ_DIR)
+       rm -rf $(BIN_DIR)
+
+
+
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/config-app/build/setup_shell_env.sh b/ti/runtime/netapi/applications/ipsec_offload/config-app/build/setup_shell_env.sh
new file mode 100755 (executable)
index 0000000..0aba750
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Source this script before starting the ipsecmgr command shell
+
+# Variable to specify the local unix socket name for IPC with IPSec daemon
+export IPSECMGR_APP_SOCK_NAME="/etc/app_sock"
+# Variable to specify the unix socket name of the IPSec daemon
+export IPSECMGR_DAEMON_SOCK_NAME="/etc/ipsd_sock"
+# Variable to specify the log file to be used by the ipsecmgr library
+export IPSECMGR_LOG_FILE="/var/run/ipsecmgr_app.log"
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell.c b/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell.c
new file mode 100755 (executable)
index 0000000..918c549
--- /dev/null
@@ -0,0 +1,598 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+/* Standard include files */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <string.h>
+
+/* module specific include files */
+#include <ipsecmgr_ipc.h>
+
+#include "cmd_shell_loc.h"
+
+/* For debugging */
+#define  DEBUG
+#define DEBUG1
+
+#define OPTION_ID_IF_NAME       1
+#define OPTION_ID_SP_ID         2
+#define OPTION_ID_CMD_NAME      3
+#define OPTION_ID_ESN           4
+#define OPTION_ID_GTPU_TEID     5
+#define OPTION_ID_NUM_TEIDS     6
+#define OPTION_ID_SHARED_SA     7
+#define OPTION_ID_MAX           8
+
+enum cmd_id {
+    CMD_ID_OFFLOAD_SP   = 1,
+    CMD_ID_STOP_OFFLOAD,
+    CMD_ID_HELP,
+    CMD_ID_EXIT,
+    CMD_ID_LAST
+};
+
+/* Maximum strlen() of string variables */
+#define MAX_STR_VAR_SIZE   32
+
+/* Maximum number of commands */
+#define MAX_CMDS    CMD_ID_LAST
+
+typedef union {
+    unsigned long   intval;
+    char            strval[MAX_STR_VAR_SIZE];
+} opt_val_gen_t;
+    
+typedef struct {
+    opt_val_gen_t   value;
+    uint8_t         is_valid;
+} opt_attr_gen_t;
+static opt_attr_gen_t opt_input_gen[OPTION_ID_MAX];
+
+/* Module context */
+static cmd_shell_ctx_t shell_ctx;
+
+static int parse_intval(char* int_str, opt_attr_gen_t *opt_attr) {
+    int i;
+    for (i=0; int_str[i]!= '\0'; i++) int_str[i] = (char) tolower(int_str[i]);
+    if (strncmp("0x", int_str, 2)) {
+        opt_attr->value.intval = strtoul(int_str, (char **)NULL, 10);
+    } else {
+        opt_attr->value.intval = strtoul(int_str, (char **)NULL, 16);
+    }
+    opt_attr->is_valid = 1;
+    return 0;
+}
+
+static int parse_strval(char* str, opt_attr_gen_t *opt_attr) {
+
+    strncpy(opt_attr->value.strval, str, MAX_STR_VAR_SIZE-1);
+    opt_attr->is_valid = 1;
+    return 0;
+}
+
+static char short_opts[200];
+
+#define CMD_NAME_OFFLOAD_SP   "offload_sp"
+#define CMD_DESC_OFFLOAD_SP   "Offload an IPSec Policy to Fast Path"
+#define CMD_MIN_ARGS_OFFLOAD_SP    3
+#define CMD_SHORT_OPTS_OFFLOAD_SP sprintf(short_opts, "%d:%d:%d%d:%d:",\
+                           OPTION_ID_SP_ID, OPTION_ID_IF_NAME, OPTION_ID_ESN,\
+                           OPTION_ID_GTPU_TEID, OPTION_ID_NUM_TEIDS,\
+                           OPTION_ID_SHARED_SA);
+
+static struct option offload_sp_options[] =
+{
+    {"sp_id",  required_argument, 0, OPTION_ID_SP_ID},
+    {"if_name", required_argument, 0, OPTION_ID_IF_NAME},
+    {"esn", no_argument, 0, OPTION_ID_ESN},
+    {"gtpu_teid", required_argument, 0, OPTION_ID_GTPU_TEID},
+    {"num_teids", required_argument, 0, OPTION_ID_NUM_TEIDS},
+    {"shared", no_argument, 0, OPTION_ID_SHARED_SA},
+    {0, 0, 0, 0}
+};
+
+#define CMD_NAME_STOP_OFFLOAD   "stop_offload"
+#define CMD_DESC_STOP_OFFLOAD   "Stop Offload of an IPSec Policy"
+#define CMD_MIN_ARGS_STOP_OFFLOAD   3
+#define CMD_SHORT_OPTS_STOP_OFFLOAD sprintf(short_opts, "%d:", OPTION_ID_SP_ID);
+static struct option stop_offload_options[] =
+{
+    {"sp_id",  required_argument, 0, OPTION_ID_SP_ID},
+    {0, 0, 0, 0}
+};
+
+#define CMD_NAME_EXIT   "exit"
+#define CMD_DESC_EXIT   "Exit the netcpcfg command shell"
+#define CMD_MIN_ARGS_EXIT    1
+#define CMD_SHORT_OPTS_EXIT sprintf(short_opts, ""); 
+static struct option exit_options[] =
+{
+    {0, 0, 0, 0}
+};
+
+#define CMD_NAME_HELP       "help"
+#define CMD_DESC_HELP       "Help on available commands"
+#define CMD_MIN_ARGS_HELP   1
+#define CMD_SHORT_OPTS_HELP sprintf(short_opts, "%d:", OPTION_ID_CMD_NAME); 
+static struct option help_options[] =
+{
+    {"cmd",  required_argument, 0, OPTION_ID_CMD_NAME},
+    {0, 0, 0, 0}
+};
+
+struct cmd_tbl_s {
+    char            *cmd_name;
+    struct option   *opt_tbl;
+    char            *desc;
+};
+
+struct cmd_tbl_s cmd_table[MAX_CMDS] = 
+{
+    {CMD_NAME_OFFLOAD_SP, offload_sp_options, CMD_DESC_OFFLOAD_SP},
+    {CMD_NAME_STOP_OFFLOAD, stop_offload_options, CMD_DESC_STOP_OFFLOAD},
+    {CMD_NAME_EXIT, exit_options, CMD_DESC_EXIT},
+    {CMD_NAME_HELP, help_options, CMD_DESC_HELP},
+    {0, 0}
+};
+
+static void print_help (char *cmd_name)
+{
+    int i,j;
+
+    if (!cmd_name) {
+        printf ("For help on command options type \"%s --cmd <cmd name>\"\n",
+                CMD_NAME_HELP);
+        printf ("Available commands:\n");
+
+        for (i=0; ((i < MAX_CMDS) && cmd_table[i].cmd_name); i++) {
+            printf ("    %s\t%s\n", cmd_table[i].cmd_name, cmd_table[i].desc);
+        }
+        return;
+    }
+
+    for (i=0; ((i < MAX_CMDS) && (cmd_table[i].cmd_name)); i++) {
+        struct option *opt = cmd_table[i].opt_tbl;
+        if (strcmp(cmd_name, cmd_table[i].cmd_name)) {
+            continue;
+        }
+
+        printf ("options for \"%s\"\n", cmd_name);
+        for (j=0; opt->name; j++, opt++) {
+            printf ("    --%s\n", opt->name);
+        }
+        return;
+    }
+
+    printf ("No help available for %s\n", cmd_name);
+    return;
+}
+
+static int setargs (char *args, char **argv)
+{
+    int count = 0;
+
+    while (isspace(*args)) ++args;
+    while (*args) {
+        if (argv) argv[count] = args;
+        while (*args && !isspace(*args)) ++args;
+        if (argv && *args) *args++ = '\0';
+        while (isspace(*args)) ++args;
+        count++;
+    }
+    return count;
+}
+
+static char **parsedargs(char *args, int *argc)
+{
+    char **argv = NULL;
+    int    argn = 0;
+
+    if (args && *args
+        && (args = strdup(args))
+        && (argn = setargs(args,NULL))
+        && (argv = malloc((argn+1) * sizeof(char *)))) {
+          *argv++ = args;
+          argn = setargs(args,argv);
+    }
+
+    if (args && !argv) free(args);
+
+    *argc = argn;
+    return argv;
+}
+
+static void freeparsedargs(char **argv)
+{
+    if (argv) {
+        free(argv[-1]);
+        free(argv-1);
+    } 
+}
+
+#define COMMAND_LINE_SIZE 400
+     
+void* cmd_shell (void* args)
+{
+    char *line = NULL;
+    size_t len = 0;
+    ssize_t read = 0;
+    char cmd[20];
+    int nargs, c, rargs;
+    struct option *long_options; 
+    char **av;
+    enum cmd_id  cmd_id;
+
+    memset(&shell_ctx, 0, sizeof(shell_ctx));
+    if (ipsecmgr_ipc_get_user_send_iface(&shell_ctx.ipc_send_if)) {
+        printf ("\ncmd_shell: Failed to get IPC send interface\n");
+        return;
+    }
+
+    while (1) {
+        memset(opt_input_gen, 0, sizeof(opt_input_gen));
+        cmd_id = 0;
+
+        printf ("\nIPSECMGR-CFG> ");
+
+        if (line) free(line);
+        line = malloc(COMMAND_LINE_SIZE);
+        if (line == NULL) {
+            printf("\nError allocating memory");
+            return;
+        }
+
+        read = getline(&line, &len, stdin);
+        if (read == -1) {
+            printf("\nERROR: reading line");
+            continue;
+        }
+        if (!read) continue;
+        memset(cmd, 0, sizeof(cmd));
+        sscanf(line, "%s", cmd);
+
+        if ( !strcmp(cmd, "exit"))
+            exit(0);
+
+        if (!strcmp(cmd, CMD_NAME_OFFLOAD_SP)) {
+            cmd_id = CMD_ID_OFFLOAD_SP;
+            long_options = offload_sp_options; 
+            CMD_SHORT_OPTS_OFFLOAD_SP;
+            rargs = CMD_MIN_ARGS_OFFLOAD_SP;
+        } else if (!strcmp(cmd, CMD_NAME_STOP_OFFLOAD)) {
+            cmd_id = CMD_ID_STOP_OFFLOAD;
+            long_options = stop_offload_options; 
+            CMD_SHORT_OPTS_STOP_OFFLOAD;
+            rargs = CMD_MIN_ARGS_STOP_OFFLOAD;
+        } else if (!strcmp(cmd, CMD_NAME_HELP)) {
+            cmd_id = CMD_ID_HELP;
+            long_options = help_options; 
+            CMD_SHORT_OPTS_HELP;
+            rargs = CMD_MIN_ARGS_HELP;
+        } else {
+            if (strlen(cmd))
+                printf ("Unknown command: %s\n", cmd);
+            continue;
+        }
+
+        if ((av = parsedargs(line, &nargs)) == NULL) {
+            printf ("error parsing arguments");
+            continue;
+        }
+
+        if (nargs < rargs) {
+            printf ("Insufficient paramaters for command \"%s\"\n", cmd);
+            print_help (cmd);
+            goto loop_over;
+        }
+
+#ifdef DEBUG1
+        {
+            int i;
+            for (i = 0; i < nargs; i++)
+            printf("[%s]\n",av[i]);
+        }
+#endif
+               
+        optind = 0;
+        while (1) {
+           /* getopt_long stores the option index here. */
+           int option_index = 0;
+            c = getopt_long (nargs, av, short_opts,
+                        long_options, &option_index);
+     
+            /* Detect the end of the options. */
+#ifdef DEBUG1
+                       printf("c=%d",c);
+#endif
+            if (c == -1)
+                break;
+
+            switch (c)
+            {
+
+                case OPTION_ID_SP_ID:
+#ifdef DEBUG
+                printf ("option sp_id with value `%s'\n", optarg);
+#endif
+                if (parse_intval(optarg, &opt_input_gen[c])) {
+                    printf ("Invalid argument for sp_id\n");
+                }
+                break;
+
+                case OPTION_ID_IF_NAME:
+#ifdef DEBUG
+                printf ("option if_name with value `%s'\n", optarg);
+#endif
+                if (parse_strval(optarg, &opt_input_gen[c])) {
+                    printf ("Invalid argument for if_name\n");
+                }
+                break;
+
+                case OPTION_ID_CMD_NAME:
+#ifdef DEBUG
+                printf ("option cmd with value `%s'\n", optarg);
+#endif
+                if (parse_strval(optarg, &opt_input_gen[c])) {
+                    printf ("Invalid argument for cmd\n");
+                }
+                break;
+
+                case OPTION_ID_ESN:
+#ifdef DEBUG
+                printf ("option esn enabled\n");
+#endif
+                opt_input_gen[c].is_valid = 1;
+                break;
+
+                case OPTION_ID_GTPU_TEID:
+#ifdef DEBUG
+                printf ("option gtpu_teid with value `%s'\n", optarg);
+#endif
+                if (parse_intval(optarg, &opt_input_gen[c])) {
+                    printf ("Invalid argument for gtpu_teid\n");
+                }
+                break;
+
+                case OPTION_ID_NUM_TEIDS:
+#ifdef DEBUG
+                printf ("option num_teids with value `%s'\n", optarg);
+#endif
+                if (parse_intval(optarg, &opt_input_gen[c])) {
+                    printf ("Invalid argument for num_teids\n");
+                }
+                break;
+
+                case OPTION_ID_SHARED_SA:
+#ifdef DEBUG
+                printf ("option shared SA enabled\n");
+#endif
+                opt_input_gen[c].is_valid = 1;
+                break;
+
+                default:
+                printf ("unknown option c=%d\n", c);
+                break;
+            }
+        }
+#ifdef DEBUG1
+    /* Print any remaining command line arguments (not options). */
+    if (optind < nargs)
+    {
+        printf ("non-option elements: ");
+        while (optind < nargs)
+            printf ("%s ", av[optind++]);
+        putchar ('\n');
+    }
+#endif
+
+    switch (cmd_id) {
+
+        case CMD_ID_HELP:
+        {
+            if (!opt_input_gen[OPTION_ID_CMD_NAME].is_valid) {
+                print_help(NULL);
+            } else {
+                print_help(opt_input_gen[OPTION_ID_CMD_NAME].value.strval);
+            }
+            break;
+        }
+
+        case CMD_ID_OFFLOAD_SP:
+        {
+            ipsecmgr_ipc_offload_sp_req_param_t req;
+            ipsecmgr_ifname_t if_name;
+            ipsecmgr_l5_selector_t l5_selector;
+
+            if (!opt_input_gen[OPTION_ID_SP_ID].is_valid) {
+                printf ("Mandatory paramater missing: sp_id\n");
+                goto loop_over;
+            }
+
+            memset(&req, 0, sizeof(req));
+            memset(&if_name, 0, sizeof(if_name));
+            memset(&l5_selector, 0, sizeof(l5_selector));
+
+            req.trans_id = ++shell_ctx.trans_id;
+
+            /* sp_id */
+            req.policy_id =
+                    (uint32_t)opt_input_gen[OPTION_ID_SP_ID].value.intval;
+
+            /* if_name */
+            if (opt_input_gen[OPTION_ID_IF_NAME].is_valid) {
+                strcpy(if_name.name,
+                       opt_input_gen[OPTION_ID_IF_NAME].value.strval);
+                req.if_name = &if_name;
+            }
+
+            /* esn */
+            if (opt_input_gen[OPTION_ID_ESN].is_valid) {
+                req.sa_flags |= IPSECMGR_SA_FLAGS_ESN;
+            }
+
+            /* gtpu_teid */
+            if (opt_input_gen[OPTION_ID_GTPU_TEID].is_valid) {
+                l5_selector.proto = IPSECMGR_L5_PROTO_GTPU;
+                l5_selector.value.gtpu.teid_start =
+                    (uint32_t)opt_input_gen[OPTION_ID_GTPU_TEID].value.intval;
+                req.l5_selector = &l5_selector;
+            }
+
+            /* num_teids */
+            if (opt_input_gen[OPTION_ID_NUM_TEIDS].is_valid) {
+                l5_selector.value.gtpu.teid_end =
+                    l5_selector.value.gtpu.teid_start - 1 +
+                    (uint32_t)opt_input_gen[OPTION_ID_NUM_TEIDS].value.intval;
+            } else { /* default is 1 TEID */
+                l5_selector.value.gtpu.teid_end =
+                    l5_selector.value.gtpu.teid_start;
+            }
+
+            /* shared tunnel */
+            if (opt_input_gen[OPTION_ID_SHARED_SA].is_valid) {
+                req.sa_flags |= IPSECMGR_SA_FLAGS_SHARED;
+            }
+
+            if (shell_ctx.ipc_send_if->offload_sp_req(&req)) {
+                printf("%s failed\n", CMD_NAME_OFFLOAD_SP);
+            } else {
+                printf("%s trans_id: 0x%x\n", CMD_NAME_OFFLOAD_SP,
+                       shell_ctx.trans_id);
+            }
+
+            break;
+        }
+
+        case CMD_ID_STOP_OFFLOAD:
+        {
+            ipsecmgr_ipc_stop_offload_req_param_t req;
+
+            if (!opt_input_gen[OPTION_ID_SP_ID].is_valid) {
+                printf ("Mandatory paramater missing: sp_id\n");
+                goto loop_over;
+            }
+
+            memset(&req, 0, sizeof(req));
+
+            req.trans_id = ++shell_ctx.trans_id;
+
+            /* sp_id */
+            req.policy_id =
+                    (uint32_t)opt_input_gen[OPTION_ID_SP_ID].value.intval;
+
+            if (shell_ctx.ipc_send_if->stop_offload_req(&req)) {
+                printf("%s failed\n", CMD_NAME_STOP_OFFLOAD);
+            } else {
+                printf("%s trans_id: 0x%x\n", CMD_NAME_STOP_OFFLOAD,
+                       shell_ctx.trans_id);
+            }
+
+            break;
+        }
+
+    } /* switch cmd_id */
+
+loop_over:
+        freeparsedargs(av);
+    }
+    return (void*)(0);
+}
+
+void cmd_shell_offload_sp_rsp
+(
+    ipsecmgr_ipc_offload_sp_rsp_param_t *rsp
+)
+{
+    char resp_str[10] = {0,};
+
+    printf ("\nRecvd OFFLOAD_SP response:\n");
+    printf ("  trans_id:\t0x%x\n", rsp->trans_id);
+
+    if (rsp->type & RSP_TYPE_ACK) {
+        strcpy(resp_str, "ACK");
+    } else if (rsp->type & RSP_TYPE_DONE) {
+        int slen = strlen(resp_str);
+        if (slen)
+            strcpy(&resp_str[slen], "|DONE");
+        else
+            strcpy(&resp_str[slen], "DONE");
+    } 
+
+    printf ("  resp_type:\t(%d) %s\n", rsp->type, resp_str);
+    printf ("  result:\t(%d) %s\n", rsp->result,
+            ((rsp->result == RESULT_SUCCESS) ? "SUCCESS":"FAIL"));
+
+    if (rsp->err_code) {
+        printf ("  FP lib retval:\t%d\n", rsp->err_code);
+    }
+
+    if (rsp->sa_handle) 
+        printf ("  sa_handle:\t0x%x\n", rsp->sa_handle);
+    if (rsp->sp_handle) 
+        printf ("  sp_handle:\t0x%x\n", rsp->sp_handle);
+
+    return;
+}
+
+void cmd_shell_stop_offload_rsp
+(
+    ipsecmgr_ipc_stop_offload_rsp_param_t *rsp
+)
+{
+    char resp_str[10] = {0,};
+
+    printf ("\nRecvd STOP_OFFLOAD response:\n");
+    printf ("  trans_id:\t0x%x\n", rsp->trans_id);
+
+    if (rsp->type & RSP_TYPE_ACK) {
+        strcpy(resp_str, "ACK");
+    } else if (rsp->type & RSP_TYPE_DONE) {
+        int slen = strlen(resp_str);
+        if (slen)
+            strcpy(&resp_str[slen], "|DONE");
+        else
+            strcpy(&resp_str[slen], "DONE");
+    } 
+
+    printf ("  resp_type:\t(%d) %s\n", rsp->type, resp_str);
+    printf ("  result:\t(%d) %s\n", rsp->result,
+            ((rsp->result == RESULT_SUCCESS) ? "SUCCESS":"FAIL"));
+
+    return;
+}
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_loc.h b/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_loc.h
new file mode 100755 (executable)
index 0000000..8ee899c
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef __CMD_SHELL_LOC_H__
+#define __CMD_SHELL_LOC_H__
+
+#include <ipsecmgr_ipc.h>
+
+/* Module context for command shell */
+typedef struct {
+    ipsecmgr_trans_id_t  trans_id;
+    ipsecmgr_ipc_user_send_if_t *ipc_send_if;
+} cmd_shell_ctx_t;
+
+/* Command line interpreter task */
+void* cmd_shell (void *args);
+
+/* OFFLOAD_SP response handler */
+void cmd_shell_offload_sp_rsp
+(
+    ipsecmgr_ipc_offload_sp_rsp_param_t *rsp
+);
+
+/* STOP_OFFLOAD response handler */
+void cmd_shell_stop_offload_rsp
+(
+    ipsecmgr_ipc_stop_offload_rsp_param_t *rsp
+);
+
+#endif
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_main.c b/ti/runtime/netapi/applications/ipsec_offload/config-app/src/cmd_shell_main.c
new file mode 100755 (executable)
index 0000000..0f29763
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h> 
+#include <time.h>
+#include <pthread.h>
+#include <string.h>
+
+#include <ipsecmgr_ipc.h>
+#include <ipsecmgr_syslog.h>
+
+#include "cmd_shell_loc.h"
+
+typedef pthread_t task_handle;
+
+#define DEFAULT_STACK_SIZE     0x8000
+static int task_create ( void *(start_routine)(void*), void* args, void* handle)
+{
+    int max_priority, err;
+    pthread_t thread;
+    pthread_attr_t attr;
+    struct sched_param param;
+
+    max_priority = sched_get_priority_max(SCHED_FIFO);
+    err = pthread_attr_init(&attr);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_init failed: (%s)\n", strerror(err));
+        return err;
+    }
+    err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_setdetachstate failed: (%s)\n", strerror(err));
+        return err;
+    }
+    err = pthread_attr_setstacksize(&attr, DEFAULT_STACK_SIZE);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_setstacksize failed: (%s)\n", strerror(err));
+        return err;
+    }
+    err = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_setinheritsched failed: (%s)\n", strerror(err));
+        return err;
+    }
+    err = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_setschedpolicy failed: (%s)\n", strerror(err));
+        return err;
+    }
+    memset(&param, 0, sizeof(param));
+    param.sched_priority = max_priority;
+    err = pthread_attr_setschedparam(&attr, &param);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_attr_setschedparam failed: (%s)\n", strerror(err));
+        return err;
+    }
+    if (err) return err;
+    err = pthread_create(&thread, &attr, start_routine, args);
+    if (err) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "pthread_create failed: (%s)\n", strerror(err));
+        return err;
+    }
+    if (err) return err;
+    *(pthread_t*)handle = thread;
+    return 0;
+}
+
+static void task_wait (void *handle)
+{
+    pthread_join(*((pthread_t*)handle), NULL);
+    return;
+}
+
+static void task_sleep(int time_in_msec)
+{
+    pthread_mutex_t fake_mutex = PTHREAD_MUTEX_INITIALIZER;
+    pthread_cond_t fake_cond = PTHREAD_COND_INITIALIZER;
+    struct timespec ts;
+    int rt;
+    unsigned int sec, nsec;
+
+    sec = time_in_msec/1000;
+    nsec = (time_in_msec - (sec*1000)) * 1000000;
+
+    /* Use the wall-clock time */
+    clock_gettime(CLOCK_REALTIME, &ts);
+
+    ts.tv_sec += sec;
+    ts.tv_nsec += nsec;
+
+    pthread_mutex_lock(&fake_mutex);
+    rt = pthread_cond_timedwait(&fake_cond, &fake_mutex, &ts);
+    pthread_mutex_unlock(&fake_mutex);
+}
+
+#define IPC_POLL_INTVL   1000
+
+static void *ipc_poll(void *args)
+{
+    while(1) {
+        ipsecmgr_ipc_poll();
+        task_sleep(IPC_POLL_INTVL);
+    } /* end while */
+    return (void*)(0);
+}
+
+/* usage ipsecmgr_cmd_shell 
+ */
+int main(int argc, char **argv)
+{
+    ipsecmgr_ipc_cfg_t  ipc_cfg;
+    ipsecmgr_ipc_user_recv_if_t recv_if;
+    task_handle cmd_th, ipc_th;
+    int status;
+
+    /* Start logging module */
+    if (ipsecmgr_syslog_init()) {
+        printf ("Failed to initialize syslog\n");
+        return -1;
+    }
+
+    memset(&ipc_cfg, 0, sizeof(ipc_cfg));
+    ipc_cfg.mode = IPC_MODE_USER_APP;
+
+    if (ipsecmgr_ipc_init(&ipc_cfg)) {
+        printf ("Failed to initialize IPC\n");
+        return -1;
+    }
+
+    recv_if.offload_sp_rsp = cmd_shell_offload_sp_rsp;
+    recv_if.stop_offload_rsp = cmd_shell_stop_offload_rsp;
+
+    if (ipsecmgr_ipc_register_user_recv_iface(&recv_if)) {
+        printf ("Failed to IPC recv interface\n");
+        return -1;
+    }
+
+    /* Create the command line interpreter task */
+    if (status = task_create(cmd_shell, NULL, &cmd_th)) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "ERROR: Command shell task-create failed (%d)\n", status);
+        return (-1);
+    }
+
+    /* Create the FP IPC poll task */
+    if (status = task_create(ipc_poll, NULL, &ipc_th)) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "ERROR: IPC recv task-create failed (%d)\n", status);
+        return (-1);
+    }
+
+    task_wait(&cmd_th);
+    return 0;
+}
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/build/Makefile b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/build/Makefile
new file mode 100755 (executable)
index 0000000..56f96f1
--- /dev/null
@@ -0,0 +1,121 @@
+# Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+
+space =$(empty) $(empty)
+
+export ARMV7OBJDIR ?= ./obj
+export ARMV7BINDIR ?= ./bin
+export ARMV7LIBDIR ?= ./lib
+export ARMV7SALIBDIR ?= ./lib
+export ARMV7LIBDIRLOCAL ?= ../../lib
+# INCLUDE Directories
+SA_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/sa
+QMSS_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/qmss
+CPPI_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/cppi
+NWAL_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/nwal
+PKTLIB_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/runtime/pktlib
+
+HPLIB_INC_DIR ?= $(TRANS_SDK_INSTALL_PATH)
+NETAPI_INC_DIR ?=  $(TRANS_SDK_INSTALL_PATH)
+NETAPI_SRC_DIR ?= $(TRANS_SDK_INSTALL_PATH)/ti/runtime/netapi
+
+CSL_DEVICE ?= -DDEVICE_K2H
+
+
+ifdef CROSS_TOOL_INSTALL_PATH
+## Support backwards compatibility with KeyStone1 approach
+ CC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc
+ AC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)as
+ AR = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)ar
+ LD = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc
+endif
+
+#QUIET_CMD=@
+EXE_NAME_PRFX=ipsecmgr_daemon
+
+###############################################################################
+# Set default options
+###############################################################################
+CFLAGS+= $(DEBUG_FLAG) -I../ -I. $(CSL_DEVICE) -D__ARMv7 -D_VIRTUAL_ADDR_SUPPORT -D__LINUX_USER_SPACE -D_LITTLE_ENDIAN=1 -DNWAL_ENABLE_SA -DMAKEFILE_BUILD -D _GNU_SOURCE
+
+OUTPUT_FILE_OPTION = -o
+
+EXE_NAME = $(EXE_NAME_PRFX).out
+
+ROOT_DIR = ..
+#IPSECMGR_IFACE_DIR?= ../../../
+IPSECMGR_UTIL_IFACE_DIR?= ../../../utils/iface
+IPSECMGR_IFACE_DIR?= ../
+
+
+QMSS_LIB=qmss
+CPPI_LIB=cppi
+PA_LIB=pa
+HPLIB_LIB=hplib
+SA_LIB=sa
+PKTLIB_LIB=pktlib
+NWAL_LIB=nwalsa
+NETAPI_LIB=netapi
+IPSECMGR_SNOOP_LIB=ipsecmgr_snoop
+IPSECMGR_IPC_LIB=ipsecmgr_ipc
+IPSECMGR_SYSLOG_LIB=ipsecmgr_syslog
+
+LIBNL_LD_OPTS = -lnl-3 -lnl-xfrm -lnl-route-3
+
+LD_OPTS += -pthread -lrt
+
+LD_OPTS += -L $(ARMV7LIBDIR) -L $(PDK_ARMV7LIBDIR) -l$(IPSECMGR_SNOOP_LIB) -l$(IPSECMGR_IPC_LIB) -l$(IPSECMGR_SYSLOG_LIB) -l$(NETAPI_LIB) -l$(NWAL_LIB) -l$(PKTLIB_LIB) -l$(SA_LIB) -l$(QMSS_LIB) -l$(CPPI_LIB) -l$(PA_LIB) -l$(HPLIB_LIB) $(LIBNL_LD_OPTS)
+###############################################################################
+# List of modules and their files
+###############################################################################
+DAEMON_SRC_DIR ?= ../src/
+DAEMON_FILES = \
+        netapi_ipsecmgr.c \
+       netapilib_interface.c
+
+VPATH = $(DAEMON_SRC_DIR)
+FILES = $(DAEMON_FILES)
+
+INCL_DIRS= $(IPSECMGR_IFACE_DIR) $(IPSECMGR_UTIL_IFACE_DIR) $(NETAPI_INC_DIR) $(CPPI_INC_DIR) $(QMSS_INC_DIR) $(HPLIB_INC_DIR) $(SA_INSTALL_PATH) $(PDK_INSTALL_PATH) 
+
+HEADERS = $(filter %.h, $(FILES))
+INCL = -I. $(patsubst %,-I%,$(INCL_DIRS))
+
+
+BIN_DIR = $(ARMV7BINDIR)/netapi/applications/ipsec_offload/ipsecmgr
+OBJ_DIR = $(ARMV7OBJDIR)/netapi/applications/ipsec_offload/ipsecmgr
+DAEMON_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(filter %.c, $(FILES)))
+
+
+all: app install
+
+app: $(BIN_DIR)/.created $(BIN_DIR)/$(EXE_NAME)
+###############################################################################
+# Normal make process                                                         
+###############################################################################
+
+$(OBJ_DIR)/%.o: %.c $(OBJ_DIR)/.created
+       @echo compiling $<
+       $(CC) -c  $(CFLAGS) $(INCL)  $<  -o $@
+
+$(OBJ_DIR)/.created:
+       $(QUIET_CMD)@echo "making $@" 
+       @mkdir -p $(OBJ_DIR)
+
+$(BIN_DIR)/.created:
+       @mkdir -p $(BIN_DIR)
+
+$(BIN_DIR)/$(EXE_NAME): $(DAEMON_OBJS) $(BIN_DIR)/.created
+       $(QUIET_CMD)@echo "linking $@" 
+       $(QUIET_CMD)@echo "$(LD_OPTS)" 
+       $(CC) $(DAEMON_OBJS) $(LD_OPTS) -o $(BIN_DIR)/$(EXE_NAME)
+
+install:
+       install -d $(INSTALL_BIN_BASE_DIR)
+       install -c -m 755 $(BIN_DIR)/* $(INSTALL_BIN_BASE_DIR)
+       install -d $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src
+       install -c -m 644 ../src/*.h $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src
+       install -d $(INSTALL_LIB_BASE_DIR)
+       @$(CP) -r $(ARMV7LIBDIR)/*.a         $(INSTALL_LIB_BASE_DIR)
+clean:
+       rm -rf $(OBJ_DIR)
+       rm -rf $(BIN_DIR)
diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c
new file mode 100755 (executable)
index 0000000..d474382
--- /dev/null
@@ -0,0 +1,735 @@
+/*
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+
+/* IPSec Manager Include Files */
+#include "ipsecmgr_snoop.h"
+#include "ipsecmgr_ipc.h"
+#include "ipsecmgr_syslog.h"
+
+/* Local include */
+#include "netapilib_interface.h"
+
+/* Standard includes */
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <stdarg.h>
+/**********************************************************************
+ ************************** Local Definitions *************************
+ **********************************************************************/
+#define DTS_LOG_FILE_QUEUE "/proc/device-tree/soc/pktdma@2004000/channels/netrx0/complete-queue"
+#define DTS_LOG_FILE_FLOW  "/proc/device-tree/soc/pktdma@2004000/channels/netrx0/flow"
+
+
+/**********************************************************************
+ ************************** Global Variables **************************
+ **********************************************************************/
+
+static ipsecmgr_ipc_daemon_send_if_t *send_iface;
+NETAPI_T netapi_handle;
+
+//paSysStats_t netcp_stats;
+ipsecMgrMcb_t globalCfg;
+
+/* Lock file for the daemon */
+#define LOCK_FILE   "/var/lock/ipsecmgr_daemon"
+
+/* snoop task */
+static pthread_t    snoop_run_th;
+
+static NETAPI_CFG_T our_netapi_default_cfg=
+{
+    TUNE_NETAPI_PERM_MEM_SZ,
+    128,  //start of packet offset for hw to place data on rx for default flow
+    TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
+    TUNE_NETAPI_NUM_GLOBAL_DESC,        //total we will use
+    TUNE_NETAPI_DEFAULT_NUM_BUFFERS,   //#descriptors+buffers in default heap
+    64, //#descriptors w/o buffers in default heap
+    TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
+    128   ,  //tail room
+    256      //extra room
+};
+
+/* stub functions */
+static void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+                         PKTIO_METADATA_T meta[], int n_pkts,
+                         uint64_t ts )
+{
+    return;
+}
+
+/* byte swap routine */
+static unsigned int swap32 (unsigned int x)
+{
+    unsigned int y;
+
+    y = (((x >> 24) & 0xff) <<  0) |
+        (((x >> 16) & 0xff) <<  8) |
+        (((x >>  8) & 0xff) << 16) |
+        (((x >>  0) & 0xff) << 24) ;
+
+    return (y);
+
+}
+
+
+static void* snoop_run_thread (void* arg)
+{
+    ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+        "snoop_run_thread: daemon entering forever event loop\n");
+
+    while (1)
+    {
+        /* Poll for message from user application */
+        ipsecmgr_ipc_poll();
+
+        /* Poll for message from Kernel */
+        ipsecmgr_snoop_run();
+    }
+
+    return;
+}
+
+/**
+ *  @b Description
+ *  @n  
+ *      SIGTERM handler.
+ *
+ *  @param[in]  lock_file
+ *      Lock file to be used by the daemon
+ */
+static void sig_term_handler(int signum)
+{
+
+    /* Cleanup and exit */        
+    ipsecmgr_snoop_shutdown ();
+
+    netapi_shutdown(netapi_handle);
+    exit (0);
+}
+
+/**
+ *  @b Description
+ *  @n  
+ *      Function to implement task sleep functionality 
+ *      for IPSecMgr
+ *
+ *  @param[in]  time_in_msec
+ *      Time in milliseconds to sleep
+ *
+ *  @retval
+ *      Not Applicable.
+ */
+static void task_sleep(uint32_t time_in_msec)
+{
+    pthread_mutex_t fake_mutex = PTHREAD_MUTEX_INITIALIZER;
+    pthread_cond_t fake_cond = PTHREAD_COND_INITIALIZER;
+    struct timespec ts;
+    int rt;
+    unsigned int sec, nsec;
+
+    sec = time_in_msec/1000;
+    nsec = (time_in_msec - (sec*1000)) * 1000000;
+
+    /* Use the wall-clock time */
+    clock_gettime(CLOCK_REALTIME, &ts);
+
+    ts.tv_sec += sec;
+    ts.tv_nsec += nsec;
+
+    pthread_mutex_lock(&fake_mutex);
+    rt = pthread_cond_timedwait(&fake_cond, &fake_mutex, &ts);
+    pthread_mutex_unlock(&fake_mutex);
+}
+
+
+/**
+ *  @b Description
+ *  @n  
+ *      NETAPI Proxy's IPSecMgr Start Offload Response 
+ *      message handler.
+ *
+ *      This function is called by the IPSecMgr library
+ *      when it has a response ready corresponding to an
+ *      Start Offload SP request issued by the user application.
+ *
+ *  @param[in]  rsp
+ *      IPSecMgr's Start Offload SP response
+ *  @param[in]  addr
+ *      Destination address (user application) to send 
+ *      the response to
+ *  @param[in]  addr_size
+ *      Size of destination address passed
+ *
+ *  @retval
+ *      Success -   0
+ *  @retval
+ *      ERROR   -   <0
+ */
+static int offload_sp_rsp_send
+(
+    ipsecmgr_snoop_offload_sp_rsp_param_t *rsp,
+    void                                  *addr,
+    uint32_t                              addr_size
+)
+{
+    ipsecmgr_ipc_offload_sp_rsp_param_t offload_sp_rsp;
+
+    offload_sp_rsp.type = rsp->type;
+    offload_sp_rsp.result = rsp->result;
+    offload_sp_rsp.trans_id = rsp->trans_id;
+    offload_sp_rsp.err_code = rsp->err_code;
+    offload_sp_rsp.sp_handle = rsp->sp_handle;
+    offload_sp_rsp.sa_handle = rsp->sa_handle;
+
+    if (addr_size != sizeof(ipsecmgr_ipc_addr_t)) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "offload_sp_rsp_send: addr size not correct\n");
+        return -1;
+    }
+
+    return send_iface->offload_sp_rsp(&offload_sp_rsp,
+                                      (ipsecmgr_ipc_addr_t *)addr);
+}
+static void offload_sp_req_recv
+(
+    ipsecmgr_ipc_offload_sp_req_param_t *req,
+    ipsecmgr_ipc_addr_t                 *src_addr
+)
+{
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"offload_sp_req_recv called for policy id\n",
+    req->policy_id);
+    ipsecmgr_snoop_offload_sp_rsp_param_t rsp;
+    uint32_t addr_size = sizeof(ipsecmgr_ipc_addr_t);
+    ipsecmgr_snoop_offload_sp_req_param_t offload_sp_req;
+
+    offload_sp_req.trans_id = req->trans_id;
+    offload_sp_req.policy_id = req->policy_id;
+    offload_sp_req.sa_flags = req->sa_flags;
+    offload_sp_req.if_name = req->if_name;
+    offload_sp_req.dscp_cfg = req->dscp_cfg;
+    offload_sp_req.l5_selector = req->l5_selector;
+
+    memset(&rsp, 0, sizeof(rsp));
+    rsp.trans_id = req->trans_id;
+
+    if (ipsecmgr_snoop_offload_sp_req(&offload_sp_req, (void*)src_addr,
+                                      addr_size)) {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "offload_sp_req_recv: snoop_offload_sp_req failed\n");
+        rsp.result = RESULT_FAILURE;
+        rsp.type = RSP_TYPE_ACK | RSP_TYPE_DONE;
+    }
+    else
+    {
+        rsp.result = RESULT_SUCCESS;
+        rsp.type = RSP_TYPE_ACK;
+    }
+    
+    if (offload_sp_rsp_send(&rsp, (void *)src_addr, addr_size))
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "offload_sp_req_recv: failed to send ACK for offload_sp\n");
+    }
+    return;
+}
+
+
+/**
+ *  @b Description
+ *  @n  
+ *      NETAPI Proxy's IPSecMgr Stop Offload response message 
+ *      handler.
+ *
+ *      This function is called by the IPSecMgr library
+ *      when it has a response ready corresponding to an
+ *      Stop Offload SP request issued by the user application.
+ *
+ *  @param[in]  rsp
+ *      IPSecMgr's Stop Offload SP response
+ *  @param[in]  addr
+ *      Destination address (user application) to send 
+ *      the response to
+ *  @param[in]  addr_size
+ *      Size of destination address passed
+ *
+ *  @retval
+ *      Success -   0
+ *  @retval
+ *      ERROR   -   <0
+ */
+static int stop_offload_rsp_send
+(
+    ipsecmgr_snoop_stop_offload_rsp_param_t *rsp,
+    void                                    *addr,
+    uint32_t                                addr_size
+)
+{
+    ipsecmgr_ipc_stop_offload_rsp_param_t stop_offload_rsp;
+
+    stop_offload_rsp.type = rsp->type;
+    stop_offload_rsp.result = rsp->result;
+    stop_offload_rsp.trans_id = rsp->trans_id;
+
+    if (addr_size != sizeof(ipsecmgr_ipc_addr_t)) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
+            "stop_offload_rsp_send: addr size not correct\n");
+        return -1;
+    }
+
+    return send_iface->stop_offload_rsp(&stop_offload_rsp,
+                                      (ipsecmgr_ipc_addr_t *)addr);
+}
+
+static void stop_offload_req_recv
+(
+    ipsecmgr_ipc_stop_offload_req_param_t   *req,
+    ipsecmgr_ipc_addr_t                     *src_addr
+)
+{
+    ipsecmgr_snoop_stop_offload_req_param_t stop_offload_req;
+    uint32_t addr_size = sizeof(ipsecmgr_ipc_addr_t);
+    ipsecmgr_snoop_stop_offload_rsp_param_t rsp;
+
+    stop_offload_req.trans_id = req->trans_id;
+    stop_offload_req.policy_id = req->policy_id;
+
+    memset(&rsp, 0, sizeof(rsp));
+    rsp.trans_id = req->trans_id;
+
+    if (ipsecmgr_snoop_stop_offload(&stop_offload_req, (void*)src_addr,
+                                      addr_size)) {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "stop_offload_req_recv: snoop_stop_offload failed\n");
+        rsp.result = RESULT_FAILURE;
+        rsp.type = RSP_TYPE_ACK | RSP_TYPE_DONE;
+    }
+    else
+    {
+        rsp.result = RESULT_SUCCESS;
+        rsp.type = RSP_TYPE_ACK;
+    }
+
+    if (stop_offload_rsp_send(&rsp, (void *)src_addr, addr_size))
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "stop_offload_req_recv: failed to send ACK for stop_offload\n");
+    }
+    return;
+}
+
+/**
+ *  @b Description
+ *  @n  
+ *      Function to initialize IPSec Manager library.
+ *
+ *  @retval
+ *      Success -   0
+ *  @retval
+ *      ERROR   -   >0
+ */
+static int32_t init_ipsecmgr (void)
+{
+    struct ipsecmgr_snoop_fp_cfg_cb     fp_cfg_cb;
+    struct ipsecmgr_snoop_mgnt_cb       mgnt_cb;
+    struct ipsecmgr_snoop_platform_cb   plat_cb;
+    ipsecmgr_ipc_daemon_recv_if_t       recv_if;
+    ipsecmgr_ipc_cfg_t                  ipc_cfg;
+    int32_t                             status;
+    pthread_attr_t threadAttr;
+
+    /* Initializations */
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO, 
+                        "DEBUG: init_ipsecmgr() starting initialization\n");
+    memset(&fp_cfg_cb, 0, sizeof(fp_cfg_cb));
+    memset(&mgnt_cb, 0, sizeof(mgnt_cb));
+    memset(&plat_cb, 0, sizeof(plat_cb));
+    memset(&recv_if, 0, sizeof(recv_if));
+    memset(&ipc_cfg, 0, sizeof(ipc_cfg));
+
+    /* Initialize IPC library */
+    ipc_cfg.mode = IPC_MODE_SNOOP_DAEMON;
+    if (ipsecmgr_ipc_init(&ipc_cfg)) {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "init_ipsecmgr: ipc_init failed\n");
+        return -1;
+    }
+    else
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "init_ipsecmgr: ipc_init sucess\n");
+
+    if (ipsecmgr_ipc_get_daemon_send_iface(&send_iface)) {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "init_ipsecmgr: ipc_get_daemon_send_iface failed\n");
+        return -1;
+    }
+    recv_if.offload_sp_req = offload_sp_req_recv;
+    recv_if.stop_offload_req = stop_offload_req_recv;
+    /* Register ipsecmgr daemon recieve i/f */
+    if (ipsecmgr_ipc_register_daemon_recv_iface(&recv_if)) {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "snoop_run: ipc_register_daemon_recv_iface failed\n");
+        return -1;
+    }
+
+    /* Initialize the IPSec Manager Snoop library */
+    fp_cfg_cb.add_sa        =   netapilib_ifAddSA;
+    fp_cfg_cb.add_sp        =   netapilib_ifAddSP;
+    fp_cfg_cb.del_sa        =   netapilib_ifDeleteSA;
+    fp_cfg_cb.del_sp        =   netapilib_ifDeleteSP;
+    fp_cfg_cb.get_sa_ctx    =   netapilib_ifGetSACtx;
+
+    plat_cb.log_msg  = (ipsecmgr_snoop_log_msg_t)ipsecmgr_syslog_msg;
+    plat_cb.sleep           =   task_sleep;
+
+    mgnt_cb.offload_sp_rsp  =   offload_sp_rsp_send;
+    mgnt_cb.stop_offload_rsp=   stop_offload_rsp_send;
+    mgnt_cb.rekey_event     =   NULL; // No explicit notifications needed on Rekey completion
+
+    if ((status = ipsecmgr_snoop_init (&fp_cfg_cb, &mgnt_cb, &plat_cb))) 
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+                            "DEBUG: init_ipsecmgr() ipsecmgr_snoop_init failed (%d)\n", status);
+        return -1;
+    }
+
+    /* Create the task context for snoop library */
+    pthread_attr_init(&threadAttr);
+    pthread_attr_setstacksize(&threadAttr, 0x8000);
+    if (pthread_create(&snoop_run_th, (void*) NULL, snoop_run_thread, NULL))
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "ERROR: NETAPI Proxy Poll Thread failed to start, error code\n"); 
+
+        /* Cleanup the plugin and exit */
+        //netapiIPSecMgrMcb.pluginMcb.exit ();
+        return -1;
+    }
+
+    /* Setup signal handler for SIGTERM */
+    if (signal(SIGTERM, sig_term_handler) == SIG_ERR) {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_WARN,
+            "snoop_run: cannot handle SIGTERM\n");
+    }
+    /* Wait for the NETAPI Proxy task to finish its processing and exit. */
+    pthread_join (snoop_run_th, NULL);
+
+    return 0;
+}
+
+/**
+ *  @b Description
+ *  @n  
+ *      Utility function to daemonize the current
+ *      application.
+ *
+ *  @param[in]  lock_file
+ *      Lock file to be used by the daemon
+ */
+static void daemonize (const char *lock_file)
+{
+    pid_t       pid, sid;
+    int32_t     lock_fp = -1;
+    char        str[10];
+
+    /* already a daemon */
+    if (getppid () == 1)
+        return;
+
+    /* Fork off the parent process */
+    if ((pid = fork ()) < 0) 
+    {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR, 
+                            "ERROR: daemonize() unable to fork daemon, code=%d (%s)",
+                            errno, 
+                            strerror(errno));
+        exit (-1);
+    }
+
+    /* If we got a PID, then exit the parent process. */
+    if (pid > 0)
+        exit (0);
+
+    /* At this point we are executing as the child process */
+
+    /* Create a new SID for the child process */
+    if ((sid = setsid ()) < 0) 
+    {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR, 
+                            "ERROR: daemonize() unable to create a new session, code %d (%s)",
+                            errno, 
+                            strerror(errno));
+        exit (-1);
+    }
+
+    /* Change the file mode mask */
+    umask (027);
+
+    /* Change the current working directory.  This prevents the current
+     * directory from being locked; hence not being able to remove it. */
+    if ((chdir("/")) < 0) 
+    {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR, 
+                            "ERROR: daemonize() unable to change directory to %s, code %d (%s)",
+                            "/", 
+                            errno, 
+                            strerror(errno));
+        exit (-1);
+    }
+
+    /* Create the lock file */
+    if (lock_file) 
+    {
+        if ((lock_fp = open(lock_file, O_RDWR|O_CREAT, 0640)) < 0 ) 
+        {
+            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR, 
+                                "ERROR: daemonize() unable to create lock file %s, code=%d (%s)",
+                                lock_file, 
+                                errno, 
+                                strerror(errno));
+            exit (-1);
+        }
+    }
+
+    if (lockf (lock_fp, F_TLOCK, 0) < 0) 
+        exit(-1); /* can not lock */
+
+    /* Record pid to lockfile */
+    sprintf (str, "%d\n", getpid());
+    write (lock_fp, str, strlen(str)); 
+
+    /* Cancel certain signals */
+    signal (SIGCHLD, SIG_DFL); /* A child process dies */
+    signal (SIGTSTP, SIG_IGN); /* Various TTY signals */
+    signal (SIGTTOU, SIG_IGN);
+    signal (SIGTTIN, SIG_IGN);
+    signal (SIGHUP, SIG_IGN); /* Ignore hangup signal */
+    signal (SIGTERM, sig_term_handler); /* catch SIGTERM */
+
+    /* Redirect standard files to /dev/null */
+    freopen( "/dev/null", "r", stdin);
+    freopen( "/dev/null", "w", stdout);
+    freopen( "/dev/null", "w", stderr);
+
+    /* Done setting up the daemon */
+    return;
+}
+
+/* FUNCTION PURPOSE:validate and process inputs to the application */
+int32_t parse_cmd_line_args(int argc, char** argv)
+{
+    int32_t             i;
+
+    /* Valid command line options */
+    if (argc == 1)
+    {
+        printf("netapi_proxyParseCommandLineArgs, argc =1\n");
+        return 0;
+    }
+    else
+    {
+           printf("netapi_proxyParseCommandLineArgs, argc=%d\n", argc);
+     
+    }
+
+    /* Scan and parse the command line options */
+    for (i = 1; i < argc; i ++)
+    {
+        if (argv[i][0] == '-' && argv[i][1] == 'f')
+        {
+            /* Log file name */                
+            if (i+1 >= argc || argv[i+1] == NULL)
+                return -1;
+
+#if 0
+            /* Close the default log file if we opened it already */
+            if (netapiIPSecMgrMcb.logFd)
+                fclose (netapiIPSecMgrMcb.logFd);                    
+
+            /* Open the log file specified at command line */
+            if ((netapiIPSecMgrMcb.logFd  = fopen(argv[i+1], "a")) == NULL)
+            {
+                printf ("Error opening log file %s\n", argv[i+1]);
+                return -1;
+            }
+#endif
+            i++;
+        }
+
+        else
+        {
+            /* Invalid options */                
+            return -1;
+        }
+    }
+
+    /* Success */
+    return 0;
+}
+
+int get_kernel_config()
+{
+    uint32_t temp=0;
+    char name[] = "offload_chan";
+    FILE *pDts = NULL;
+
+    pDts = fopen(DTS_LOG_FILE_QUEUE, "rb");
+
+    if(pDts)
+    {
+        fread((void*)&temp, sizeof(uint32_t), 1, pDts);
+        globalCfg.qNum= (int)swap32(temp);
+        fclose(pDts);
+    }
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "main: error opening device tree file: %s\n",DTS_LOG_FILE_QUEUE);
+        return -1;
+    }
+
+    pDts = NULL;
+    pDts = fopen(DTS_LOG_FILE_FLOW, "rb");
+
+    if(pDts)
+    {
+        fread((void*)&temp, sizeof(uint32_t), 1, pDts);
+        globalCfg.flowId = (int)swap32(temp);
+        fclose(pDts);
+    }
+    else
+    {
+        printf("main: error opening %s\n",DTS_LOG_FILE_FLOW);
+        return -1;
+    }
+    
+    return 0;
+}
+
+int create_pktio_channel()
+{
+    int error = 0;
+    char name[] = "offload_chan";
+    PKTIO_HANDLE_T *pktio_channel;
+    PKTIO_CFG_T pktio_cfg;
+
+    pktio_cfg.qnum = globalCfg.qNum;
+    pktio_cfg.flags1 = PKTIO_RX;
+    pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
+    pktio_cfg.max_n = 8;
+
+    globalCfg.pktio_channel = netapi_pktioCreate(netapi_handle,
+                                               &name[0],
+                                               (PKTIO_CB)recv_cb,
+                                               &pktio_cfg,
+                                               &error);
+    if (!globalCfg.pktio_channel)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "create_pktio_channel: failed\n");
+        return -1;
+    }
+
+    return 0;
+}
+/**
+ *  @b Description
+ *  @n  
+ *      Entry point for the NETAPI Proxy application.
+ *
+ *  @param[in]  argc
+ *      Number of arguments passed to the application
+ *  @param[in]  argv
+ *      Arguments passed to the application.
+ *
+ *  @retval
+ *      Success -   0
+ *  @retval
+ *      ERROR   -   >0
+ */
+int32_t main (int argc, char* argv[])
+{
+    int32_t             retVal;
+    ipsecmgr_syslog_init();
+
+    /* create netapi */
+    netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
+
+    if(netapi_handle == NULL)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR, "ERROR: netapi_init failed\n");
+        printf("main: netapi_init failed\n");
+        return -1;
+    }
+    else
+        printf("main: netapi_init passed\n");
+
+    if (get_kernel_config())
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                            "ERROR: main: get_kernel_config() failed\n");
+        return -1;
+    }
+
+        if (create_pktio_channel())
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                            "ERROR: main: create_pktio_channel() failed\n");
+        return -1;
+    }
+
+#if 1
+    /* Read and parse command line options */
+    if (parse_cmd_line_args (argc, argv) < 0)
+    {
+        printf ("Usage format: netfpproxy.out [-f <log_file>]\n");
+        return -1;
+    }
+#endif
+    printf("main: calling daemonize\n");
+    /* Create the proxy daemon. */
+    //daemonize (LOCK_FILE);
+
+    /* Initialize and start the IPSec Mgr Snoop functionality */
+    if ((retVal = init_ipsecmgr ()) < 0)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                            "ERROR: IPSec Mgr init failed, error code %d \n",
+                            retVal);
+        return -1;
+    }
+    else
+        printf("main: init_ipsecmgr passed\n");
+}
diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c
new file mode 100755 (executable)
index 0000000..6256ed5
--- /dev/null
@@ -0,0 +1,492 @@
+/*
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+/* Standard includes */
+#include <stdio.h>
+#include <arpa/inet.h>
+#include <inttypes.h>
+
+/* ipsecmgr includes */
+#include <ipsecmgr_snoop.h>
+#include <ipsecmgr_syslog.h>
+
+#include "netapilib_interface.h"
+
+
+extern ipsecMgrMcb_t globalCfg;
+extern NETAPI_T netapi_handle;
+NETCP_CFG_SA_T saAppIdOut = 0;
+NETCP_CFG_SA_T saAppIdIn = 0;
+
+/**************************************************************************
+ * FUNCTION PURPOSE: The function is used to translate the SA configuration
+ * parameters received from the IPSec Snopper and call the NETAPI function
+ * to create a security association
+ ********************************************************************/
+int netapilib_ifAddSA
+(
+    ipsecmgr_af_t               af,
+    ipsecmgr_sa_id_t            *sa_id,
+    ipsecmgr_sa_info_t          *sa_info,
+    ipsecmgr_sa_dscp_map_cfg_t  *dscp_map_cfg,
+    ipsecmgr_ifname_t           *if_name,
+    ipsecmgr_sa_encap_tmpl_t    *encap,
+    ipsecmgr_fp_handle_t        *sa_handle
+)
+{
+    uint8_t                 auth_key[36];
+    uint8_t                 encr_key[36];
+    int error, index;
+    NETAPI_SEC_SA_INFO_T saInfo;
+    nwalSecKeyParams_t  keyParams;
+    void * p_rx_inflow_mode_handle;
+    void * p_tx_inflow_mode_handle;
+    NETCP_CFG_ROUTE_T  route;
+    NETCP_CFG_FLOW_T flow;
+    NETCP_CFG_SA_HANDLE_T pSaHandle;
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO, 
+                "netapilib_ifAddSA:, DEBUG: Translating SA\n");
+
+
+    memset((void *)&saInfo, 0, sizeof (NETAPI_SEC_SA_INFO_T));
+    memset((void *)&keyParams, 0, sizeof (nwalSecKeyParams_t));
+    memset((void *)&route, 0, sizeof (NETCP_CFG_ROUTE_T));
+    memset((void *)&flow, 0, sizeof (NETCP_CFG_FLOW_T));
+
+    flow.dma_engine= 1;
+    flow.flowid = globalCfg.flowId;
+    route.p_flow = &flow;
+    route.p_dest_q = globalCfg.pktio_channel;
+
+
+    /* Initialize the SA Config structure. */
+    /* Get the IP protocol version. */
+    if (af == IPSECMGR_AF_IPV4)
+    {
+        saInfo.ipType = nwal_IPV4;
+        /* Populate the source and destination IP addresses. */
+        for (index = 0; index < 4; index++)
+        {
+            saInfo.dst.ipv4[index] = sa_id->daddr.ipv4[index];
+            saInfo.src.ipv4[index] = sa_info->saddr.ipv4[index];
+        }
+    }
+    else if (af == IPSECMGR_AF_IPV6)
+    { 
+        saInfo.ipType = nwal_IPV6;
+
+        /* Populate the source and destination IP addresses. */
+        for (index = 0; index < 16; index++)
+        {
+            saInfo.dst.ipv6[index] = sa_id->daddr.ipv6[index];
+            saInfo.src.ipv6[index] = sa_info->saddr.ipv6[index];
+        }
+    }
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSA: Address family (%d) is invalid\n", af);
+        return -1;
+    }
+    /* Get the SPI. */
+    saInfo.spi = sa_id->spi;
+
+    /* Get the SA direction. */
+    if (sa_info->dir == DIR_INBOUND)
+        saInfo.dir = NWAL_SA_DIR_INBOUND;
+    else if (sa_info->dir == DIR_OUTBOUND)
+        saInfo.dir = NWAL_SA_DIR_OUTBOUND;
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSA: IPSec direction (%d) is invalid\n", sa_info->dir);
+        return -1;
+    }
+    
+
+    /* Get the replay Window */
+    saInfo.replayWindow = sa_info->replay_window;
+   
+    /* Get the IPSec protocol. */
+    if (sa_id->proto == SA_PROTO_AH)
+        saInfo.proto = nwal_IpSecProtoAH;
+    else if (sa_id->proto == SA_PROTO_ESP)
+        saInfo.proto = nwal_IpSecProtoESP;
+    else
+    {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+            "netapilib_ifAddSA: IPSec protocol (%d) is invalid.\n", sa_id->proto);
+        return -1;
+    }
+    /* Get the IPSec mode. */
+    if (sa_info->mode == SA_MODE_TRANSPORT)
+        saInfo.saMode = nwal_SA_MODE_TRANSPORT;
+    else if (sa_info->mode == SA_MODE_TUNNEL)
+        saInfo.saMode = nwal_SA_MODE_TUNNEL;
+    else
+    {
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+            "netapilib_ifAddSA: IPSec mode (%d) is invalid.\n", sa_info->mode);
+        return -1;
+    }
+    /* Get the authentication mode algorithm. */
+    if (sa_info->auth.algo == SA_AALG_HMAC_SHA1)
+    {
+        saInfo.authMode = NWAL_SA_AALG_HMAC_SHA1;
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifAddSA: auth algo is SA_AALG_HMAC_SHA1\n");
+    }
+    else if (sa_info->auth.algo == SA_AALG_HMAC_MD5)
+        saInfo.authMode = NWAL_SA_AALG_HMAC_MD5;
+    else if (sa_info->auth.algo == SA_AALG_NONE || sa_info->auth.algo == SA_AALG_NULL)  
+        saInfo.authMode = NWAL_SA_AALG_NULL;
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifAddSA: Authentication algorithm (%d) is invalid\n", sa_info->auth.algo);
+        return -1;
+    }
+
+    /* Get the encryption mode algorithm. */
+    if (sa_info->enc.algo == SA_EALG_NULL) 
+        saInfo.cipherMode = NWAL_SA_EALG_NULL;
+    else if (sa_info->enc.algo == SA_EALG_AES_CTR) 
+        saInfo.cipherMode = NWAL_SA_EALG_AES_CTR;
+    else if (sa_info->enc.algo == SA_EALG_AES_CBC)
+    {
+        saInfo.cipherMode = NWAL_SA_EALG_AES_CBC;
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"encr algo is NWAL_SA_EALG_AES_CBC\n");
+    }
+    else if (sa_info->enc.algo == SA_EALG_3DES_CBC) 
+        saInfo.cipherMode = NWAL_SA_EALG_3DES_CBC;
+    else if (sa_info->enc.algo == SA_EALG_DES_CBC) 
+        saInfo.cipherMode = NWAL_SA_EALG_DES_CBC;
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSA: Encryption algorithm (%d) is invalid\n", sa_info->enc.algo);
+        return -1;
+    }
+    /* Validate the key lengths. */
+    if ((keyParams.macKeySize = sa_info->auth_key_len) > 32)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSA: Authentication key size (%d) is invalid.\n", sa_info->auth_key_len);
+        return -1;
+    }
+    if ((keyParams.encKeySize = sa_info->enc_key_len) > 32)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSA: Encryption key size (%d) is invalid.\n", sa_info->enc_key_len);
+        return -1;
+    }
+
+    /* Get the authentication/encryption keys. */
+    keyParams.pAuthKey = &sa_info->auth_key[0];
+    keyParams.pEncKey = &sa_info->enc_key[0];
+
+    if (saInfo.dir == NWAL_SA_DIR_INBOUND)
+    {
+        /* Inbound == RX */
+        saAppIdIn = netapi_secAddSA(netapi_handle,
+                        NETCP_CFG_NO_INTERFACE,
+                        &saInfo,
+                        &keyParams,
+                        NETAPI_SEC_SA_INFLOW,
+                        (NETCP_CFG_ROUTE_HANDLE_T)&route,
+                        &p_rx_inflow_mode_handle,
+                        &p_tx_inflow_mode_handle,
+                        NULL, &error);
+
+        if (error == NETAPI_ERR_OK)
+        {
+            *sa_handle = saAppIdIn;
+        }
+        else
+        {
+            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                                "netapilib_ifAddSA: netapi_secAddSA returned error: %d.\n",
+                                 error);
+            return -1;
+        }
+    }
+    else
+    {
+        /* OUTBOUND == TX */
+        saAppIdOut = netapi_secAddSA(netapi_handle,
+                        NETCP_CFG_NO_INTERFACE,
+                        &saInfo,
+                        &keyParams,
+                        NETAPI_SEC_SA_INFLOW,
+                        (NETCP_CFG_ROUTE_HANDLE_T)NULL,
+                        &p_rx_inflow_mode_handle,
+                        &p_tx_inflow_mode_handle,
+                        NULL, &error);
+        if (error == NETAPI_ERR_OK)
+        {
+            *sa_handle = saAppIdOut;
+#if 0
+             netapi_secGetPaHandle(netapi_handle,
+                          saAppIdOut,
+                          NULL,
+                          &pSaHandle);
+#endif
+        }
+        else
+        {
+            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                                "netapilib_ifAddSA: netapi_secAddSA returned error: %d.\n",
+                                 error);
+            return -1;
+        }
+    }
+    
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+    "netapilib_ifAddSA: Translation of SA successful, app_id: 0x%x\n", *sa_handle);
+
+    /* SA was created successfully. */
+    return 0;
+}
+/**************************************************************************
+ * FUNCTION PURPOSE: The function is used to translate the SA configuration
+ * parameters received from the IPSec Snopper and call the NETAPI function
+ * to delete a security association
+ ********************************************************************/
+int netapilib_ifDeleteSA (ipsecmgr_fp_handle_t sa_handle)
+{
+    int error;
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+    "netapilib_ifDeleteSA: sa_app_id 0x%x\n", sa_handle);
+    netapi_secDelSA(netapi_handle,
+                    NETCP_CFG_NO_INTERFACE,
+                    (NETCP_CFG_SA_T) sa_handle,
+                    &error);
+    return error;
+}
+
+/**************************************************************************
+ * FUNCTION PURPOSE: The function is used to translate the SP configuration
+ * parameters received from the IPSec Snopper and call the NETAPI function
+ * to create a security policy
+ ********************************************************************/
+int32_t netapilib_ifAddSP
+(
+    ipsecmgr_af_t           af,
+    ipsecmgr_selector_t     *sel,
+    ipsecmgr_dir_t          dir,
+    uint32_t                reqid,
+    ipsecmgr_fp_handle_t    sa_handle, 
+    ipsecmgr_policy_id_t    policy_id,
+    ipsecmgr_fp_handle_t    *sp_handle
+)
+{
+    NETCP_CFG_IPSEC_POLICY_T spAppIdIn;
+    int error, index;
+    nwal_IpType ipType;
+    nwalIpAddr_t src_ip_addr;
+    nwalIpAddr_t dst_ip_addr;
+    nwalIpOpt_t ip_qualifiers;
+    NETCP_CFG_SA_T sa =(NETCP_CFG_SA_T)sa_handle;
+    NETCP_CFG_ROUTE_T  route;
+    NETCP_CFG_FLOW_T flow;
+    NETCP_CFG_PA_HANDLE_T* pPaHandle;
+    NETCP_CFG_SA_HANDLE_T* pSaHandle;
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"netapilib_ifAddSP: called\n");
+
+
+    if (dir == DIR_OUTBOUND)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifAddSP: called for outbound SA, no RX policy required\n");
+        return 0;
+    }
+    flow.dma_engine= 1;
+    flow.flowid = globalCfg.flowId;
+    route.p_flow = &flow;
+    route.p_dest_q = globalCfg.pktio_channel;
+
+    /* Get the IP protocol version. */
+    if (af == IPSECMGR_AF_IPV4)
+    {
+        ipType = nwal_IPV4;
+        /* Populate the source and destination IP addresses. */
+        for (index = 0; index < 4; index++)
+        {
+            dst_ip_addr.ipv4[index] = sel->daddr.ipv4[index];
+            src_ip_addr.ipv4[index] = sel->saddr.ipv4[index];
+        }
+    }
+    else if (af == IPSECMGR_AF_IPV6)
+    { 
+        ipType = nwal_IPV6;
+        /* Populate the source and destination IP addresses. */
+        for (index = 0; index < 16; index++)
+        {
+            dst_ip_addr.ipv6[index] = sel->daddr.ipv6[index];
+            src_ip_addr.ipv6[index] = sel->saddr.ipv6[index];
+        }
+    }
+    else
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifAddSP: Address family (%d) is invalid\n", af);
+        return -1;
+    }
+
+    ip_qualifiers.flowLabel = 1; 
+    ip_qualifiers.proto = 1;
+    ip_qualifiers.tos = 1;
+    ip_qualifiers.validParams = 1;
+    
+    spAppIdIn = netapi_secAddRxPolicy(netapi_handle,
+                                     (NETCP_CFG_SA_T) sa_handle,
+                                     ipType,
+                                     &src_ip_addr,
+                                     &dst_ip_addr,
+                                     NULL,
+                                     (NETCP_CFG_ROUTE_HANDLE_T)&route,
+                                     NULL,
+                                     &error);
+
+        if (error == NETAPI_ERR_OK)
+        {
+                *sp_handle = spAppIdIn;
+        }
+        else
+        {
+            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                                "netapilib_ifAddSA: netapi_secAddRxPolicy returned error: %d.\n",
+                                 error);
+            return -1;
+        }
+
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+        "netapi_proxy:DEBUG: Translation of SP successful.\n");
+
+#if 0
+    netapi_secGetPaHandle(netapi_handle,
+                          (NETCP_CFG_SA_T)sa_handle,
+                          pPaHandle,
+                          pSaHandle);
+#endif
+    return 0;
+}
+
+/**************************************************************************
+ * FUNCTION PURPOSE: The function is used to translate the SP configuration
+ * parameters received from the IPSec Snopper and call the NETAPI function
+ * to delete a security association
+ ********************************************************************/
+int32_t netapilib_ifDeleteSP
+(
+    ipsecmgr_fp_handle_t    sp_handle,
+    ipsecmgr_policy_id_t    policy_id,
+    ipsecmgr_dir_t          dir
+)
+{
+    int error =0;
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"netapilib_ifDeleteSP: called\n");
+
+    if (dir == DIR_OUTBOUND)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifDeleteSP: called for outbound SA, no RX policy to delete\n");
+            return 0;
+    }
+    netapi_secDelRxPolicy(netapi_handle,
+                          (NETCP_CFG_IPSEC_POLICY_T) sp_handle,
+                          &error);
+                          
+    return 0;
+}
+
+/**************************************************************************
+ * FUNCTION PURPOSE: The function is used to translate the SA configuration
+ * parameters received from the IPSec Snopper and retrieve SA context
+ * information for SA.
+ *************************************************************************/
+int netapilib_ifGetSACtx
+(
+    ipsecmgr_fp_handle_t    sa_handle,
+    ipsecmgr_sa_hw_ctx_t*   hw_ctx
+)
+{
+    uint32_t swInfo0 = 0;
+    uint32_t swInfo1 = 0;
+    nwalGlobCxtInfo_t info;
+    nwal_RetValue retVal;
+
+    memset(&info, 0, sizeof(nwalGlobCxtInfo_t));
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) netapi_handle;
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"netapilib_ifGetSACtx: called\n");
+
+
+    netapip_netcpCfgGetSaInflowInfo(&netapi_get_global()->nwal_context,
+                                    (NETCP_CFG_SA_T) sa_handle,
+                                    &swInfo0,
+                                    &swInfo1);
+
+    hw_ctx->swinfo_sz = 2;
+    hw_ctx->swinfo[0] = swInfo0;
+    hw_ctx->swinfo[1] = swInfo1;
+
+    retVal = nwal_getGlobCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
+        &info);
+    if (retVal != nwal_OK)
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "netapilib_ifGetSACtx: nwal_getGlobCxtInfo returned error: 0x%x\n", retVal);
+        return -1;
+    }
+    hw_ctx->flow_id = info.rxSaPaFlowId;
+
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifGetSACtx: rxPaSaFlowId: 0x%x, rxSaPaFlowId: 0x%x\n", 
+            info.rxPaSaFlowId,
+            info.rxSaPaFlowId);
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "netapilib_ifGetSACtx: swInfo0: 0x%x, swInfo1: 0x%x, flowId: 0x%x\n",
+            hw_ctx->swinfo[0],
+            hw_ctx->swinfo[1],
+            hw_ctx->flow_id);
+
+   /* return success */
+    return 0;
+}
+
+
+
+
+
+
diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.h b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.h
new file mode 100755 (executable)
index 0000000..0a1744c
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef __FPLIB_INTERFACE_H__
+#define __FPLIB_INTERFACE_H__
+
+#include "ti/runtime/netapi/netapi.h"
+
+typedef struct {
+    int                 flowId;
+    PKTIO_HANDLE_T*     pktio_channel;
+    int                 qNum;
+} ipsecMgrMcb_t;
+
+
+int netapilib_ifAddSA
+(
+    ipsecmgr_af_t           af,
+    ipsecmgr_sa_id_t        *sa_id,
+    ipsecmgr_sa_info_t      *sa_info,
+    ipsecmgr_sa_dscp_map_cfg_t *dscp_map_cfg,
+    ipsecmgr_ifname_t       *if_name,
+    ipsecmgr_sa_encap_tmpl_t *encap,
+    ipsecmgr_fp_handle_t    *sa_handle
+);
+
+int netapilib_ifAddSP
+(
+    ipsecmgr_af_t           af,
+    ipsecmgr_selector_t     *sel,
+    ipsecmgr_dir_t          dir,
+    uint32_t                reqid,
+    ipsecmgr_fp_handle_t    sa_handle,
+    ipsecmgr_policy_id_t    policy_id,
+    ipsecmgr_fp_handle_t    *sp_handle
+);
+
+int netapilib_ifDeleteSP
+(
+    ipsecmgr_fp_handle_t   sp_handle,
+    ipsecmgr_policy_id_t   policy_id,
+    ipsecmgr_dir_t         dir
+);
+
+int netapilib_ifDeleteSA
+(
+    ipsecmgr_fp_handle_t   sa_handle
+);
+
+int netapilib_ifGetSACtx
+(
+    ipsecmgr_fp_handle_t    sa_handle,
+    ipsecmgr_sa_hw_ctx_t    *hw_ctx
+);
+
+#endif
+
index 7f911da9f0b6b0f2b3ed74b6e5c81c05fb62c8c3..522ace0dd35a15febe3980f81986b59252746508 100755 (executable)
@@ -82,6 +82,8 @@ install:
        $(CP) ./*.h                $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi
        @$(CP) -r $(ARMV7LIBDIR)/*.a         $(INSTALL_LIB_BASE_DIR)
        $(CP) src/*.h                $(INSTALL_INC_BASE_DIR)/ti/runtime/netapi/src
+
+installbin:
        install -d $(INSTALL_BIN_BASE_DIR)
        install -c -m 755 $(ARMV7BINDIR)/netapi/test/* $(INSTALL_BIN_BASE_DIR)
        install -d $(SYSCONFDIR)/netapi
@@ -92,7 +94,7 @@ install:
        install -c -m 755 tools/dsp_core_setup.sh           $(SYSCONFDIR)/netapi
 # Make rule to create tests
 tests:
-       -@echo compiling tests ..........!
+       -@echo compiling tests 
        @$(MAKE) -f ./test/build/Makefile $@
 
 examples:
index f59ace322d7a5a1b2980f44c546084430f72bd6a..f3c9c85fb588705912ca7aeba50f4a5955a83e74 100755 (executable)
@@ -200,6 +200,20 @@ typedef NETCP_CFG_ROUTE_T* NETCP_CFG_ROUTE_HANDLE_T;
  */
 typedef void * NETCP_CFG_VLAN_T;
 
+/**
+ * @ingroup cfg_constants
+ * @brief  NETCP PA LLD handle associated with an SA
+ * @details Application to use this handle to identify a PA PLLD handle associated with an SA.
+ */
+typedef void * NETCP_CFG_PA_HANDLE_T;
+
+/**
+ * @ingroup cfg_constants
+ * @brief  NETCP SA LLD handle associated with an SA
+ * @details Application to use this handle to identify a SA LLD handle associated with an SA.
+ */
+typedef void * NETCP_CFG_SA_HANDLE_T;
+
 /**
  * @ingroup cfg_constants
  * @brief  AppID for packets matching a  MAC interface rule
index bb710204e6eb6eafd36f278165ad9b79a7653fbf..7f8577f19299883c9e4ceb6a23bd92858c336665 100755 (executable)
@@ -6,10 +6,7 @@
 #ifndef __NETAPI_LOC__H
 #define __NETAPI_LOC__H
 
-
-//#include "ti/runtime/netapi/netapi.h"
 #include "ti/drv/nwal/nwal_util.h"
-#include "pktio.h"
 #include "ti/drv/nwal/nwal.h"
 #include "ti/drv/nwal/nwal_util.h"