qcacmn: Add support to parse a string into uint16 array
Currently there is no api to parse a string to uint16 array. Write an api to parse a string to uint16 array. Change-Id: Idbde9d70c64bc131813f5789c0453c9b3736228b CRs-Fixed: 2478267
This commit is contained in:
@@ -934,6 +934,22 @@ struct qdf_ipv6_addr {
|
||||
*/
|
||||
QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr);
|
||||
|
||||
/**
|
||||
* qdf_uint16_array_parse() - parse the given string as uint16 array
|
||||
* @in_str: the input string to parse
|
||||
* @out_array: the output uint16 array, populated on success
|
||||
* @array_size: size of the array
|
||||
* @out_size: size of the populated array
|
||||
*
|
||||
* This API is called to convert string (each value separated by
|
||||
* a comma) into an uint16 array
|
||||
*
|
||||
* Return: QDF_STATUS
|
||||
*/
|
||||
|
||||
QDF_STATUS qdf_uint16_array_parse(const char *in_str, uint16_t *out_array,
|
||||
qdf_size_t array_size, qdf_size_t *out_size);
|
||||
|
||||
/**
|
||||
* qdf_uint8_array_parse() - parse the given string as uint8 array
|
||||
* @in_str: the input string to parse
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
@@ -612,6 +612,55 @@ QDF_STATUS qdf_ipv6_parse(const char *ipv6_str, struct qdf_ipv6_addr *out_addr)
|
||||
}
|
||||
qdf_export_symbol(qdf_ipv6_parse);
|
||||
|
||||
QDF_STATUS qdf_uint16_array_parse(const char *in_str, uint16_t *out_array,
|
||||
qdf_size_t array_size, qdf_size_t *out_size)
|
||||
{
|
||||
QDF_STATUS status;
|
||||
bool negate;
|
||||
qdf_size_t size = 0;
|
||||
uint64_t value;
|
||||
|
||||
QDF_BUG(in_str);
|
||||
if (!in_str)
|
||||
return QDF_STATUS_E_INVAL;
|
||||
|
||||
QDF_BUG(out_array);
|
||||
if (!out_array)
|
||||
return QDF_STATUS_E_INVAL;
|
||||
|
||||
QDF_BUG(out_size);
|
||||
if (!out_size)
|
||||
return QDF_STATUS_E_INVAL;
|
||||
|
||||
while (size < array_size) {
|
||||
status = __qdf_int_parse_lazy(&in_str, &value, &negate);
|
||||
if (QDF_IS_STATUS_ERROR(status))
|
||||
return status;
|
||||
|
||||
if ((uint16_t)value != value || negate)
|
||||
return QDF_STATUS_E_RANGE;
|
||||
|
||||
in_str = qdf_str_left_trim(in_str);
|
||||
|
||||
switch (in_str[0]) {
|
||||
case ',':
|
||||
out_array[size++] = value;
|
||||
in_str++;
|
||||
break;
|
||||
case '\0':
|
||||
out_array[size++] = value;
|
||||
*out_size = size;
|
||||
return QDF_STATUS_SUCCESS;
|
||||
default:
|
||||
return QDF_STATUS_E_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return QDF_STATUS_E_FAILURE;
|
||||
}
|
||||
|
||||
qdf_export_symbol(qdf_uint16_array_parse);
|
||||
|
||||
QDF_STATUS qdf_uint8_array_parse(const char *in_str, uint8_t *out_array,
|
||||
qdf_size_t array_size, qdf_size_t *out_size)
|
||||
{
|
||||
|
Reference in New Issue
Block a user