Conditionally revert "rmnetctl: Remove rmnet_data.h header include"

Retain the old driver support for everything prior to kalama platform.

This conditionally reverts commit 574e0f6071.

Change-Id: I3dba52edffd7cccbef29f3620e1f742905c468e7
This commit is contained in:
Bruno Martins
2023-07-27 17:45:32 +01:00
committed by Michael Bestas
parent 1159d11d69
commit dfc2ec0112
4 changed files with 1360 additions and 1 deletions

View File

@@ -1,16 +1,33 @@
soong_config_module_type {
name: "rmnetctl_cc_defaults",
module_type: "cc_defaults",
config_namespace: "rmnetctl",
bool_variables: [
"old_rmnet_data",
],
properties: [
"cflags",
],
}
cc_library_headers {
name: "librmnetctl_headers",
export_include_dirs: ["inc"],
vendor: true,
}
cc_defaults {
rmnetctl_cc_defaults {
name: "librmnetctl_defaults",
cflags: [
"-Wall",
"-Werror",
],
header_libs: ["librmnetctl_headers"],
soong_config_variables: {
old_rmnet_data: {
cflags: ["-DUSE_OLD_RMNET_DATA"],
},
},
vendor: true,
}

View File

@@ -58,11 +58,19 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define RMNET_MAX_STR_LEN 16
#ifdef USE_OLD_RMNET_DATA
#define _RMNETCLI_CHECKNULL(X) do { if (!X) { \
print_rmnet_api_status(RMNETCTL_INVALID_ARG, RMNETCTL_CFG_FAILURE_NO_COMMAND); \
rmnetctl_cleanup(handle); \
return RMNETCTL_INVALID_ARG; \
} } while (0);
#else
#define _RMNETCLI_CHECKNULL(X) do { if (!X) { \
print_rmnet_api_status(RMNETCTL_INVALID_ARG, RMNETCTL_CFG_FAILURE_NO_COMMAND); \
rtrmnet_ctl_deinit(handle); \
return RMNETCTL_INVALID_ARG; \
} } while (0);
#endif
#define _STRTOUI32(X) (uint32_t)strtoul(X, NULL, 0)
#define _STRTOUI16(X) (uint16_t)strtoul(X, NULL, 0)
#define _STRTOUI8(X) (uint8_t)strtoul(X, NULL, 0)
@@ -246,6 +254,9 @@ static int rmnet_api_call(int argc, char *argv[])
struct rmnetctl_hndl_s *handle = NULL;
uint16_t error_number = RMNETCTL_CFG_FAILURE_NO_COMMAND;
int return_code = RMNETCTL_LIB_ERR;
#ifdef USE_OLD_RMNET_DATA
int is_new_api = 0;
#endif
if ((!argc) || (!*argv)) {
print_rmnet_api_status(RMNETCTL_LIB_ERR,
@@ -259,6 +270,9 @@ static int rmnet_api_call(int argc, char *argv[])
}
if (!strcmp(*argv, "-n")) {
#ifdef USE_OLD_RMNET_DATA
is_new_api = 1;
#endif
return_code = rtrmnet_ctl_init(&handle, &error_number);
if (return_code != RMNETCTL_SUCCESS) {
print_rmnet_api_status(return_code, error_number);
@@ -454,7 +468,11 @@ static int rmnet_api_call(int argc, char *argv[])
if (!bearers) {
print_rmnet_api_status(RMNETCTL_INVALID_ARG,
RMNETCTL_CFG_FAILURE_NO_COMMAND);
#ifdef USE_OLD_RMNET_DATA
rmnetctl_cleanup(handle);
#else
rtrmnet_ctl_deinit(handle);
#endif
return RMNETCTL_INVALID_ARG;
}
@@ -480,11 +498,147 @@ static int rmnet_api_call(int argc, char *argv[])
goto end;
#ifdef USE_OLD_RMNET_DATA
} else {
return_code = rmnetctl_init(&handle, &error_number);
if (return_code != RMNETCTL_SUCCESS) {
print_rmnet_api_status(return_code, error_number);
return RMNETCTL_LIB_ERR;
}
}
error_number = RMNETCTL_CFG_FAILURE_NO_COMMAND;
return_code = RMNETCTL_LIB_ERR;
if (!strcmp(*argv, "assocnetdev")) {
return_code = rmnet_associate_network_device(handle,
argv[1], &error_number, RMNETCTL_DEVICE_ASSOCIATE);
} else if (!strcmp(*argv, "unassocnetdev")) {
return_code = rmnet_associate_network_device(handle,
argv[1], &error_number, RMNETCTL_DEVICE_UNASSOCIATE);
} else if (!strcmp(*argv, "getnetdevassoc")) {
int register_status;
return_code = rmnet_get_network_device_associated(handle,
argv[1], &register_status, &error_number);
if (return_code == RMNETCTL_SUCCESS)
printf("register_status is %d\n", register_status);
} else if (!strcmp(*argv, "getledf")) {
uint32_t egress_flags;
uint16_t agg_size, agg_count;
return_code = rmnet_get_link_egress_data_format(handle,
argv[1], &egress_flags, &agg_size, &agg_count, &error_number);
if (return_code == RMNETCTL_SUCCESS) {
printf("egress_flags is %u\n", egress_flags);
printf("agg_size is %u\n", agg_size);
printf("agg_count is %u\n", agg_count);
}
} else if (!strcmp(*argv, "getlidf")) {
uint32_t ingress_flags;
uint8_t tail_spacing;
return_code = rmnet_get_link_ingress_data_format_tailspace(
handle, argv[1], &ingress_flags, &tail_spacing, &error_number);
if (return_code == RMNETCTL_SUCCESS) {
printf("ingress_flags is %u\n", ingress_flags);
printf("tail_spacing is %u\n", tail_spacing);
}
} else if (!strcmp(*argv, "newvndprefix")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
return_code = rmnet_new_vnd_prefix(handle,
_STRTOUI32(argv[1]), &error_number, RMNETCTL_NEW_VND, argv[2]);
} else if (!strcmp(*argv, "newvndname")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
return_code = rmnet_new_vnd_name(handle,
_STRTOUI32(argv[1]), &error_number, argv[2]);
} else if (!strcmp(*argv, "newvnd")) {
_RMNETCLI_CHECKNULL(argv[1]);
return_code = rmnet_new_vnd(handle,
_STRTOUI32(argv[1]), &error_number, RMNETCTL_NEW_VND);
} else if (!strcmp(*argv, "getvndname")) {
char buffer[32];
memset(buffer, 0, 32);
_RMNETCLI_CHECKNULL(argv[1]);
return_code = rmnet_get_vnd_name(handle, _STRTOUI32(argv[1]),
&error_number, buffer, 32);
if (return_code == RMNETCTL_SUCCESS) {
printf("VND name: %s\n", buffer);
}
} else if (!strcmp(*argv, "freevnd")) {
_RMNETCLI_CHECKNULL(argv[1]);
return_code = rmnet_new_vnd(handle,
_STRTOUI32(argv[1]), &error_number, RMNETCTL_FREE_VND);
} else if (!strcmp(*argv, "setlidf")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
_RMNETCLI_CHECKNULL(argv[3]);
return_code = rmnet_set_link_ingress_data_format_tailspace(
handle, _STRTOUI32(argv[1]), _STRTOUI8(argv[2]), argv[3],
&error_number);
} else if (!strcmp(*argv, "delvnctcflow")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
_RMNETCLI_CHECKNULL(argv[3]);
return_code = rmnet_add_del_vnd_tc_flow(handle,
_STRTOUI32(argv[1]), _STRTOUI32(argv[2]), _STRTOUI32(argv[3]),
RMNETCTL_DEL_FLOW, &error_number);
} else if (!strcmp(*argv, "getlepc")) {
_RMNETCLI_CHECKNULL(argv[1]);
uint8_t rmnet_mode;
char *egress_dev_name;
egress_dev_name = NULL;
egress_dev_name = (char *)malloc(RMNET_MAX_STR_LEN
* sizeof(char));
if (!egress_dev_name) {
print_rmnet_api_status(RMNETCTL_LIB_ERR,
RMNETCTL_CFG_FAILURE_EGRESS_DEV_NAME_NULL);
rmnetctl_cleanup(handle);
return RMNETCTL_LIB_ERR;
}
return_code = rmnet_get_logical_ep_config(handle,
_STRTOI32(argv[1]), argv[2], &rmnet_mode,
&egress_dev_name, RMNET_MAX_STR_LEN, &error_number);
if (return_code == RMNETCTL_SUCCESS) {
printf("rmnet_mode is %u\n", rmnet_mode);
printf("egress_dev_name is %s\n", egress_dev_name);
}
free(egress_dev_name);
} else if (!strcmp(*argv, "addvnctcflow")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
_RMNETCLI_CHECKNULL(argv[3]);
return_code = rmnet_add_del_vnd_tc_flow(handle,
_STRTOUI32(argv[1]), _STRTOUI32(argv[2]), _STRTOUI32(argv[3]),
RMNETCTL_ADD_FLOW, &error_number);
} else if (!strcmp(*argv, "setledf")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
_RMNETCLI_CHECKNULL(argv[3]);
return_code = rmnet_set_link_egress_data_format(handle,
_STRTOUI32(argv[1]), _STRTOUI16(argv[2]), _STRTOUI16(argv[3]),
argv[4], &error_number);
} else if (!strcmp(*argv, "setlepc")) {
_RMNETCLI_CHECKNULL(argv[1]);
_RMNETCLI_CHECKNULL(argv[2]);
return_code = rmnet_set_logical_ep_config(handle,
_STRTOI32(argv[1]), _STRTOUI8(argv[2]), argv[3], argv[4],
&error_number);
} else if (!strcmp(*argv, "unsetlepc")) {
_RMNETCLI_CHECKNULL(argv[1]);
return_code = rmnet_unset_logical_ep_config(handle,
_STRTOI32(argv[1]), argv[2], &error_number);
#endif
}
end:
print_rmnet_api_status(return_code, error_number);
#ifdef USE_OLD_RMNET_DATA
if (is_new_api)
rtrmnet_ctl_deinit(handle);
else
rmnetctl_cleanup(handle);
#else
rtrmnet_ctl_deinit(handle);
#endif
return return_code;
}

View File

@@ -201,6 +201,352 @@ struct rmnetctl_ll_ack
===========================================================================*/
typedef struct rmnetctl_hndl_s rmnetctl_hndl_t;
#ifdef USE_OLD_RMNET_DATA
/*!
* @brief Public API to initialize the RMNET control driver
* @details Allocates memory for the RmNet handle. Creates and binds to a and
* netlink socket if successful
* @param **rmnetctl_hndl_t_val RmNet handle to be initialized
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnetctl_init(rmnetctl_hndl_t **hndl, uint16_t *error_code);
/*!
* @brief Public API to clean up the RmNeT control handle
* @details Close the socket and free the RmNet handle
* @param *rmnetctl_hndl_t_val RmNet handle to be initialized
* @return void
*/
void rmnetctl_cleanup(rmnetctl_hndl_t *hndl);
/*!
* @brief Public API to register/unregister a RMNET driver on a particular device
* @details Message type is RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE or
* RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE based on the flag for assoc_dev
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param dev_name Device on which to register the RmNet driver
* @param error_code Status code of this operation
* @param assoc_dev registers the device if RMNETCTL_DEVICE_ASSOCIATE or
* unregisters the device if RMNETCTL_DEVICE_UNASSOCIATE
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_associate_network_device(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint16_t *error_code,
uint8_t assoc_dev);
/*!
* @brief Public API to get if a RMNET driver is registered on a particular
* device
* @details Message type is RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param dev_name Device on which to check if the RmNet driver is registered
* @param register_status 1 if RmNet data driver is registered on a particular
* device, 0 if not
* @param error_code Status code of this operation
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_get_network_device_associated(rmnetctl_hndl_t *hndl,
const char *dev_name,
int *register_status,
uint16_t *error_code);
/*!
* @brief Public API to set the egress data format for a particular link.
* @details Message type is RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param egress_flags Egress flags to be set on the device
* @param agg_size Max size of aggregated packets
* @param agg_count Number of packets to be aggregated
* @param dev_name Device on which to set the egress data format
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_set_link_egress_data_format(rmnetctl_hndl_t *hndl,
uint32_t egress_flags,
uint16_t agg_size,
uint16_t agg_count,
const char *dev_name,
uint16_t *error_code);
/*!
* @brief Public API to get the egress data format for a particular link.
* @details Message type is RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param dev_name Device on which to get the egress data format
* @param egress_flags Egress flags from the device
* @param agg_count Number of packets to be aggregated
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_get_link_egress_data_format(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint32_t *egress_flags,
uint16_t *agg_size,
uint16_t *agg_count,
uint16_t *error_code);
/*!
* @brief Public API to set the ingress data format for a particular link.
* @details Message type is RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param ingress_flags Ingress flags from the device
* @param tail_spacing Tail spacing needed for the packet
* @param dev_name Device on which to set the ingress data format
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_set_link_ingress_data_format_tailspace(rmnetctl_hndl_t *hndl,
uint32_t ingress_flags,
uint8_t tail_spacing,
const char *dev_name,
uint16_t *error_code);
/*!
* @brief Public API to get the ingress data format for a particular link.
* @details Message type is RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param dev_name Device on which to get the ingress data format
* @param ingress_flags Ingress flags from the device
* @param tail_spacing Tail spacing needed for the packet
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_get_link_ingress_data_format_tailspace(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint32_t *ingress_flags,
uint8_t *tail_spacing,
uint16_t *error_code);
inline int rmnet_set_link_ingress_data_format(rmnetctl_hndl_t *hndl,
uint32_t ingress_flags,
const char *dev_name,
uint16_t *error_code)
{
return rmnet_set_link_ingress_data_format_tailspace(hndl,
ingress_flags,
0,
dev_name,
error_code);
}
inline int rmnet_get_link_ingress_data_format(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint32_t *ingress_flags,
uint16_t *error_code)
{
return rmnet_get_link_ingress_data_format_tailspace(hndl,
dev_name,
ingress_flags,
0,
error_code);
}
/*!
* @brief Public API to set the logical endpoint configuration for a
* particular link.
* @details Message type is RMNET_NETLINK_SET_LOGICAL_EP_CONFIG.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param logical_ep_id Logical end point id on which the configuration is to be
* set
* @param rmnet_mode RmNet mode to be set on the device
* @param dev_name Device on which to set the logical end point configuration
* @param egress_dev_name Egress Device if operating in bridge mode
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_set_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
uint8_t operating_mode,
const char *dev_name,
const char *next_dev,
uint16_t *error_code);
/*!
* @brief Public API to un-set the logical endpoint configuration for a
* particular link.
* @details Message type is RMNET_NETLINK_UNSET_LOGICAL_EP_CONFIG.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param logical_ep_id Logical end point id on which the configuration is to be
* un-set
* @param dev_name Device on which to un-set the logical end point configuration
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_unset_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
const char *dev_name,
uint16_t *error_code);
/*!
* @brief Public API to get the logical endpoint configuration for a
* particular link.
* @details Message type is RMNET_NETLINK_GET_LOGICAL_EP_CONFIG.
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param logical_ep_id Logical end point id from which to get the configuration
* @param dev_name Device on which to get the logical end point configuration
* @param rmnet_mode RmNet mode from the device
* @param next_dev Egress Device name
* @param next_dev_len Egress Device I/O string len
* @param error_code Status code of this operation returned from the kernel
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_get_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
const char *dev_name,
uint8_t *operating_mode,
char **next_dev,
uint32_t next_dev_len,
uint16_t *error_code);
/*!
* @brief Public API to create a new virtual device node
* @details Message type is RMNET_NETLINK_NEW_VND or
* RMNETCTL_FREE_VND based on the flag for new_vnd
* @param hndl RmNet handle for the Netlink message
* @param id Node number to create the virtual network device node
* @param error_code Status code of this operation returned from the kernel
* @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or
* frees the device if RMNETCTL_FREE_VND
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_new_vnd(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
uint8_t new_vnd);
/*!
* @brief Public API to create a new virtual device node with a custom prefix
* @details Message type is RMNET_NETLINK_NEW_VND or
* RMNETCTL_FREE_VND based on the flag for new_vnd
* @param hndl RmNet handle for the Netlink message
* @param id Node number to create the virtual network device node
* @param error_code Status code of this operation returned from the kernel
* @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or
* frees the device if RMNETCTL_FREE_VND
* @param prefix Prefix to be used when naming the network interface
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_new_vnd_prefix(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
uint8_t new_vnd,
const char *prefix);
/*!
* @brief Public API to create a new virtual device node with a custom prefix
* @details Message type is RMNET_NETLINK_NEW_VND or
* RMNETCTL_FREE_VND based on the flag for new_vnd
* @param hndl RmNet handle for the Netlink message
* @param id Node number to create the virtual network device node
* @param error_code Status code of this operation returned from the kernel
* @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or
* frees the device if RMNETCTL_FREE_VND
* @param name Name to be used when naming the network interface
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_new_vnd_name(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
const char *name);
/*!
* @brief API to get the ASCII name of a virtual network device from its ID
* @param hndl RmNet handle for the Netlink message
* @param id Node number to create the virtual network device node
* @param error_code Status code of this operation returned from the kernel
* @param buf Buffer to store ASCII representation of device name
* @param buflen Length of the buffer
* @param prefix Prefix to be used when naming the network interface
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_get_vnd_name(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
char *buf,
uint32_t buflen);
/*!
* @brief Public API to set or clear a flow
* @details Message type is RMNET_NETLINK_ADD_VND_TC_FLOW or
* RMNET_NETLINK_DEL_VND_TC_FLOW based on the flag for set_flow
* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
* @param id Node number to set or clear the flow on the virtual network
* device node
* @param map_flow_id Flow handle of the modem
* @param tc_flow_id Software flow handle
* @param set_flow sets the flow if RMNET_NETLINK_SET_FLOW or
* clears the flow if RMNET_NETLINK_CLEAR_FLOW
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
*/
int rmnet_add_del_vnd_tc_flow(rmnetctl_hndl_t *hndl,
uint32_t id,
uint32_t map_flow_id,
uint32_t tc_flow_id,
uint8_t set_flow,
uint16_t *error_code);
#endif
/* @brief Public API to initialize the RTM_NETLINK RMNET control driver
* @details Allocates memory for the RmNet handle. Creates and binds to a
* netlink socket if successful

View File

@@ -53,6 +53,9 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <linux/gen_stats.h>
#include <net/if.h>
#include <asm/types.h>
#ifdef USE_OLD_RMNET_DATA
#include <linux/rmnet_data.h>
#endif
#include "librmnetctl_hndl.h"
#include "librmnetctl.h"
@@ -195,6 +198,124 @@ static inline int memscpy_repeat(void* dst, size_t *dst_size,
return *dst_size;
}
#ifdef USE_OLD_RMNET_DATA
/*!
* @brief Synchronous method to send and receive messages to and from the kernel
* using netlink sockets
* @details Increments the transaction id for each message sent to the kernel.
* Sends the netlink message to the kernel and receives the response from the
* kernel.
* @param *hndl RmNet handle for this transaction
* @param request Message to be sent to the kernel
* @param response Message received from the kernel
* @return RMNETCTL_API_SUCCESS if successfully able to send and receive message
* from the kernel
* @return RMNETCTL_API_ERR_HNDL_INVALID if RmNet handle for the transaction was
* NULL
* @return RMNETCTL_API_ERR_REQUEST_NULL not enough memory to create buffer for
* sending the message
* @return RMNETCTL_API_ERR_MESSAGE_SEND if could not send the message to kernel
* @return RMNETCTL_API_ERR_MESSAGE_RECEIVE if could not receive message from the
* kernel
* @return RMNETCTL_API_ERR_MESSAGE_TYPE if the request and response type do not
* match
*/
static uint16_t rmnetctl_transact(rmnetctl_hndl_t *hndl,
struct rmnet_nl_msg_s *request,
struct rmnet_nl_msg_s *response) {
uint8_t *request_buf, *response_buf;
struct nlmsghdr *nlmsghdr_val;
struct rmnet_nl_msg_s *rmnet_nl_msg_s_val;
ssize_t bytes_read = -1, buffsize = MAX_BUF_SIZE - sizeof(struct nlmsghdr);
uint16_t return_code = RMNETCTL_API_ERR_HNDL_INVALID;
struct sockaddr_nl* __attribute__((__may_alias__)) saddr_ptr;
request_buf = NULL;
response_buf = NULL;
nlmsghdr_val = NULL;
rmnet_nl_msg_s_val = NULL;
do {
if (!hndl){
break;
}
if (!request){
return_code = RMNETCTL_API_ERR_REQUEST_NULL;
break;
}
if (!response){
return_code = RMNETCTL_API_ERR_RESPONSE_NULL;
break;
}
request_buf = (uint8_t *)malloc(MAX_BUF_SIZE * sizeof(uint8_t));
if (!request_buf){
return_code = RMNETCTL_API_ERR_REQUEST_NULL;
break;
}
response_buf = (uint8_t *)malloc(MAX_BUF_SIZE * sizeof(uint8_t));
if (!response_buf) {
return_code = RMNETCTL_API_ERR_RESPONSE_NULL;
break;
}
nlmsghdr_val = (struct nlmsghdr *)request_buf;
rmnet_nl_msg_s_val = (struct rmnet_nl_msg_s *)NLMSG_DATA(request_buf);
memset(request_buf, 0, MAX_BUF_SIZE*sizeof(uint8_t));
memset(response_buf, 0, MAX_BUF_SIZE*sizeof(uint8_t));
nlmsghdr_val->nlmsg_seq = hndl->transaction_id;
nlmsghdr_val->nlmsg_pid = hndl->pid;
nlmsghdr_val->nlmsg_len = MAX_BUF_SIZE;
memscpy((void *)NLMSG_DATA(request_buf), buffsize, request,
sizeof(struct rmnet_nl_msg_s));
rmnet_nl_msg_s_val->crd = RMNET_NETLINK_MSG_COMMAND;
hndl->transaction_id++;
saddr_ptr = &hndl->dest_addr;
socklen_t addrlen = sizeof(struct sockaddr_nl);
if (sendto(hndl->netlink_fd,
request_buf,
MAX_BUF_SIZE,
RMNETCTL_SOCK_FLAG,
(struct sockaddr*)saddr_ptr,
sizeof(struct sockaddr_nl)) < 0) {
return_code = RMNETCTL_API_ERR_MESSAGE_SEND;
break;
}
saddr_ptr = &hndl->src_addr;
bytes_read = recvfrom(hndl->netlink_fd,
response_buf,
MAX_BUF_SIZE,
RMNETCTL_SOCK_FLAG,
(struct sockaddr*)saddr_ptr,
&addrlen);
if (bytes_read < 0) {
return_code = RMNETCTL_API_ERR_MESSAGE_RECEIVE;
break;
}
buffsize = MAX_BUF_SIZE - sizeof(struct nlmsghdr);
memscpy(response, buffsize, (void *)NLMSG_DATA(response_buf),
sizeof(struct rmnet_nl_msg_s));
if (sizeof(*response) < sizeof(struct rmnet_nl_msg_s)) {
return_code = RMNETCTL_API_ERR_RESPONSE_NULL;
break;
}
if (request->message_type != response->message_type) {
return_code = RMNETCTL_API_ERR_MESSAGE_TYPE;
break;
}
return_code = RMNETCTL_SUCCESS;
} while(0);
free(request_buf);
free(response_buf);
return return_code;
}
#endif
/*!
* @brief Static function to check the dev name
* @details Checks if the name is not NULL and if the name is less than the
@@ -208,17 +329,738 @@ static inline int _rmnetctl_check_dev_name(const char *dev_name) {
do {
if (!dev_name)
break;
#ifdef USE_OLD_RMNET_DATA
if (strlen(dev_name) >= RMNET_MAX_STR_LEN)
#else
if (strlen(dev_name) >= IFNAMSIZ)
#endif
break;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
#ifdef USE_OLD_RMNET_DATA
/*!
* @brief Static function to check the string length after a copy
* @details Checks if the string length is not lesser than zero and lesser than
* RMNET_MAX_STR_LEN
* @param str_len length of the string after a copy
* @param error_code Status code of this operation
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
*/
static inline int _rmnetctl_check_len(size_t str_len, uint16_t *error_code) {
int return_code = RMNETCTL_LIB_ERR;
do {
if (str_len > RMNET_MAX_STR_LEN) {
*error_code = RMNETCTL_API_ERR_STRING_TRUNCATION;
break;
}
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
/*!
* @brief Static function to check the response type
* @details Checks if the response type of this message was return code
* @param crd The crd field passed
* @param error_code Status code of this operation
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
*/
static inline int _rmnetctl_check_code(int crd, uint16_t *error_code) {
int return_code = RMNETCTL_LIB_ERR;
do {
if (crd != RMNET_NETLINK_MSG_RETURNCODE) {
*error_code = RMNETCTL_API_ERR_RETURN_TYPE;
break;
}
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
/*!
* @brief Static function to check the response type
* @details Checks if the response type of this message was data
* @param crd The crd field passed
* @param error_code Status code of this operation
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
*/
static inline int _rmnetctl_check_data(int crd, uint16_t *error_code) {
int return_code = RMNETCTL_LIB_ERR;
do {
if (crd != RMNET_NETLINK_MSG_RETURNDATA) {
*error_code = RMNETCTL_API_ERR_RETURN_TYPE;
break;
}
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
/*!
* @brief Static function to set the return value
* @details Checks if the error_code from the transaction is zero for a return
* code type message and sets the message type as RMNETCTL_SUCCESS
* @param crd The crd field passed
* @param error_code Status code of this operation
* @return RMNETCTL_SUCCESS if successful
* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
* Check error_code
*/
static inline int _rmnetctl_set_codes(int error_val, uint16_t *error_code) {
int return_code = RMNETCTL_KERNEL_ERR;
if (error_val == RMNET_CONFIG_OK)
return_code = RMNETCTL_SUCCESS;
else
*error_code = (uint16_t)error_val + RMNETCTL_KERNEL_FIRST_ERR;
return return_code;
}
#endif
/*===========================================================================
EXPOSED API
===========================================================================*/
#ifdef USE_OLD_RMNET_DATA
int rmnetctl_init(rmnetctl_hndl_t **hndl, uint16_t *error_code)
{
pid_t pid = 0;
int netlink_fd = -1, return_code = RMNETCTL_LIB_ERR;
struct sockaddr_nl* __attribute__((__may_alias__)) saddr_ptr;
do {
if ((!hndl) || (!error_code)){
return_code = RMNETCTL_INVALID_ARG;
break;
}
*hndl = (rmnetctl_hndl_t *)malloc(sizeof(rmnetctl_hndl_t));
if (!*hndl) {
*error_code = RMNETCTL_API_ERR_HNDL_INVALID;
break;
}
memset(*hndl, 0, sizeof(rmnetctl_hndl_t));
pid = getpid();
if (pid < MIN_VALID_PROCESS_ID) {
free(*hndl);
*error_code = RMNETCTL_INIT_ERR_PROCESS_ID;
break;
}
(*hndl)->pid = (uint32_t)pid;
netlink_fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, RMNET_NETLINK_PROTO);
if (netlink_fd < MIN_VALID_SOCKET_FD) {
free(*hndl);
*error_code = RMNETCTL_INIT_ERR_NETLINK_FD;
break;
}
(*hndl)->netlink_fd = netlink_fd;
memset(&(*hndl)->src_addr, 0, sizeof(struct sockaddr_nl));
(*hndl)->src_addr.nl_family = AF_NETLINK;
(*hndl)->src_addr.nl_pid = (*hndl)->pid;
saddr_ptr = &(*hndl)->src_addr;
if (bind((*hndl)->netlink_fd,
(struct sockaddr*)saddr_ptr,
sizeof(struct sockaddr_nl)) < 0) {
close((*hndl)->netlink_fd);
free(*hndl);
*error_code = RMNETCTL_INIT_ERR_BIND;
break;
}
memset(&(*hndl)->dest_addr, 0, sizeof(struct sockaddr_nl));
(*hndl)->dest_addr.nl_family = AF_NETLINK;
(*hndl)->dest_addr.nl_pid = KERNEL_PROCESS_ID;
(*hndl)->dest_addr.nl_groups = UNICAST;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
void rmnetctl_cleanup(rmnetctl_hndl_t *hndl)
{
if (!hndl)
return;
close(hndl->netlink_fd);
free(hndl);
}
int rmnet_associate_network_device(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint16_t *error_code,
uint8_t assoc_dev)
{
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
((assoc_dev != RMNETCTL_DEVICE_ASSOCIATE) &&
(assoc_dev != RMNETCTL_DEVICE_UNASSOCIATE))) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
if (assoc_dev == RMNETCTL_DEVICE_ASSOCIATE)
request.message_type = RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE;
else
request.message_type = RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE;
request.arg_length = RMNET_MAX_STR_LEN;
str_len = strlcpy((char *)(request.data), dev_name, (size_t)RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_get_network_device_associated(rmnetctl_hndl_t *hndl,
const char *dev_name,
int *register_status,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!register_status) || (!error_code) ||
_rmnetctl_check_dev_name(dev_name)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED;
request.arg_length = RMNET_MAX_STR_LEN;
str_len = strlcpy((char *)(request.data), dev_name, RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_data(response.crd, error_code)
!= RMNETCTL_SUCCESS) {
if (_rmnetctl_check_code(response.crd, error_code)
== RMNETCTL_SUCCESS)
return_code = _rmnetctl_set_codes(response.return_code,
error_code);
break;
}
*register_status = response.return_code;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
int rmnet_set_link_egress_data_format(rmnetctl_hndl_t *hndl,
uint32_t egress_flags,
uint16_t agg_size,
uint16_t agg_count,
const char *dev_name,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
((~EGRESS_FLAGS_MASK) & egress_flags)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT;
request.arg_length = RMNET_MAX_STR_LEN +
sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t);
str_len = strlcpy((char *)(request.data_format.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
request.data_format.flags = egress_flags;
request.data_format.agg_size = agg_size;
request.data_format.agg_count = agg_count;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_get_link_egress_data_format(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint32_t *egress_flags,
uint16_t *agg_size,
uint16_t *agg_count,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!egress_flags) || (!agg_size) || (!agg_count) ||
(!error_code) || _rmnetctl_check_dev_name(dev_name)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT;
request.arg_length = RMNET_MAX_STR_LEN;
str_len = strlcpy((char *)(request.data_format.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_data(response.crd, error_code)
!= RMNETCTL_SUCCESS) {
if (_rmnetctl_check_code(response.crd, error_code)
== RMNETCTL_SUCCESS)
return_code = _rmnetctl_set_codes(response.return_code,
error_code);
break;
}
*egress_flags = response.data_format.flags;
*agg_size = response.data_format.agg_size;
*agg_count = response.data_format.agg_count;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
int rmnet_set_link_ingress_data_format_tailspace(rmnetctl_hndl_t *hndl,
uint32_t ingress_flags,
uint8_t tail_spacing,
const char *dev_name,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
((~INGRESS_FLAGS_MASK) & ingress_flags)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT;
request.arg_length = RMNET_MAX_STR_LEN +
sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t);
str_len = strlcpy((char *)(request.data_format.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
request.data_format.flags = ingress_flags;
request.data_format.tail_spacing = tail_spacing;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_get_link_ingress_data_format_tailspace(rmnetctl_hndl_t *hndl,
const char *dev_name,
uint32_t *ingress_flags,
uint8_t *tail_spacing,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) ||
_rmnetctl_check_dev_name(dev_name)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT;
request.arg_length = RMNET_MAX_STR_LEN;
str_len = strlcpy((char *)(request.data_format.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_data(response.crd, error_code)
!= RMNETCTL_SUCCESS) {
if (_rmnetctl_check_code(response.crd, error_code)
== RMNETCTL_SUCCESS)
return_code = _rmnetctl_set_codes(response.return_code,
error_code);
break;
}
if (ingress_flags)
*ingress_flags = response.data_format.flags;
if (tail_spacing)
*tail_spacing = response.data_format.tail_spacing;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
int rmnet_set_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
uint8_t operating_mode,
const char *dev_name,
const char *next_dev,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || ((ep_id < -1) || (ep_id > 31)) || (!error_code) ||
_rmnetctl_check_dev_name(dev_name) ||
_rmnetctl_check_dev_name(next_dev) ||
operating_mode >= RMNET_EPMODE_LENGTH) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_SET_LOGICAL_EP_CONFIG;
request.arg_length = RMNET_MAX_STR_LEN +
RMNET_MAX_STR_LEN + sizeof(int32_t) + sizeof(uint8_t);
str_len = strlcpy((char *)(request.local_ep_config.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
str_len = strlcpy((char *)(request.local_ep_config.next_dev),
next_dev,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
request.local_ep_config.ep_id = ep_id;
request.local_ep_config.operating_mode = operating_mode;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_unset_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
const char *dev_name,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || ((ep_id < -1) || (ep_id > 31)) || (!error_code) ||
_rmnetctl_check_dev_name(dev_name)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_UNSET_LOGICAL_EP_CONFIG;
request.arg_length = RMNET_MAX_STR_LEN + sizeof(int32_t);
str_len = strlcpy((char *)(request.local_ep_config.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
request.local_ep_config.ep_id = ep_id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_get_logical_ep_config(rmnetctl_hndl_t *hndl,
int32_t ep_id,
const char *dev_name,
uint8_t *operating_mode,
char **next_dev,
uint32_t next_dev_len,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
size_t str_len = 0;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!operating_mode) || (!error_code) || ((ep_id < -1) ||
(ep_id > 31)) || _rmnetctl_check_dev_name(dev_name) || (!next_dev)
|| (0 == next_dev_len)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_GET_LOGICAL_EP_CONFIG;
request.arg_length = RMNET_MAX_STR_LEN + sizeof(int32_t);
str_len = strlcpy((char *)(request.local_ep_config.dev),
dev_name,
RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
request.local_ep_config.ep_id = ep_id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_data(response.crd, error_code)
!= RMNETCTL_SUCCESS) {
if (_rmnetctl_check_code(response.crd, error_code)
== RMNETCTL_SUCCESS)
return_code = _rmnetctl_set_codes(response.return_code,
error_code);
break;
}
str_len = strlcpy(*next_dev,
(char *)(response.local_ep_config.next_dev),
min(RMNET_MAX_STR_LEN, next_dev_len));
if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
break;
*operating_mode = response.local_ep_config.operating_mode;
return_code = RMNETCTL_SUCCESS;
} while(0);
return return_code;
}
int rmnet_new_vnd_prefix(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
uint8_t new_vnd,
const char *prefix)
{
struct rmnet_nl_msg_s request, response;
int return_code = RMNETCTL_LIB_ERR;
size_t str_len = 0;
do {
if ((!hndl) || (!error_code) ||
((new_vnd != RMNETCTL_NEW_VND) && (new_vnd != RMNETCTL_FREE_VND))) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
memset(request.vnd.vnd_name, 0, RMNET_MAX_STR_LEN);
if (new_vnd == RMNETCTL_NEW_VND) {
if (prefix) {
request.message_type =RMNET_NETLINK_NEW_VND_WITH_PREFIX;
str_len = strlcpy((char *)request.vnd.vnd_name,
prefix, RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code)
!= RMNETCTL_SUCCESS)
break;
} else {
request.message_type = RMNET_NETLINK_NEW_VND;
}
} else {
request.message_type = RMNET_NETLINK_FREE_VND;
}
request.arg_length = sizeof(uint32_t);
request.vnd.id = id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_new_vnd_name(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
const char *prefix)
{
struct rmnet_nl_msg_s request, response;
int return_code = RMNETCTL_LIB_ERR;
size_t str_len = 0;
do {
if ((!hndl) || (!error_code)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
memset(request.vnd.vnd_name, 0, RMNET_MAX_STR_LEN);
if (prefix) {
request.message_type =RMNET_NETLINK_NEW_VND_WITH_NAME;
str_len = strlcpy((char *)request.vnd.vnd_name,
prefix, RMNET_MAX_STR_LEN);
if (_rmnetctl_check_len(str_len, error_code)
!= RMNETCTL_SUCCESS)
break;
} else {
request.message_type = RMNET_NETLINK_NEW_VND;
}
request.arg_length = sizeof(uint32_t);
request.vnd.id = id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
int rmnet_new_vnd(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
uint8_t new_vnd)
{
return rmnet_new_vnd_prefix(hndl, id, error_code, new_vnd, 0);
}
int rmnet_get_vnd_name(rmnetctl_hndl_t *hndl,
uint32_t id,
uint16_t *error_code,
char *buf,
uint32_t buflen)
{
struct rmnet_nl_msg_s request, response;
uint32_t str_len;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) || (!buf) || (0 == buflen)) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
request.message_type = RMNET_NETLINK_GET_VND_NAME;
request.arg_length = sizeof(uint32_t);
request.vnd.id = id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_data(response.crd, error_code)
!= RMNETCTL_SUCCESS) {
if (_rmnetctl_check_code(response.crd, error_code)
== RMNETCTL_SUCCESS)
return_code = _rmnetctl_set_codes(response.return_code,
error_code);
break;
}
str_len = (uint32_t)strlcpy(buf,
(char *)(response.vnd.vnd_name),
buflen);
if (str_len >= buflen) {
*error_code = RMNETCTL_API_ERR_STRING_TRUNCATION;
break;
}
return_code = RMNETCTL_SUCCESS;
} while (0);
return return_code;
}
int rmnet_add_del_vnd_tc_flow(rmnetctl_hndl_t *hndl,
uint32_t id,
uint32_t map_flow_id,
uint32_t tc_flow_id,
uint8_t set_flow,
uint16_t *error_code) {
struct rmnet_nl_msg_s request, response;
int return_code = RMNETCTL_LIB_ERR;
do {
if ((!hndl) || (!error_code) || ((set_flow != RMNETCTL_ADD_FLOW) &&
(set_flow != RMNETCTL_DEL_FLOW))) {
return_code = RMNETCTL_INVALID_ARG;
break;
}
if (set_flow == RMNETCTL_ADD_FLOW)
request.message_type = RMNET_NETLINK_ADD_VND_TC_FLOW;
else
request.message_type = RMNET_NETLINK_DEL_VND_TC_FLOW;
request.arg_length = (sizeof(uint32_t))*3;
request.flow_control.id = id;
request.flow_control.map_flow_id = map_flow_id;
request.flow_control.tc_flow_id = tc_flow_id;
if ((*error_code = rmnetctl_transact(hndl, &request, &response))
!= RMNETCTL_SUCCESS)
break;
if (_rmnetctl_check_code(response.crd, error_code) != RMNETCTL_SUCCESS)
break;
return_code = _rmnetctl_set_codes(response.return_code, error_code);
} while(0);
return return_code;
}
#endif
/*
* NEW DRIVER API
*/