Kyle Swenson | 74ad753 | 2023-02-16 11:05:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * FILE NAME cpmodem_wrapper.h |
| 3 | * |
| 4 | * BRIEF MODULE DESCRIPTION |
| 5 | * Header file indicating API requirements for interfacing to custom wrapper module |
| 6 | * |
| 7 | * Author: CradlePoint Technology, Inc. <source@cradlepoint.com> |
| 8 | * Ben Kendall <benk@cradlepoint.com> |
| 9 | * Cory Atkin <catkin@cradlepoint.com> |
| 10 | * |
| 11 | * Copyright 2012-2021, CradlePoint Technology, Inc. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 |
| 15 | * as published by the Free Software Foundation. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to: |
| 24 | * Free Software Foundation |
| 25 | * 51 Franklin Street, Fifth Floor |
| 26 | * Boston, MA 02111-1301 USA |
| 27 | */ |
| 28 | |
| 29 | // OR'd mask bits for setting the log mask - these must match cpmodem_shim.h |
| 30 | #define LOG_DEBUG_LEVEL_ERROR (1 << 0) |
| 31 | #define LOG_DEBUG_LEVEL_WARN (1 << 1) |
| 32 | #define LOG_DEBUG_LEVEL_INFO (1 << 2) |
| 33 | #define LOG_DEBUG_LEVEL_TRACE (1 << 3) |
| 34 | #define LOG_DEBUG_LEVEL_PRINTF (1 << 4) |
| 35 | // LOG_DEBUG_LEVEL_ASSERT is always on |
| 36 | |
| 37 | |
| 38 | //Traffic control for wrappers |
| 39 | #define CP_LKM_WRAPPER_SRC_DATA 0x01 //data coming from the network |
| 40 | #define CP_LKM_WRAPPER_SRC_CTRL 0x02 //data coming from the cpcommon stack |
| 41 | #define CP_LKM_WRAPPER_DST_DATA 0x03 //data going to network stack |
| 42 | #define CP_LKM_WRAPPER_DST_CTRL 0x04 //data going to cpcommon stack |
| 43 | #define CP_LKM_WRAPPER_DST_FLOW_PAUSE 0x05 //pause tx traffic (i.e. SRC_DATA) |
| 44 | #define CP_LKM_WRAPPER_DST_FLOW_RESUME 0x06 //resume tx traffic |
| 45 | #define CP_LKM_WRAPPER_DST_UNKNOWN 0x07 //don't know what this is, drop it |
| 46 | |
| 47 | //results for wrappers |
| 48 | #define CP_LKM_WRAPPER_RES_DONE 0x01 //Wrapper is done with success |
| 49 | #define CP_LKM_WRAPPER_RES_AGAIN 0x02 //Wrapper needs to be called again to continue processing |
| 50 | #define CP_LKM_WRAPPER_RES_ERROR 0x03 //Wrapper is done with an error |
| 51 | |
| 52 | //state of the usb device as a whole |
| 53 | typedef enum{ |
| 54 | CP_LKM_WRAPPER_INIT = 0, //ioctl created the object, but we haven't gotten the probe yet from USB |
| 55 | CP_LKM_WRAPPER_CTRL = 1, //got probe from usb, can now pass ctrl pkts between USB device and the app space driver |
| 56 | CP_LKM_WRAPPER_ACTIVE = 2, //ioctl told us the data connection is now active |
| 57 | CP_LKM_WRAPPER_INVALID = 0xff |
| 58 | } cp_lkm_wrapper_state_t; |
| 59 | |
| 60 | //These must match the cp_lkm_wrapper_t enum in cpmodem_shim.h |
| 61 | typedef enum |
| 62 | { |
| 63 | CP_LKM_WRAPPER_TYPE_NONE = 0, |
| 64 | CP_LKM_WRAPPER_TYPE_ASIX, |
| 65 | CP_LKM_WRAPPER_TYPE_ASIX_88179, |
| 66 | CP_LKM_WRAPPER_TYPE_LG, |
| 67 | CP_LKM_WRAPPER_TYPE_DIRECT_IP, |
| 68 | CP_LKM_WRAPPER_TYPE_MSRNDIS, |
| 69 | CP_LKM_WRAPPER_TYPE_PEGASUS, |
| 70 | CP_LKM_WRAPPER_TYPE_NCM, |
| 71 | CP_LKM_WRAPPER_TYPE_QMAP, //New Qualcomm muxing and aggregation protocol |
| 72 | CP_LKM_WRAPPER_TYPE_NUM_WRAPPERS //NOTE: this one needs to always be last |
| 73 | } cp_lkm_wrapper_type_t; |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | Alloc an opaque wrapper context |
| 78 | wrapper_info is wrapper specific data sent down from the app space driver. cp_lkm retains |
| 79 | ownership of the memory and frees it when the device unplugs, so the wrapper must copy any data it needs to hang onto. |
| 80 | */ |
| 81 | void* cp_lkm_wrapper_instance_alloc(cp_lkm_wrapper_type_t wrapper, void* wrapper_info, int len); |
| 82 | void cp_lkm_wrapper_instance_free(void* ctxt); |
| 83 | |
| 84 | /* |
| 85 | * Apply the wrapper to a send pkt before sending to USB |
| 86 | * ctxt : wrapper ctxt from cp_lkm_wrapper_instance_alloc() |
| 87 | * src : CP_LKM_WRAPPER_SRC_DATA or CP_LKM_WRAPPER_SRC_CTRL |
| 88 | * skb_in : buffer with send data. This function takes ownership of skb_in and is responsible for freeing it when done. |
| 89 | * skb_out : pointer to skb to send to usb. If NULL, nothing to send, else send it. The calling function takes ownership |
| 90 | * of skb_out and is responsbil for freeing it. |
| 91 | * wrapper_state: CP_LKM_WRAPPER_ACTIVE if data connection is active, CP_LKM_WRAPPER_CTRL if no data connection. Some wrappers may |
| 92 | * need to wrap differently depending on the state |
| 93 | * |
| 94 | * return value: CP_LKM_WRAPPER_RES_DONE - Done processing skb_in. if skb_out is non NULL, send to usb. |
| 95 | * CP_LKM_WRAPPER_RES_AGAIN - Still processing skb_in. if skb_out is non NULL send to usb, call send again with |
| 96 | * skb_in set to NULL (since send took ownership on last call). |
| 97 | * CP_LKM_WRAPPER_RES_ERROR - There was an error with the buffer, update error pkt counts if needed. |
| 98 | * (send has taken ownership, and will free the skb). |
| 99 | * |
| 100 | */ |
| 101 | int cp_lkm_wrapper_send(void* ctxt, int src, int mux_id, struct sk_buff* skb_in, struct sk_buff** skb_out); |
| 102 | |
| 103 | /* |
| 104 | * Process the recv pkt before sending up to the app driver (ctrl) or to the network stack (data) |
| 105 | * ctxt : wrapper ctxt from cp_lkm_wrapper_instance_alloc() |
| 106 | * skb_in : buffer with recv data. This function takes ownership of skb_in and is responsible for freeing it when done. |
| 107 | * skb_out : pointer to skb to send to ctrl or data. If NULL, nothing to send. The calling function takes ownership |
| 108 | * of skb_out and is responsible for freeing it. |
| 109 | * wrapper_state: CP_LKM_WRAPPER_ACTIVE if data connection is active, CP_LKM_WRAPPER_CTRL if no data connection. Some wrappers may |
| 110 | * need to wrap differently depending on the state |
| 111 | * |
| 112 | * return value: The return value has the result and the destination OR'd into it. |
| 113 | * result: |
| 114 | * CP_LKM_WRAPPER_RES_DONE - Done processing skb_in. if skb_out is non NULL, send to destination. |
| 115 | * CP_LKM_WRAPPER_RES_AGAIN - Still processing skb_in. if skb_out is non NULL send to destination, then call send again with |
| 116 | * skb_in set to NULL (since send took ownership on last call) to get the next result and dest. |
| 117 | * CP_LKM_WRAPPER_RES_ERROR - There was an error with the buffer, update error pkt counts if needed. |
| 118 | * (send has taken ownership, and will free the skb). |
| 119 | * dest: CP_LKM_WRAPPER_DST_DATA - send to protocol stack |
| 120 | * CP_LKM_WRAPPER_DST_CTRL = send to app space driver |
| 121 | * |
| 122 | */ |
| 123 | int cp_lkm_wrapper_recv(void* ctxt, int* dst, int* mux_id, struct sk_buff* skb_in, struct sk_buff** skb_out); |
| 124 | |
| 125 | /* |
| 126 | * Let the wrapper know the state of the interface with unique identifier id |
| 127 | * |
| 128 | */ |
| 129 | #define CP_LKM_WRAPPER_DEFAULT_ID 0 |
| 130 | void cp_lkm_wrapper_set_state(void* ctxt, int id, cp_lkm_wrapper_state_t wrapper_state); |
| 131 | |
| 132 | void cp_lkm_wrapper_set_log_level(int level); |
| 133 | int cp_lkm_wrapper_hdr_size(void* ctxt); |
| 134 | |