Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 1 | /* |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 6 | * above copyright notice and this permission notice appear in all copies. |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 14 | ************************************************************************** |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 15 | */ |
| 16 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 17 | #include "nss_tx_rx_common.h" |
Sachin Shashidhar | 4529cea | 2018-08-13 16:58:32 -0700 | [diff] [blame] | 18 | #include "nss_tunipip6_log.h" |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 19 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 20 | /* |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 21 | * nss_tunipip6_verify_if_num |
| 22 | * Verify the interface is a valid interface |
| 23 | */ |
| 24 | static bool nss_tunipip6_verify_if_num(uint32_t if_num) |
| 25 | { |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 26 | enum nss_dynamic_interface_type type; |
| 27 | |
| 28 | type = nss_dynamic_interface_get_type(nss_tunipip6_get_context(), if_num); |
| 29 | |
| 30 | switch (type) { |
| 31 | case NSS_DYNAMIC_INTERFACE_TYPE_TUNIPIP6_INNER: |
| 32 | case NSS_DYNAMIC_INTERFACE_TYPE_TUNIPIP6_OUTER: |
| 33 | return true; |
| 34 | default: |
| 35 | return false; |
| 36 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 40 | * nss_tunipip6_handler() |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 41 | * Handle NSS -> HLOS messages for ipip6 tunnel |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 42 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 43 | static void nss_tunipip6_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 44 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 45 | struct nss_tunipip6_msg *ntm = (struct nss_tunipip6_msg *)ncm; |
| 46 | void *ctx; |
| 47 | nss_tunipip6_msg_callback_t cb; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 48 | |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 49 | BUG_ON(!nss_tunipip6_verify_if_num(ncm->interface)); |
| 50 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 51 | /* |
Sachin Shashidhar | 4529cea | 2018-08-13 16:58:32 -0700 | [diff] [blame] | 52 | * Trace Messages |
| 53 | */ |
| 54 | nss_tunipip6_log_rx_msg(ntm); |
| 55 | |
| 56 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 57 | * Is this a valid request/response packet? |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 58 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 59 | if (ncm->type >= NSS_TUNIPIP6_MAX) { |
| 60 | nss_warning("%p: received invalid message %d for DS-Lite interface", nss_ctx, ncm->type); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 64 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tunipip6_msg)) { |
| 65 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 66 | return; |
| 67 | } |
| 68 | |
| 69 | /* |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 70 | * Update the callback and app_data for NOTIFY messages, tunipip6 sends all notify messages |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 71 | * to the same callback/app_data. |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 72 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 73 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 74 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->tunipip6_msg_callback; |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Log failures |
| 79 | */ |
| 80 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 81 | |
| 82 | /* |
| 83 | * Do we have a call back |
| 84 | */ |
| 85 | if (!ncm->cb) { |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | |
| 89 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 90 | * callback |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 91 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 92 | cb = (nss_tunipip6_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 93 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 94 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 95 | /* |
| 96 | * call ipip6 tunnel callback |
| 97 | */ |
| 98 | if (!ctx) { |
| 99 | nss_warning("%p: Event received for DS-Lite tunnel interface %d before registration", nss_ctx, ncm->interface); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 100 | return; |
| 101 | } |
| 102 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 103 | cb(ctx, ntm); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 107 | * nss_tunipip6_tx() |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 108 | * Transmit a tunipip6 message to NSSFW |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 109 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 110 | nss_tx_status_t nss_tunipip6_tx(struct nss_ctx_instance *nss_ctx, struct nss_tunipip6_msg *msg) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 111 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 112 | struct nss_cmn_msg *ncm = &msg->cm; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 113 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 114 | /* |
Sachin Shashidhar | 4529cea | 2018-08-13 16:58:32 -0700 | [diff] [blame] | 115 | * Trace Messages |
| 116 | */ |
| 117 | nss_tunipip6_log_tx_msg(msg); |
| 118 | |
| 119 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 120 | * Sanity check the message |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 121 | */ |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 122 | if (!nss_tunipip6_verify_if_num(ncm->interface)) { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 123 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 124 | return NSS_TX_FAILURE; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 125 | } |
| 126 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 127 | if (ncm->type > NSS_TUNIPIP6_MAX) { |
| 128 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 129 | return NSS_TX_FAILURE; |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 130 | } |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 131 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 132 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 133 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 134 | EXPORT_SYMBOL(nss_tunipip6_tx); |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 135 | |
| 136 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 137 | * ********************************** |
| 138 | * Register/Unregister/Miscellaneous APIs |
| 139 | * ********************************** |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 140 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * nss_register_tunipip6_if() |
| 144 | */ |
| 145 | struct nss_ctx_instance *nss_register_tunipip6_if(uint32_t if_num, |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 146 | uint32_t dynamic_interface_type, |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 147 | nss_tunipip6_callback_t tunipip6_callback, |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 148 | nss_tunipip6_msg_callback_t event_callback, |
| 149 | struct net_device *netdev, |
| 150 | uint32_t features) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 151 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 152 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 153 | |
| 154 | nss_assert(nss_ctx); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 155 | nss_assert(nss_tunipip6_verify_if_num(if_num)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 156 | |
Apoorv Gupta | 09c387f | 2018-08-02 09:36:15 +0530 | [diff] [blame] | 157 | nss_ctx->subsys_dp_register[if_num].type = dynamic_interface_type; |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 158 | nss_top_main.tunipip6_msg_callback = event_callback; |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 159 | nss_core_register_subsys_dp(nss_ctx, if_num, tunipip6_callback, NULL, NULL, netdev, features); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 160 | nss_core_register_handler(nss_ctx, if_num, nss_tunipip6_handler, NULL); |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 161 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 162 | return nss_ctx; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 163 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 164 | EXPORT_SYMBOL(nss_register_tunipip6_if); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 165 | |
| 166 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 167 | * nss_unregister_tunipip6_if() |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 168 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 169 | void nss_unregister_tunipip6_if(uint32_t if_num) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 170 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 171 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 172 | |
| 173 | nss_assert(nss_ctx); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 174 | nss_assert(nss_tunipip6_verify_if_num(if_num)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 175 | |
Ken Zhu | 917fd23 | 2018-12-04 17:41:47 -0800 | [diff] [blame^] | 176 | nss_core_unregister_handler(nss_ctx, if_num); |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 177 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
| 178 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 179 | nss_top_main.tunipip6_msg_callback = NULL; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 180 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 181 | EXPORT_SYMBOL(nss_unregister_tunipip6_if); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 182 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 183 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 184 | * nss_tunipip6_get_context() |
| 185 | */ |
| 186 | struct nss_ctx_instance *nss_tunipip6_get_context(void) |
| 187 | { |
| 188 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 189 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 190 | EXPORT_SYMBOL(nss_tunipip6_get_context); |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 191 | |
| 192 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 193 | * nss_tunipip6_register_handler() |
| 194 | */ |
| 195 | void nss_tunipip6_register_handler() |
| 196 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 197 | struct nss_ctx_instance *nss_ctx = nss_tunipip6_get_context(); |
| 198 | |
| 199 | nss_core_register_handler(nss_ctx, NSS_TUNIPIP6_INTERFACE, nss_tunipip6_handler, NULL); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 200 | } |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 201 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 202 | /* |
| 203 | * nss_tunipip6_msg_init() |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 204 | * Initialize nss_tunipip6 msg. |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 205 | */ |
| 206 | void nss_tunipip6_msg_init(struct nss_tunipip6_msg *ntm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 207 | { |
| 208 | nss_cmn_msg_init(&ntm->cm, if_num, type, len, cb, app_data); |
| 209 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 210 | EXPORT_SYMBOL(nss_tunipip6_msg_init); |