Pārlūkot izejas kodu

qcacmn: Add qdf parser API of type uint8_t and uint16_t

Add QDF INI parser API of type uint8_t and uint16_t

Change-Id: I0716df7986f00c60ead852f368d06d37dba7db80
CRs-Fixed: 3389847
Madhavan Ganesan 2 gadi atpakaļ
vecāks
revīzija
a30c47e6cc
2 mainītis faili ar 65 papildinājumiem un 1 dzēšanām
  1. 26 0
      qdf/inc/qdf_types.h
  2. 39 1
      qdf/src/qdf_types.c

+ 26 - 0
qdf/inc/qdf_types.h

@@ -882,6 +882,32 @@ QDF_STATUS qdf_bool_parse(const char *bool_str, bool *out_bool);
  */
 QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int);
 
+/**
+ * qdf_uint8_parse() - parse the given string as a 8-bit unsigned integer
+ * @int_str: the input integer string to parse
+ * @out_int: the output integer value, populated on success
+ *
+ * Supports binary (0b), octal (0o), decimal (no prefix), and hexadecimal (0x)
+ * encodings via typical prefix notation. Leading/trailing whitespace is
+ * ignored.
+ *
+ * Return: QDF_STATUS
+ */
+QDF_STATUS qdf_uint8_parse(const char *int_str, uint8_t *out_int);
+
+/**
+ * qdf_uint16_parse() - parse the given string as a 16-bit unsigned integer
+ * @int_str: the input integer string to parse
+ * @out_int: the output integer value, populated on success
+ *
+ * Supports binary (0b), octal (0o), decimal (no prefix), and hexadecimal (0x)
+ * encodings via typical prefix notation. Leading/trailing whitespace is
+ * ignored.
+ *
+ * Return: QDF_STATUS
+ */
+QDF_STATUS qdf_uint16_parse(const char *int_str, uint16_t *out_int);
+
 /**
  * qdf_uint32_parse() - parse the given string as a 32-bit unsigned integer
  * @int_str: the input integer string to parse

+ 39 - 1
qdf/src/qdf_types.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. 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
@@ -307,6 +307,44 @@ QDF_STATUS qdf_int32_parse(const char *int_str, int32_t *out_int)
 }
 qdf_export_symbol(qdf_int32_parse);
 
+QDF_STATUS qdf_uint8_parse(const char *int_str, uint8_t *out_int)
+{
+	QDF_STATUS status;
+	uint64_t value;
+
+	status = qdf_uint64_parse(int_str, &value);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
+
+	if ((uint8_t)value != value)
+		return QDF_STATUS_E_RANGE;
+
+	*out_int = value;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+qdf_export_symbol(qdf_uint8_parse);
+
+QDF_STATUS qdf_uint16_parse(const char *int_str, uint16_t *out_int)
+{
+	QDF_STATUS status;
+	uint64_t value;
+
+	status = qdf_uint64_parse(int_str, &value);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
+
+	if ((uint16_t)value != value)
+		return QDF_STATUS_E_RANGE;
+
+	*out_int = value;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+qdf_export_symbol(qdf_uint16_parse);
+
 QDF_STATUS qdf_uint32_parse(const char *int_str, uint32_t *out_int)
 {
 	QDF_STATUS status;