Add cpmodem_shim
Change-Id: I469fe04efac7b6636f9d2d1a8ae93c6c1ac30dc1
diff --git a/cpmodem_shim/include/cpmodem_wrapper.h b/cpmodem_shim/include/cpmodem_wrapper.h
new file mode 100644
index 0000000..e3d6fb2
--- /dev/null
+++ b/cpmodem_shim/include/cpmodem_wrapper.h
@@ -0,0 +1,134 @@
+/*
+ * FILE NAME cpmodem_wrapper.h
+ *
+ * BRIEF MODULE DESCRIPTION
+ * Header file indicating API requirements for interfacing to custom wrapper module
+ *
+ * Author: CradlePoint Technology, Inc. <source@cradlepoint.com>
+ * Ben Kendall <benk@cradlepoint.com>
+ * Cory Atkin <catkin@cradlepoint.com>
+ *
+ * Copyright 2012-2021, CradlePoint Technology, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to:
+ * Free Software Foundation
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02111-1301 USA
+ */
+
+// OR'd mask bits for setting the log mask - these must match cpmodem_shim.h
+#define LOG_DEBUG_LEVEL_ERROR (1 << 0)
+#define LOG_DEBUG_LEVEL_WARN (1 << 1)
+#define LOG_DEBUG_LEVEL_INFO (1 << 2)
+#define LOG_DEBUG_LEVEL_TRACE (1 << 3)
+#define LOG_DEBUG_LEVEL_PRINTF (1 << 4)
+// LOG_DEBUG_LEVEL_ASSERT is always on
+
+
+//Traffic control for wrappers
+#define CP_LKM_WRAPPER_SRC_DATA 0x01 //data coming from the network
+#define CP_LKM_WRAPPER_SRC_CTRL 0x02 //data coming from the cpcommon stack
+#define CP_LKM_WRAPPER_DST_DATA 0x03 //data going to network stack
+#define CP_LKM_WRAPPER_DST_CTRL 0x04 //data going to cpcommon stack
+#define CP_LKM_WRAPPER_DST_FLOW_PAUSE 0x05 //pause tx traffic (i.e. SRC_DATA)
+#define CP_LKM_WRAPPER_DST_FLOW_RESUME 0x06 //resume tx traffic
+#define CP_LKM_WRAPPER_DST_UNKNOWN 0x07 //don't know what this is, drop it
+
+//results for wrappers
+#define CP_LKM_WRAPPER_RES_DONE 0x01 //Wrapper is done with success
+#define CP_LKM_WRAPPER_RES_AGAIN 0x02 //Wrapper needs to be called again to continue processing
+#define CP_LKM_WRAPPER_RES_ERROR 0x03 //Wrapper is done with an error
+
+//state of the usb device as a whole
+typedef enum{
+ CP_LKM_WRAPPER_INIT = 0, //ioctl created the object, but we haven't gotten the probe yet from USB
+ CP_LKM_WRAPPER_CTRL = 1, //got probe from usb, can now pass ctrl pkts between USB device and the app space driver
+ CP_LKM_WRAPPER_ACTIVE = 2, //ioctl told us the data connection is now active
+ CP_LKM_WRAPPER_INVALID = 0xff
+} cp_lkm_wrapper_state_t;
+
+//These must match the cp_lkm_wrapper_t enum in cpmodem_shim.h
+typedef enum
+{
+ CP_LKM_WRAPPER_TYPE_NONE = 0,
+ CP_LKM_WRAPPER_TYPE_ASIX,
+ CP_LKM_WRAPPER_TYPE_ASIX_88179,
+ CP_LKM_WRAPPER_TYPE_LG,
+ CP_LKM_WRAPPER_TYPE_DIRECT_IP,
+ CP_LKM_WRAPPER_TYPE_MSRNDIS,
+ CP_LKM_WRAPPER_TYPE_PEGASUS,
+ CP_LKM_WRAPPER_TYPE_NCM,
+ CP_LKM_WRAPPER_TYPE_QMAP, //New Qualcomm muxing and aggregation protocol
+ CP_LKM_WRAPPER_TYPE_NUM_WRAPPERS //NOTE: this one needs to always be last
+} cp_lkm_wrapper_type_t;
+
+
+/*
+ Alloc an opaque wrapper context
+ wrapper_info is wrapper specific data sent down from the app space driver. cp_lkm retains
+ ownership of the memory and frees it when the device unplugs, so the wrapper must copy any data it needs to hang onto.
+*/
+void* cp_lkm_wrapper_instance_alloc(cp_lkm_wrapper_type_t wrapper, void* wrapper_info, int len);
+void cp_lkm_wrapper_instance_free(void* ctxt);
+
+/*
+ * Apply the wrapper to a send pkt before sending to USB
+ * ctxt : wrapper ctxt from cp_lkm_wrapper_instance_alloc()
+ * src : CP_LKM_WRAPPER_SRC_DATA or CP_LKM_WRAPPER_SRC_CTRL
+ * skb_in : buffer with send data. This function takes ownership of skb_in and is responsible for freeing it when done.
+ * skb_out : pointer to skb to send to usb. If NULL, nothing to send, else send it. The calling function takes ownership
+ * of skb_out and is responsbil for freeing it.
+ * wrapper_state: CP_LKM_WRAPPER_ACTIVE if data connection is active, CP_LKM_WRAPPER_CTRL if no data connection. Some wrappers may
+ * need to wrap differently depending on the state
+ *
+ * return value: CP_LKM_WRAPPER_RES_DONE - Done processing skb_in. if skb_out is non NULL, send to usb.
+ * CP_LKM_WRAPPER_RES_AGAIN - Still processing skb_in. if skb_out is non NULL send to usb, call send again with
+ * skb_in set to NULL (since send took ownership on last call).
+ * CP_LKM_WRAPPER_RES_ERROR - There was an error with the buffer, update error pkt counts if needed.
+ * (send has taken ownership, and will free the skb).
+ *
+ */
+int cp_lkm_wrapper_send(void* ctxt, int src, int mux_id, struct sk_buff* skb_in, struct sk_buff** skb_out);
+
+/*
+ * Process the recv pkt before sending up to the app driver (ctrl) or to the network stack (data)
+ * ctxt : wrapper ctxt from cp_lkm_wrapper_instance_alloc()
+ * skb_in : buffer with recv data. This function takes ownership of skb_in and is responsible for freeing it when done.
+ * skb_out : pointer to skb to send to ctrl or data. If NULL, nothing to send. The calling function takes ownership
+ * of skb_out and is responsible for freeing it.
+ * wrapper_state: CP_LKM_WRAPPER_ACTIVE if data connection is active, CP_LKM_WRAPPER_CTRL if no data connection. Some wrappers may
+ * need to wrap differently depending on the state
+ *
+ * return value: The return value has the result and the destination OR'd into it.
+ * result:
+ * CP_LKM_WRAPPER_RES_DONE - Done processing skb_in. if skb_out is non NULL, send to destination.
+ * CP_LKM_WRAPPER_RES_AGAIN - Still processing skb_in. if skb_out is non NULL send to destination, then call send again with
+ * skb_in set to NULL (since send took ownership on last call) to get the next result and dest.
+ * CP_LKM_WRAPPER_RES_ERROR - There was an error with the buffer, update error pkt counts if needed.
+ * (send has taken ownership, and will free the skb).
+ * dest: CP_LKM_WRAPPER_DST_DATA - send to protocol stack
+ * CP_LKM_WRAPPER_DST_CTRL = send to app space driver
+ *
+*/
+int cp_lkm_wrapper_recv(void* ctxt, int* dst, int* mux_id, struct sk_buff* skb_in, struct sk_buff** skb_out);
+
+/*
+ * Let the wrapper know the state of the interface with unique identifier id
+ *
+*/
+#define CP_LKM_WRAPPER_DEFAULT_ID 0
+void cp_lkm_wrapper_set_state(void* ctxt, int id, cp_lkm_wrapper_state_t wrapper_state);
+
+void cp_lkm_wrapper_set_log_level(int level);
+int cp_lkm_wrapper_hdr_size(void* ctxt);
+