Harout Hedeshian | b2fc5b1 | 2013-09-03 13:49:00 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | |
| 3 | L I B R M N E T C T L . H |
| 4 | |
| 5 | Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 6 | |
| 7 | Redistribution and use in source and binary forms, with or without |
| 8 | modification, are permitted provided that the following conditions are |
| 9 | met: |
| 10 | * Redistributions of source code must retain the above copyright |
| 11 | notice, this list of conditions and the following disclaimer. |
| 12 | * Redistributions in binary form must reproduce the above |
| 13 | copyright notice, this list of conditions and the following |
| 14 | disclaimer in the documentation and/or other materials provided |
| 15 | with the distribution. |
| 16 | * Neither the name of The Linux Foundation nor the names of its |
| 17 | contributors may be used to endorse or promote products derived |
| 18 | from this software without specific prior written permission. |
| 19 | |
| 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 29 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | ******************************************************************************/ |
| 33 | |
| 34 | /*! |
| 35 | * @file librmnetctl.h |
| 36 | * @brief rmnet control API's header file |
| 37 | */ |
| 38 | |
| 39 | #ifndef LIBRMNETCTL_H |
| 40 | #define LIBRMNETCTL_H |
| 41 | |
| 42 | /* RMNET API succeeded */ |
| 43 | #define RMNETCTL_SUCCESS 0 |
| 44 | /* RMNET API encountered an error while executing within the library. Check the |
| 45 | * error code in this case */ |
| 46 | #define RMNETCTL_LIB_ERR 1 |
| 47 | /* RMNET API encountered an error while executing in the kernel. Check the |
| 48 | * error code in this case */ |
| 49 | #define RMNETCTL_KERNEL_ERR 2 |
| 50 | /* RMNET API encountered an error because of invalid arguments*/ |
| 51 | #define RMNETCTL_INVALID_ARG 3 |
| 52 | |
| 53 | /* Flag to associate a network device*/ |
| 54 | #define RMNETCTL_DEVICE_ASSOCIATE 1 |
| 55 | /* Flag to unassociate a network device*/ |
| 56 | #define RMNETCTL_DEVICE_UNASSOCIATE 0 |
| 57 | /* Flag to create a new virtual network device*/ |
| 58 | #define RMNETCTL_NEW_VND 1 |
| 59 | /* Flag to free a new virtual network device*/ |
| 60 | #define RMNETCTL_FREE_VND 0 |
| 61 | |
| 62 | enum rmnetctl_error_codes_e { |
| 63 | /* API succeeded. This should always be the first element. */ |
| 64 | RMNETCTL_API_SUCCESS, |
| 65 | /* API failed because not enough memory to create buffer to send |
| 66 | * message */ |
| 67 | RMNETCTL_API_ERR_REQUEST_INVALID, |
| 68 | /* API failed because not enough memory to create buffer for the |
| 69 | * response message */ |
| 70 | RMNETCTL_API_ERR_RESPONSE_INVALID, |
| 71 | /* API failed because could not send the message to kernel */ |
| 72 | RMNETCTL_API_ERR_MESSAGE_SEND, |
| 73 | /* API failed because could not receive message from the kernel */ |
| 74 | RMNETCTL_API_ERR_MESSAGE_RECEIVE, |
| 75 | /* Invalid process id. So return an error. */ |
| 76 | RMNETCTL_INIT_ERR_PROCESS_ID, |
| 77 | /* Invalid socket descriptor id. So return an error. */ |
| 78 | RMNETCTL_INIT_ERR_NETLINK_FD, |
| 79 | /* Could not bind the socket to the Netlink file descriptor */ |
| 80 | RMNETCTL_INIT_ERR_BIND, |
| 81 | /* Invalid user id. Only root has access to this function. (NA) */ |
| 82 | RMNETCTL_INIT_ERR_INVALID_USER, |
| 83 | /* API failed because the RmNet handle for the transaction was NULL */ |
| 84 | RMNETCTL_API_ERR_HNDL_INVALID, |
| 85 | /* API failed because the request buffer for the transaction was NULL */ |
| 86 | RMNETCTL_API_ERR_REQUEST_NULL, |
| 87 | /* API failed because the response buffer for the transaction was NULL*/ |
| 88 | RMNETCTL_API_ERR_RESPONSE_NULL, |
| 89 | /* API failed because the request and response type do not match*/ |
| 90 | RMNETCTL_API_ERR_MESSAGE_TYPE, |
| 91 | /* API failed because the return type is invalid */ |
| 92 | RMNETCTL_API_ERR_RETURN_TYPE, |
| 93 | /* API failed because the string was truncated */ |
| 94 | RMNETCTL_API_ERR_STRING_TRUNCATION, |
| 95 | /* This should always be the last element */ |
| 96 | RMNETCTL_API_ERR_ENUM_LENGTH |
| 97 | }; |
| 98 | |
| 99 | #define RMNETCTL_ERR_MSG_SIZE 100 |
| 100 | |
| 101 | /*! |
| 102 | * @brief Contains a list of error message from API |
| 103 | */ |
| 104 | char rmnetctl_error_code_text |
| 105 | [RMNETCTL_API_ERR_ENUM_LENGTH][RMNETCTL_ERR_MSG_SIZE] = { |
| 106 | "ERROR: API succeeded\n", |
| 107 | "ERROR: Unable to allocate the buffer to send message\n", |
| 108 | "ERROR: Unable to allocate the buffer to receive message\n", |
| 109 | "ERROR: Could not send the message to kernel\n", |
| 110 | "ERROR: Unable to receive message from the kernel\n", |
| 111 | "ERROR: Invalid process id\n", |
| 112 | "ERROR: Invalid socket descriptor id\n", |
| 113 | "ERROR: Could not bind to netlink socket\n", |
| 114 | "ERROR: Only root can access this API\n", |
| 115 | "ERROR: RmNet handle for the transaction was NULL\n", |
| 116 | "ERROR: Request buffer for the transaction was NULL\n", |
| 117 | "ERROR: Response buffer for the transaction was NULL\n", |
| 118 | "ERROR: Request and response type do not match\n", |
| 119 | "ERROR: Return type is invalid\n", |
| 120 | "ERROR: String was truncated\n" |
| 121 | }; |
| 122 | |
| 123 | /*=========================================================================== |
| 124 | DEFINITIONS AND DECLARATIONS |
| 125 | ===========================================================================*/ |
| 126 | typedef struct rmnetctl_hndl_s rmnetctl_hndl_t; |
| 127 | |
| 128 | /*! |
| 129 | * @brief Public API to initialize the RMNET control driver |
| 130 | * @details Allocates memory for the RmNet handle. Creates and binds to a and |
| 131 | * netlink socket if successful |
| 132 | * @param **rmnetctl_hndl_t_val RmNet handle to be initialized |
| 133 | * @return RMNETCTL_SUCCESS if successful |
| 134 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 135 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 136 | * Check error_code |
| 137 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 138 | */ |
| 139 | int rmnetctl_init(rmnetctl_hndl_t **hndl, uint16_t *error_code); |
| 140 | |
| 141 | /*! |
| 142 | * @brief Public API to clean up the RmNeT control handle |
| 143 | * @details Close the socket and free the RmNet handle |
| 144 | * @param *rmnetctl_hndl_t_val RmNet handle to be initialized |
| 145 | * @return void |
| 146 | */ |
| 147 | void rmnetctl_cleanup(rmnetctl_hndl_t *hndl); |
| 148 | |
| 149 | /*! |
| 150 | * @brief Public API to register/unregister a RMNET driver on a particular device |
| 151 | * @details Message type is RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE or |
| 152 | * RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE based on the flag for assoc_dev |
| 153 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 154 | * @param dev_name Device on which to register the RmNet driver |
| 155 | * @param error_code Status code of this operation |
| 156 | * @param assoc_dev registers the device if RMNETCTL_DEVICE_ASSOCIATE or |
| 157 | * unregisters the device if RMNETCTL_DEVICE_UNASSOCIATE |
| 158 | * @return RMNETCTL_SUCCESS if successful |
| 159 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 160 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 161 | * Check error_code |
| 162 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 163 | */ |
| 164 | int rmnet_associate_network_device(rmnetctl_hndl_t *hndl, |
| 165 | const char *dev_name, |
| 166 | uint16_t *error_code, |
| 167 | uint8_t assoc_dev); |
| 168 | |
| 169 | /*! |
| 170 | * @brief Public API to get if a RMNET driver is registered on a particular |
| 171 | * device |
| 172 | * @details Message type is RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED. |
| 173 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 174 | * @param dev_name Device on which to check if the RmNet driver is registered |
| 175 | * @param register_status 1 if RmNet data driver is registered on a particular |
| 176 | * device, 0 if not |
| 177 | * @param error_code Status code of this operation |
| 178 | * @return RMNETCTL_SUCCESS if successful |
| 179 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 180 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 181 | * Check error_code |
| 182 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 183 | */ |
| 184 | int rmnet_get_network_device_associated(rmnetctl_hndl_t *hndl, |
| 185 | const char *dev_name, |
| 186 | int *register_status, |
| 187 | uint16_t *error_code); |
| 188 | |
| 189 | /*! |
| 190 | * @brief Public API to set the egress data format for a particular link. |
| 191 | * @details Message type is RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT. |
| 192 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 193 | * @param egress_flags Egress flags to be set on the device |
| 194 | * @param agg_size Max size of aggregated packets |
| 195 | * @param agg_count Number of packets to be aggregated |
| 196 | * @param dev_name Device on which to set the egress data format |
| 197 | * @param error_code Status code of this operation returned from the kernel |
| 198 | * @return RMNETCTL_SUCCESS if successful |
| 199 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 200 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 201 | * Check error_code |
| 202 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 203 | */ |
| 204 | int rmnet_set_link_egress_data_format(rmnetctl_hndl_t *hndl, |
| 205 | uint32_t egress_flags, |
| 206 | uint16_t agg_size, |
| 207 | uint16_t agg_count, |
| 208 | const char *dev_name, |
| 209 | uint16_t *error_code); |
| 210 | |
| 211 | /*! |
| 212 | * @brief Public API to get the egress data format for a particular link. |
| 213 | * @details Message type is RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT. |
| 214 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 215 | * @param dev_name Device on which to get the egress data format |
| 216 | * @param egress_flags Egress flags from the device |
| 217 | * @param agg_count Number of packets to be aggregated |
| 218 | * @param error_code Status code of this operation returned from the kernel |
| 219 | * @return RMNETCTL_SUCCESS if successful |
| 220 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 221 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 222 | * Check error_code |
| 223 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 224 | */ |
| 225 | int rmnet_get_link_egress_data_format(rmnetctl_hndl_t *hndl, |
| 226 | const char *dev_name, |
| 227 | uint32_t *egress_flags, |
| 228 | uint16_t *agg_size, |
| 229 | uint16_t *agg_count, |
| 230 | uint16_t *error_code); |
| 231 | |
| 232 | /*! |
| 233 | * @brief Public API to set the ingress data format for a particular link. |
| 234 | * @details Message type is RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT. |
| 235 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 236 | * @param ingress_flags Ingress flags from the device |
| 237 | * @param dev_name Device on which to set the ingress data format |
| 238 | * @param error_code Status code of this operation returned from the kernel |
| 239 | * @return RMNETCTL_SUCCESS if successful |
| 240 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 241 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 242 | * Check error_code |
| 243 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 244 | */ |
| 245 | int rmnet_set_link_ingress_data_format(rmnetctl_hndl_t *hndl, |
| 246 | uint32_t ingress_flags, |
| 247 | const char *dev_name, |
| 248 | uint16_t *error_code); |
| 249 | |
| 250 | /*! |
| 251 | * @brief Public API to get the ingress data format for a particular link. |
| 252 | * @details Message type is RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT. |
| 253 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 254 | * @param dev_name Device on which to get the ingress data format |
| 255 | * @param ingress_flags Ingress flags from the device |
| 256 | * @param error_code Status code of this operation returned from the kernel |
| 257 | * @return RMNETCTL_SUCCESS if successful |
| 258 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 259 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 260 | * Check error_code |
| 261 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 262 | */ |
| 263 | int rmnet_get_link_ingress_data_format(rmnetctl_hndl_t *hndl, |
| 264 | const char *dev_name, |
| 265 | uint32_t *ingress_flags, |
| 266 | uint16_t *error_code); |
| 267 | |
| 268 | /*! |
| 269 | * @brief Public API to set the logical endpoint configuration for a |
| 270 | * particular link. |
| 271 | * @details Message type is RMNET_NETLINK_SET_LOGICAL_EP_CONFIG. |
| 272 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 273 | * @param logical_ep_id Logical end point id on which the configuration is to be |
| 274 | * set |
| 275 | * @param rmnet_mode RmNet mode to be set on the device |
| 276 | * @param dev_name Device on which to set the logical end point configuration |
| 277 | * @param egress_dev_name Egress Device if operating in bridge mode |
| 278 | * @param error_code Status code of this operation returned from the kernel |
| 279 | * @return RMNETCTL_SUCCESS if successful |
| 280 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 281 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 282 | * Check error_code |
| 283 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 284 | */ |
| 285 | int rmnet_set_logical_ep_config(rmnetctl_hndl_t *hndl, |
| 286 | int32_t ep_id, |
| 287 | uint8_t operating_mode, |
| 288 | const char *dev_name, |
| 289 | const char *next_dev, |
| 290 | uint16_t *error_code); |
| 291 | |
| 292 | /*! |
| 293 | * @brief Public API to get the logical endpoint configuration for a |
| 294 | * particular link. |
| 295 | * @details Message type is RMNET_NETLINK_GET_LOGICAL_EP_CONFIG. |
| 296 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 297 | * @param logical_ep_id Logical end point id from which to get the configuration |
| 298 | * @param dev_name Device on which to get the logical end point configuration |
| 299 | * @param rmnet_mode RmNet mode from the device |
| 300 | * @param egress_dev_name Egress Device if operating in bridge mode |
| 301 | * @param error_code Status code of this operation returned from the kernel |
| 302 | * @return RMNETCTL_SUCCESS if successful |
| 303 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 304 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 305 | * Check error_code |
| 306 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 307 | */ |
| 308 | int rmnet_get_logical_ep_config(rmnetctl_hndl_t *hndl, |
| 309 | int32_t ep_id, |
| 310 | const char *dev_name, |
| 311 | uint8_t *operating_mode, |
| 312 | char **next_dev, |
| 313 | uint16_t *error_code); |
| 314 | |
| 315 | /*! |
| 316 | * @brief Public API to create a new virtual device node |
| 317 | * @details Message type is RMNET_NETLINK_NEW_VND or |
| 318 | * RMNETCTL_FREE_VND based on the flag for new_vnd |
| 319 | * @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message |
| 320 | * @param node_number Node number to create the virtual network device node |
| 321 | * @param error_code Status code of this operation returned from the kernel |
| 322 | * @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or |
| 323 | * frees the device if RMNETCTL_FREE_VND |
| 324 | * @return RMNETCTL_SUCCESS if successful |
| 325 | * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code |
| 326 | * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel. |
| 327 | * Check error_code |
| 328 | * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API |
| 329 | */ |
| 330 | int rmnet_new_vnd(rmnetctl_hndl_t *hndl, |
| 331 | uint32_t id, |
| 332 | uint16_t *error_code, |
| 333 | uint8_t new_vnd); |
| 334 | |
| 335 | #endif /* not defined LIBRMNETCTL_H */ |
| 336 | |