fix:wifi_app mistake (#13)

This commit is contained in:
luckfox-eng33
2023-10-27 17:12:27 +08:00
committed by GitHub
parent b496d0e4f8
commit 395d161f40
1323 changed files with 537512 additions and 492255 deletions
+1 -9
View File
@@ -1,12 +1,4 @@
# *.o
# !hostapd-2.6/hostapd/*.o
# !hostapd-2.6/src/common/*.o
# !hostapd-2.6/src/crypto/*.o
# !hostapd-2.6/src/drivers/*.o
# !hostapd-2.6/src/drivers/*.o
# !hostapd-2.6/src/drivers/*.o
# !hostapd-2.6/src/drivers/*.o
*.o
hostapd-2.6/hostapd/hostapd
hostapd-2.6/hostapd/hostapd_cli
install_out
File diff suppressed because it is too large Load Diff
@@ -24,27 +24,23 @@
#define cJSON__h
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#if !defined(__WINDOWS__) && \
(defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid
issues where we are being called from a project with a different default calling
convention. For windows you have 3 define options:
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever
dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you
want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you
want to dllimport symbol
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar
behavior by
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
@@ -52,18 +48,15 @@ or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way
CJSON_EXPORT_SYMBOLS does
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and
* header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
!defined(CJSON_EXPORT_SYMBOLS)
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
@@ -78,8 +71,7 @@ CJSON_EXPORT_SYMBOLS does
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \
defined(CJSON_API_VISIBILITY)
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
@@ -108,13 +100,12 @@ CJSON_EXPORT_SYMBOLS does
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON {
/* next/prev allow you to walk array/object chains. Alternatively, use
* GetArraySize/GetArrayItem/GetObjectItem */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of
* the items in the array/object. */
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
@@ -127,23 +118,21 @@ typedef struct cJSON {
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of
* subitems of an object. */
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks {
/* malloc/free are CDECL on Windows regardless of the default calling
* convention of the compiler, so ensure the hooks allow passing those
* functions directly. */
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse
* them. This is to prevent stack overflows. */
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
@@ -154,64 +143,36 @@ CJSON_PUBLIC(const char *) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from
* all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib
* free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is
* cJSON_PrintPreallocated, where the caller has full responsibility of the
* buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate.
*/
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null
* terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then
* return_parse_end will contain a pointer to the error so will match
* cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithOpts(const char *value, const char **return_parse_end,
cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length,
const char **return_parse_end,
cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
* at the final size. guessing well reduces reallocation. fmt=0 gives
* unformatted, =1 gives formatted */
CJSON_PUBLIC(char *)
cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with
* given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will
* use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool)
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length,
const cJSON_bool format);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if
* unsuccessful. */
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *)
cJSON_GetObjectItem(const cJSON *const object, const char *const string);
CJSON_PUBLIC(cJSON *)
cJSON_GetObjectItemCaseSensitive(const cJSON *const object,
const char *const string);
CJSON_PUBLIC(cJSON_bool)
cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error.
* You'll probably need to look a few chars back to make sense of it. Defined
* when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
@@ -251,126 +212,77 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the
* number array, otherwise array access will be out of bounds.*/
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *)
cJSON_CreateStringArray(const char *const *strings, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and
* will definitely survive the cJSON object. WARNING: When this function was
* used, make sure to always check that (item->type & cJSON_StringIsConst) is
* zero before writing to `item->string` */
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you
* want to add an existing cJSON to a new cJSON, but don't want to corrupt your
* existing cJSON. */
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool)
cJSON_InsertItemInArray(
cJSON *array, int which,
cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item,
cJSON *replacement);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string,
cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new
* memory that will need to be released. With recurse!=0, it will duplicate any
* children connected to the item. The item->next and ->prev pointers are always
* zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or
* invalid, they will be considered unequal. case_sensitive determines if object
* keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool)
cJSON_Compare(const cJSON *const a, const cJSON *const b,
const cJSON_bool case_sensitive);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from
* strings. The input pointer json cannot point to a read-only address area,
* such as a string constant, but should point to a readable and writable adress
* area. */
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON *)
cJSON_AddNullToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddTrueToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddFalseToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddBoolToObject(cJSON *const object, const char *const name,
const cJSON_bool boolean);
CJSON_PUBLIC(cJSON *)
cJSON_AddNumberToObject(cJSON *const object, const char *const name,
const double number);
CJSON_PUBLIC(cJSON *)
cJSON_AddStringToObject(cJSON *const object, const char *const name,
const char *const string);
CJSON_PUBLIC(cJSON *)
cJSON_AddRawToObject(cJSON *const object, const char *const name,
const char *const raw);
CJSON_PUBLIC(cJSON *)
cJSON_AddObjectToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddArrayToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble
* too. */
#define cJSON_SetIntValue(object, number) \
((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) \
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type
* of object is cJSON_String */
CJSON_PUBLIC(char *)
cJSON_SetValuestring(cJSON *object, const char *valuestring);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) \
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
element = element->next)
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with
* cJSON_InitHooks */
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
@@ -1,30 +1,33 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include "hi_base.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "hi_types.h"
#include "securec.h"
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "hi_base.h"
#include "cJSON.h"
/*****************************************************************************
4 函数实现
*****************************************************************************/
hi_void client_wait_event(hi_u8 cmdval) {
hi_void client_wait_event(hi_u8 cmdval)
{
ssize_t recvbytes;
char buf[SOCK_BUF_MAX];
struct sockaddr_in clientaddr;
@@ -42,23 +45,20 @@ hi_void client_wait_event(hi_u8 cmdval) {
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(SOCK_EVENT_PORT);
if (bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) ==
-1) {
if (bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
sample_log_print("bind error:%s", strerror(errno));
goto error_bind;
}
tv.tv_sec = 10;
tv.tv_usec = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) !=
0) {
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != 0) {
sample_log_print("setsockopt error:%s", strerror(errno));
goto error_setsockopt;
}
memset(buf, 0, sizeof(buf));
recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0,
(struct sockaddr *)&clientaddr, &addrlen);
recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&clientaddr, &addrlen);
if (recvbytes < 0) {
sample_log_print("recvfrom error:%s\n", strerror(errno));
goto error_recvfrom;
@@ -85,7 +85,8 @@ error_recvfrom:
close(sockfd);
}
hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len) {
hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len)
{
struct sockaddr_in servaddr;
ssize_t recvbytes;
hi_char buf[SOCK_BUF_MAX];
@@ -103,23 +104,20 @@ hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len) {
return;
}
if (sendto(sockfd, cmd, strlen(cmd), 0, (const struct sockaddr *)&servaddr,
sizeof(servaddr)) == -1) {
if (sendto(sockfd, cmd, strlen(cmd), 0, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
sample_log_print("SAMPLE_CLIENT: sendto error:%s\n", strerror(errno));
return;
}
tv.tv_sec = 10;
tv.tv_usec = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) !=
0) {
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != 0) {
sample_log_print("setsockopt error:%s", strerror(errno));
return;
}
memset(buf, 0, sizeof(buf));
recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0,
(struct sockaddr *)&clientaddr, &addrlen);
recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&clientaddr, &addrlen);
if (recvbytes < 0) {
sample_log_print("recvfrom error:%s\n", strerror(errno));
return;
@@ -143,7 +141,8 @@ hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len) {
sample_log_print("SAMPLE_CLIENT: send cmd ok!\n");
}
hi_s32 main(hi_s32 argc, const hi_char **argv) {
hi_s32 main(hi_s32 argc, const hi_char **argv)
{
(void)argc;
hi_char cmd[SOCK_BUF_MAX] = {0};
if (argc < 2 || argv == NULL) { /* 2:参数个数 */
@@ -171,3 +170,4 @@ hi_s32 main(hi_s32 argc, const hi_char **argv) {
close(sockfd);
return 0;
}
+6 -5
View File
@@ -1,7 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: header file for Wi-Fi Station component Author:
* Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: header file for Wi-Fi Station component
* Author: Hisilicon
* Create: 2020-09-09
*/
#ifndef __SAMPLE_COMM_H__
@@ -18,11 +19,11 @@ extern "C" {
#define SOCK_EVENT_PORT 8823
#define sample_log_print(fmt, args...) \
printf("[%s][%s][l:%d]," fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, \
##args);
printf("[%s][%s][l:%d]," fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args);
#define sample_unused(x) ((x) = (x))
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
@@ -1,7 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights
* reserved. Description: Error code returned by the interface. Author:
* Hisilicon Create: 2019-08-02
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: Error code returned by the interface.
* Author: Hisilicon
* Create: 2019-08-02
*/
#ifndef __HI_ERRNO_H__
#define __HI_ERRNO_H__
@@ -283,6 +284,7 @@
#define HI_ERR_PWM_INITILIZATION_ALREADY 0x80001341
#define HI_ERR_PWM_INVALID_PARAMETER 0x80001342
/* dma */
#define HI_ERR_DMA_INVALID_PARA 0x80001380
#define HI_ERR_DMA_NOT_INIT 0x80001381
@@ -428,6 +430,7 @@
#define HI_ERR_SYSERROR_NOT_FOUND 0x80003140
#define HI_ERR_SYSERROR_INVALID_PARAMETER 0x80003141
/* APP */
#define HI_ERR_APP_INITILIZATION_ALREADY 0x80003180
#define HI_ERR_APP_INVALID_PARAMETER 0x80003181
@@ -435,6 +438,7 @@
/* CRC */
#define HI_ERR_CRC_INVALID_PARAMETER 0x800031C0
/* sigma */
#define HI_ERR_SIGMA_INVALID_PARAMETER 0x80003200
@@ -1,9 +1,9 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights
* reserved. Description: A parameter is added to the security C APIs based on
* the standard C interface, that is, the upper limit of the write operation
* address space to prevent out-of-bounds write. Author: Hisilicon Create:
* 2018-08-04
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved.
* Description: A parameter is added to the security C APIs based on the standard C interface, that is, the upper
* limit of the write operation address space to prevent out-of-bounds write.
* Author: Hisilicon
* Create: 2018-08-04
*/
/**
@@ -31,27 +31,22 @@ typedef unsigned int size_t;
/**
* @ingroup iot_secure_c
* @brief Copies the source string to the destination
buffer.CNcomment:复制源字符串到目的缓冲区。CNend
* @brief Copies the source string to the destination buffer.CNcomment:复制源字符串到目的缓冲区。CNend
*
* @par 描述: Copies the source string to the destination buffer.
CNcomment:复制源字符串到目的缓冲区。CNend
*
* @attention None
*
* @param dest [OUT] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param dest [OUT] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
@@ -59,33 +54,28 @@ extern errno_t strcpy_s(char *dest, size_t dest_max, const char *src);
/**
* @ingroup iot_secure_c
* @brief Copies the source string of a specified length to the destination
buffer. CNcomment:复制指定长度源字符串到目的缓冲区。CNend
* @brief Copies the source string of a specified length to the destination buffer.
CNcomment:复制指定长度源字符串到目的缓冲区。CNend
*
* @par 描述:Copies the source string of a specified length to the destination
buffer. CNcomment:复制指定长度源字符串到目的缓冲区。CNend
* @par 描述:Copies the source string of a specified length to the destination buffer.
CNcomment:复制指定长度源字符串到目的缓冲区。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source
buffer. CNcomment:从源缓冲区中复制的字符数。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source buffer.
CNcomment:从源缓冲区中复制的字符数。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
extern errno_t strncpy_s(char *dest, size_t dest_max, const char *src,
size_t count);
extern errno_t strncpy_s(char *dest, size_t dest_max, const char *src, size_t count);
/**
* @ingroup iot_secure_c
@@ -96,19 +86,15 @@ CNcomment:
CNcomment:将源字符串连接到目的字符串后面。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
@@ -116,34 +102,28 @@ extern errno_t strcat_s(char *dest, size_t dest_max, const char *src);
/**
* @ingroup iot_secure_c
* @brief Concatenates the source string of a specified length to the end of the
destination string. CNcomment:将指定长度的源字符串连接到目的字符串后面。CNend
* @brief Concatenates the source string of a specified length to the end of the destination string.
CNcomment:将指定长度的源字符串连接到目的字符串后面。CNend
*
* @par 描述: Concatenates the source string of a specified length to the end of
the destination string.
* @par 描述: Concatenates the source string of a specified length to the end of the destination string.
CNcomment:将指定长度的源字符串连接到目的字符串后面。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source
buffer. CNcomment:从源缓冲区连接的字符数。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source buffer.
CNcomment:从源缓冲区连接的字符数。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
extern errno_t strncat_s(char *dest, size_t dest_max, const char *src,
size_t count);
extern errno_t strncat_s(char *dest, size_t dest_max, const char *src, size_t count);
/**
* @ingroup iot_secure_c
@@ -154,26 +134,21 @@ CNcomment:
CNcomment:复制源缓冲区的数据到目的缓冲区。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source
buffer. CNcomment:从源缓冲区中复制的字符数。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source buffer.
CNcomment:从源缓冲区中复制的字符数。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src,
size_t count);
extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src, size_t count);
/**
* @ingroup iot_secure_c
@@ -184,21 +159,17 @@ CNcomment:
CNcomment:设置目的缓冲区为特定值。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param c [IN] type #const #char *, Source
buffer.CNcomment:特定值。CNend
* @param count [IN] type #size_t, Number of characters copied from the source
buffer. CNcomment:设置为特定值的字符数。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param c [IN] type #const #char *, Source buffer.CNcomment:特定值。CNend
* @param count [IN] type #size_t, Number of characters copied from the source buffer.
CNcomment:设置为特定值的字符数。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
@@ -213,51 +184,42 @@ CNcomment:
CNcomment:移动源缓冲区的数据到目的缓冲区。CNend
* @attention None
*
* @param dest [IN] type #char *, Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source
buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source
buffer. CNcomment:从源缓冲区中移动的字符数。CNend
* @param dest [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param src [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
* @param count [IN] type #size_t, Number of characters copied from the source buffer.
CNcomment:从源缓冲区中移动的字符数。CNend
*
* @retval #EOK Success
* @retval #Other Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
extern errno_t memmove_s(void *dest, size_t dest_max, const void *src,
size_t count);
extern errno_t memmove_s(void *dest, size_t dest_max, const void *src, size_t count);
/**
* @ingroup iot_secure_c
* @brief Splits a string into substrings according to the specified separators.
CNcomment:将字符串按照指定的分隔符分割成子字符串。CNend
*
* @par 描述: Splits a string into substrings according to the specified
separators. CNcomment:将字符串按照指定的分隔符分割成子字符串。CNend
* @par 描述: Splits a string into substrings according to the specified separators.
CNcomment:将字符串按照指定的分隔符分割成子字符串。CNend
* @attention None
*
* @param token [IN] type #char *。 String to be
split.CNcomment:要分割的字符串。CNend
* @param delimit [IN] type #const char *。 String
separator.CNcomment:字符串分隔符。CNend
* @param context [IN] type #char* 。Position information after a call to
HI_strtok_s is saved. CNcomment:保存调用HI_strtok_s后的位置信息。CNend
* @param token [IN] type #char *。 String to be split.CNcomment:要分割的字符串。CNend
* @param delimit [IN] type #const char *。 String separator.CNcomment:字符串分隔符。CNend
* @param context [IN] type #char* 。Position information after a call to HI_strtok_s is saved.
CNcomment:保存调用HI_strtok_s后的位置信息。CNend
*
* @retval #char* Point to the next token.
CNcomment:指向在token中的下一个token。CNend
* @retval #char* Point to the next token. CNcomment:指向在token中的下一个token。CNend
* @retval #HI_NULL A specified substring is not found or an error occurs.
CNcomment:没有找到指定的子字符串或者发生错误。CNend
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
@@ -272,21 +234,17 @@ CNcomment:
CNcomment:将数据格式化输出到目的缓冲区。CNend
* @attention None
*
* @param dest [OUT] type #char *。 Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t。 Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param format [IN] type #const #char *。 Formatting control
string.CNcomment:格式化控制字符串。CNend
* @param dest [OUT] type #char *。 Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t。 Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param format [IN] type #const #char *。 Formatting control string.CNcomment:格式化控制字符串。CNend
* @param ... [IN] Optional parameter CNcomment:可选参数。CNend
*
* @retval #>=0 Return the number of bytes stored in dest, not counting the
terminating null character. CNcomment:返回存储在dest的字节数,不包括结束符CNend
* @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character.
CNcomment:返回存储在dest的字节数,不包括结束符CNend
* @retval #-1 Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
@@ -294,38 +252,30 @@ extern int sprintf_s(char *dest, size_t dest_max, const char *format, ...);
/**
* @ingroup iot_secure_c
* @brief Formats the data according to a specified length and outputs the data
to the destination buffer.
* @brief Formats the data according to a specified length and outputs the data to the destination buffer.
CNcomment:将数据按照指定长度格式化输出到目的缓冲区。CNend
*
* @par 描述: Formats the data according to a specified length and outputs the
data to the destination buffer.
* @par 描述: Formats the data according to a specified length and outputs the data to the destination buffer.
CNcomment:将数据按照指定长度格式化输出到目的缓冲区。CNend
* @attention None
*
* @param dest [OUT] type #char *。 Destination
buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t。 Size of the destination
buffer.CNcomment:目的缓冲区大小。CNend
* @param count [IN] type #size_t。 Number of formatted characters to be
output to the destination buffer.
* @param dest [OUT] type #char *。 Destination buffer.CNcomment:目的缓冲区。CNend
* @param dest_max [IN] type #size_t。 Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
* @param count [IN] type #size_t。 Number of formatted characters to be output to the destination buffer.
CNcomment:要输出到目的缓冲区的格式化字符个数。CNend
* @param format [IN] type #const #char *。 Formatting control
string.CNcomment:格式化控制字符串。CNend
* @param format [IN] type #const #char *。 Formatting control string.CNcomment:格式化控制字符串。CNend
* @param ... [IN] Optional parameter CNcomment:可选参数。CNend
*
* @retval #>=0 Return the number of bytes stored in dest, not counting the
terminating null character. CNcomment:返回存储在dest的字节数,不包括结束符CNend
* @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character.
CNcomment:返回存储在dest的字节数,不包括结束符CNend
* @retval #-1 Failure
*
* @par 依赖:
* @li hi_stdlib.h: This file declares the
APIs.CNcomment:该接口声明所在的头文件。CNend
* @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
* @see None
* @since Hi3861_V100R001C00
*/
extern int snprintf_s(char *dest, size_t dest_max, size_t count,
const char *format, ...);
extern int snprintf_s(char *dest, size_t dest_max, size_t count, const char *format, ...);
/*
* C库接口
@@ -347,3 +297,4 @@ extern UT_CONST char *strchr(const char *s, int c);
HI_END_HEADER
#endif /* __HI_STDLIB_H__ */
@@ -1,6 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights
* reserved. Description: file hi_types.h. Author: HiSilicon Create: 2019-4-3
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: file hi_types.h.
* Author: HiSilicon
* Create: 2019-4-3
*/
/**
* @file hi_types.h
@@ -13,8 +15,9 @@
#ifndef __HI_TYPES_H__
#define __HI_TYPES_H__
#include <hi_errno.h>
#include <hi_types_base.h>
#include <hi_errno.h>
/* linux错误码 */
#define OAL_SUCC 0
@@ -28,4 +31,6 @@
#define oal_reference(data) ((void)(data))
#endif // __HI_TYPES_H__
@@ -1,6 +1,7 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights
* reserved. Description: 数据类型定义和公用宏和结构定义 Author: Hisilicon
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: 数据类型定义和公用宏和结构定义
* Author: Hisilicon
* Create: 2019-06-02
*/
@@ -21,8 +22,7 @@
#endif
#if !defined(HI_HAVE_CROSS_COMPILER_DIAB_AS)
#if defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) || \
defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \
#if defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) || defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \
defined(HI_HAVE_CROSS_COMPILER_DIAB)
#undef HI_HAVE_CROSS_COMPILER
#define HI_HAVE_CROSS_COMPILER
@@ -71,16 +71,13 @@
#endif
#undef HI_SYS_DEBUG
#if (defined(PRODUCT_CFG_VERSION_DEBUG) || defined(SAL_HAVE_DEBUG_VERSION)) && \
!defined(SAL_HAVE_RELEASE_VERSION)
#if (defined(PRODUCT_CFG_VERSION_DEBUG) || defined(SAL_HAVE_DEBUG_VERSION)) && !defined(SAL_HAVE_RELEASE_VERSION)
# define HI_SYS_DEBUG
#endif
#if defined(PRODUCT_CFG_OS_WIN)
#pragma warning(disable : 4200) /* disable nonstandard extension used : \
zero-sized array in struct/union. */
#pragma warning(disable : 4214) /* allows bitfield structure members to be of \
any integral type. */
#pragma warning(disable:4200) /* disable nonstandard extension used : zero-sized array in struct/union. */
#pragma warning(disable:4214) /* allows bitfield structure members to be of any integral type. */
#pragma warning(disable:4201)
#pragma warning(disable:4514)
#pragma warning(disable:4127)
@@ -110,8 +107,7 @@ typedef unsigned int hi_size_t;
typedef int hi_ssize_t;
typedef int hi_offset_t;
/* for 64bits platform, intptr_t/uintptr_t should be defined as 64bits length.
*/
/* for 64bits platform, intptr_t/uintptr_t should be defined as 64bits length. */
typedef int intptr_t;
#if defined(__LITEOS__)
@@ -199,8 +195,7 @@ typedef __int64 hi_s64;
#define HI_PRVL HI_PRV HI_INLINE
#if defined(__ONEBUILDER__CROSS_COMPILER_PRODUCT_CONFIG__)
#if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \
defined(HI_HAVE_CROSS_COMPILER_ARM_GCC)
#if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || defined(HI_HAVE_CROSS_COMPILER_ARM_GCC)
# define hi_section(name_string) __attribute__ ((section(name_string)))
# define HI_PACKED __attribute__((packed))
# define HI_ALIGNED4 __attribute__ ((aligned (4)))
@@ -292,6 +287,7 @@ typedef __int64 hi_s64;
#define HI_NULL ((void *)0)
#endif
#define hi_array_count(x) (sizeof(x) / sizeof((x)[0]))
#if !defined(hi_unref_param) && !defined(HI_HAVE_CROSS_COMPILER_DIAB)
@@ -330,17 +326,13 @@ typedef __int64 hi_s64;
#define HI_CHAR_CR '\r' /* 0x0D */
#define HI_CHAR_LF '\n' /* 0x0A */
#define hi_tolower(x) \
((x) | 0x20) /* Works only for digits and letters, but small and fast */
#define hi_tolower(x) ((x) | 0x20) /* Works only for digits and letters, but small and fast */
#define hi_array_size(_array) (sizeof(_array) / sizeof((_array)[0]))
#define hi_makeu16(a, b) ((hi_u16)(((hi_u8)(a)) | ((hi_u16)((hi_u8)(b))) << 8))
#define hi_makeu32(a, b) \
((hi_u32)(((hi_u16)(a)) | ((hi_u32)((hi_u16)(b))) << 16))
#define hi_makeu64(a, b) \
((hi_u64)(((hi_u32)(a)) | ((hi_u64)((hi_u32)(b))) << 32))
#define hi_joinu32(a, b, c, d) \
((a) | ((hi_u32)(b) << 8) | ((hi_u32)(c) << 16) | ((hi_u32)(d) << 24))
#define hi_makeu32(a, b) ((hi_u32)(((hi_u16)(a)) | ((hi_u32)((hi_u16)(b))) << 16))
#define hi_makeu64(a, b) ((hi_u64)(((hi_u32)(a)) | ((hi_u64)((hi_u32)(b))) <<32))
#define hi_joinu32(a, b, c, d) ((a) | ((hi_u32)(b) << 8) | ((hi_u32)(c) << 16) | ((hi_u32)(d) << 24))
#define hi_hiu32(l) ((hi_u32)(((hi_u64)(l) >> 32) & 0xFFFFFFFF))
#define hi_lou32(l) ((hi_u32)(l))
@@ -356,19 +348,15 @@ typedef __int64 hi_s64;
#define hi_abs_sub(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
#define hi_byte_align(value, align) (((value) + (align) - 1) & (~((align) -1)))
#define hi_is_byte_align(value, align) (((hi_u32)(value) & ((align) - 1))== 0)
#define hi_inc_wraparound(value, round_size) \
++(value); \
(value) &= ((round_size)-1)
#define hi_dec_wraparound(value, round_size) \
--(value); \
(value) &= ((round_size)-1)
#define hi_inc_wraparound(value, round_size) ++(value); (value) &= ((round_size) - 1)
#define hi_dec_wraparound(value, round_size) --(value); (value) &= ((round_size) - 1)
#define hi_swap_byteorder_16(value) \
((((value)&0xFF) << 8) + (((value)&0xFF00) >> 8))
#define hi_swap_byteorder_16(value) ((((value) & 0xFF) << 8) + (((value) & 0xFF00) >> 8))
#define hi_swap_byteorder_32(value) \
((hi_u32)(((value) & 0x000000FF) << 24) + \
(hi_u32)(((value)&0x0000FF00) << 8) + (hi_u32)(((value)&0x00FF0000) >> 8) + \
(hi_u32)(((value) & 0x0000FF00) << 8) + \
(hi_u32)(((value) & 0x00FF0000) >> 8) + \
(hi_u32)(((value) & 0xFF000000) >> 24))
#define hi_swap_byteorder_64(value) \
@@ -384,10 +372,8 @@ typedef __int64 hi_s64;
#undef MIN_T
#define MIN_T hi_min
#define hi_make_identifier(a, b, c, d) \
hi_makeu32(hi_makeu16(a, b), hi_makeu16(c, d))
#define hi_make_ver16(spc, b) \
((hi_u16)(((hi_u8)((spc)&0x0F)) | ((hi_u16)((hi_u8)(b))) << 12))
#define hi_make_identifier(a, b, c, d) hi_makeu32(hi_makeu16(a, b), hi_makeu16(c, d))
#define hi_make_ver16(spc, b) ((hi_u16)(((hi_u8)((spc)&0x0F)) | ((hi_u16)((hi_u8)(b))) << 12))
#define hi_set_bit_i(val, n) ((val) |= (1 << (n)))
#define hi_clr_bit_i(val, n) ((val) &= ~(1 << (n)))
@@ -395,17 +381,13 @@ typedef __int64 hi_s64;
#define hi_is_bit_clr_i(val, n) (~((val) & (1 << (n))))
#define hi_switch_bit_i(val, n) ((val) ^= (1 << (n)))
#define hi_get_bit_i(val, n) (((val) >> (n)) & 1)
#define hi_reg_clr_bit_i(reg, n) \
((*(volatile unsigned int *)(reg)) &= ~(1 << (n)))
#define hi_reg_clr_bit_i(reg, n) ((*(volatile unsigned int *)(reg)) &= ~(1 << (n)))
#define hi_u8_bit_val(b7, b6, b5, b4, b3, b2, b1, b0) \
(((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | \
((b2) << 2) | ((b1) << 1) | ((b0) << 0))
(((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0))
#define hi_u16_bit_val(b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \
(hi_u16)(((b12) << 12) | ((b11) << 11) | ((b10) << 10) | ((b9) << 9) | \
((b8) << 8) | ((b7) << 7) | ((b6) << 6) | ((b5) << 5) | \
((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | \
((b0) << 0))
(hi_u16)(((b12) << 12) | ((b11) << 11) | ((b10) << 10) | ((b9) << 9) | ((b8) << 8) | ((b7) << 7) | \
((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0))
#if defined(__ONEBUILDER__CROSS_COMPILER_PRODUCT_CONFIG__)
#define HSO_ENUM HI_ALIGNED4 enum
@@ -424,10 +406,8 @@ typedef __int64 hi_s64;
#endif
/*****************************************************************************/
#define hi_set_u32_ptr_val(ptr, offset, val) \
(*((hi_u32 *)(((hi_u8 *)(ptr)) + (offset))) = (val))
#define hi_get_u32_ptr_val(ptr, offset) \
*((hi_u32 *)(((hi_u8 *)(ptr)) + (offset)))
#define hi_set_u32_ptr_val(ptr, offset, val) (*((hi_u32*)(((hi_u8*)(ptr)) + (offset))) = (val))
#define hi_get_u32_ptr_val(ptr, offset) *((hi_u32*)(((hi_u8*)(ptr)) + (offset)))
/*****************************************************************************/
/*****************************************************************************/
#define HI_SIZE_1K 1024
@@ -472,55 +452,34 @@ typedef __int64 hi_s64;
#define HALFWORD_BIT_WIDTH 16
/* 寄存器访问接口 */
#define hi_reg_write(addr, val) \
(*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define hi_reg_read(addr, val) \
((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define hi_reg_write32(addr, val) \
(*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define hi_reg_read32(addr, val) \
((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define hi_reg_write(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define hi_reg_read(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define hi_reg_write32(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define hi_reg_read32(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define hi_reg_read_val32(addr) (*(volatile unsigned int*)(uintptr_t)(addr))
#define hi_reg_setbitmsk(addr, msk) ((hi_reg_read_val32(addr)) |= (msk))
#define hi_reg_clrbitmsk(addr, msk) ((hi_reg_read_val32(addr)) &= ~(msk))
#define hi_reg_clrbit(addr, pos) \
((hi_reg_read_val32(addr)) &= ~((unsigned int)(1) << (pos)))
#define hi_reg_setbit(addr, pos) \
((hi_reg_read_val32(addr)) |= ((unsigned int)(1) << (pos)))
#define hi_reg_clrbits(addr, pos, bits) \
(hi_reg_read_val32(addr) &= ~((((unsigned int)1 << (bits)) - 1) << (pos)))
#define hi_reg_setbits(addr, pos, bits, val) \
(hi_reg_read_val32(addr) = \
(hi_reg_read_val32(addr) & \
(~((((unsigned int)1 << (bits)) - 1) << (pos)))) | \
#define hi_reg_clrbit(addr, pos) ((hi_reg_read_val32(addr)) &= ~((unsigned int)(1) << (pos)))
#define hi_reg_setbit(addr, pos) ((hi_reg_read_val32(addr)) |= ((unsigned int)(1) << (pos)))
#define hi_reg_clrbits(addr, pos, bits) (hi_reg_read_val32(addr) &= ~((((unsigned int)1 << (bits)) - 1) << (pos)))
#define hi_reg_setbits(addr, pos, bits, val) (hi_reg_read_val32(addr) = \
(hi_reg_read_val32(addr) & (~((((unsigned int)1 << (bits)) - 1) << (pos)))) | \
((unsigned int)((val) & (((unsigned int)1 << (bits)) - 1)) << (pos)))
#define hi_reg_getbits(addr, pos, bits) \
((hi_reg_read_val32(addr) >> (pos)) & (((unsigned int)1 << (bits)) - 1))
#define hi_reg_getbits(addr, pos, bits) ((hi_reg_read_val32(addr) >> (pos)) & (((unsigned int)1 << (bits)) - 1))
#define hi_reg_write16(addr, val) \
(*(volatile unsigned short *)(uintptr_t)(addr) = (val))
#define hi_reg_read16(addr, val) \
((val) = *(volatile unsigned short *)(uintptr_t)(addr))
#define hi_reg_write16(addr, val) (*(volatile unsigned short *)(uintptr_t)(addr) = (val))
#define hi_reg_read16(addr, val) ((val) = *(volatile unsigned short *)(uintptr_t)(addr))
#define hi_reg_read_val16(addr) (*(volatile unsigned short*)(uintptr_t)(addr))
#define hi_reg_clrbit16(addr, pos) \
((hi_reg_read_val16(addr)) &= ~((unsigned short)(1) << (pos)))
#define hi_reg_setbit16(addr, pos) \
((hi_reg_read_val16(addr)) |= ((unsigned short)(1) << (pos)))
#define hi_reg_clrbits16(addr, pos, bits) \
(hi_reg_read_val16(addr) &= ~((((unsigned short)1 << (bits)) - 1) << (pos)))
#define hi_reg_setbits16(addr, pos, bits, val) \
(hi_reg_read_val16(addr) = \
(hi_reg_read_val16(addr) & \
(~((((unsigned short)1 << (bits)) - 1) << (pos)))) | \
((unsigned short)((val) & (((unsigned short)1 << (bits)) - 1)) \
<< (pos)))
#define hi_reg_getbits16(addr, pos, bits) \
((hi_reg_read_val16(addr) >> (pos)) & (((unsigned short)1 << (bits)) - 1))
#define hi_reg_clrbit16(addr, pos) ((hi_reg_read_val16(addr)) &= ~((unsigned short)(1) << (pos)))
#define hi_reg_setbit16(addr, pos) ((hi_reg_read_val16(addr)) |= ((unsigned short)(1) << (pos)))
#define hi_reg_clrbits16(addr, pos, bits) (hi_reg_read_val16(addr) &= ~((((unsigned short)1 << (bits)) - 1) << (pos)))
#define hi_reg_setbits16(addr, pos, bits, val) (hi_reg_read_val16(addr) = \
(hi_reg_read_val16(addr) & (~((((unsigned short)1 << (bits)) - 1) << (pos)))) | \
((unsigned short)((val) & (((unsigned short)1 << (bits)) - 1)) << (pos)))
#define hi_reg_getbits16(addr, pos, bits) ((hi_reg_read_val16(addr) >> (pos)) & (((unsigned short)1 << (bits)) - 1))
#define reg_write32(addr, val) \
(*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define reg_read32(addr, val) \
((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define reg_write32(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val))
#define reg_read32(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr))
#define reg_read_val(addr) (*(volatile unsigned *)(uintptr_t)(addr))
#ifndef BSP_RAM_TEXT_SECTION
@@ -573,3 +532,4 @@ typedef __int64 hi_s64;
#define HI_SYS_WAIT_FOREVER 0xFFFFFFFF
#endif /* __HI_TYPES__BASE_H__ */
@@ -1,24 +1,26 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/netlink.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "securec.h"
/*****************************************************************************
2 宏定义、全局变量
@@ -42,7 +44,8 @@ static netlink_monitor_s *g_channel_monitor = HI_NULL;
/*****************************************************************************
4 函数实现
*****************************************************************************/
static hi_void *hi_channel_host_thread(hi_void *args) {
static hi_void *hi_channel_host_thread(hi_void *args)
{
hi_s32 rev_len;
hi_s32 payload_len;
hi_char msg[SYSTEM_CMD_SIZE];
@@ -72,8 +75,7 @@ static hi_void *hi_channel_host_thread(hi_void *args) {
nlh = (struct nlmsghdr *)msg;
payload_len = rev_len - NLMSG_HDRLEN;
sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type,
payload_len, rev_len, NLMSG_HDRLEN);
sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, payload_len, rev_len, NLMSG_HDRLEN);
if (g_channel_monitor->rx_func != HI_NULL) {
g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len);
}
@@ -82,7 +84,8 @@ static hi_void *hi_channel_host_thread(hi_void *args) {
return HI_NULL;
}
hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) {
hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func)
{
if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) {
sample_log_print("hi_channel_register_rx_cb is fail\n");
return HI_FAILURE;
@@ -92,7 +95,8 @@ hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) {
return HI_SUCCESS;
}
hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) {
hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len)
{
int ret;
struct nlmsghdr *nlh = HI_NULL;
struct sockaddr_nl daddr;
@@ -126,7 +130,8 @@ hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) {
return 0;
}
hi_s32 hi_channel_init(hi_void) {
hi_s32 hi_channel_init(hi_void)
{
hi_s32 ret;
struct sockaddr_nl saddr = {0};
@@ -141,11 +146,9 @@ hi_s32 hi_channel_init(hi_void) {
}
g_channel_terminate = HI_FALSE;
(hi_void) memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0,
sizeof(netlink_monitor_s));
(hi_void)memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, sizeof(netlink_monitor_s));
g_channel_monitor->skfd = -1;
g_channel_monitor->skfd =
socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID);
g_channel_monitor->skfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID);
if (g_channel_monitor->skfd == -1) {
sample_log_print("create is fail:%s\n", strerror(errno));
goto deinit;
@@ -160,8 +163,7 @@ hi_s32 hi_channel_init(hi_void) {
goto deinit;
}
ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL,
hi_channel_host_thread, HI_NULL);
ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, hi_channel_host_thread, HI_NULL);
if (ret != HI_SUCCESS) {
goto deinit;
}
@@ -180,7 +182,8 @@ deinit:
return HI_FAILURE;
}
hi_s32 hi_channel_deinit(hi_void) {
hi_s32 hi_channel_deinit(hi_void)
{
if (g_channel_monitor == HI_NULL) {
sample_log_print("hi_channel_deinit is fail\n");
return HI_FAILURE;
@@ -205,3 +208,4 @@ hi_s32 hi_channel_deinit(hi_void) {
return HI_SUCCESS;
}
@@ -1,6 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample link file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample link file.
* Author: Hisilicon
* Create: 2020-09-09
*/
#ifndef HISI_LINK_H
@@ -1,20 +1,21 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights
* reserved. Description: sample common file. Author: Hisilicon Create:
* 2018-08-04
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved.
* Description: sample common file.
* Author: Hisilicon
* Create: 2018-08-04
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "securec.h"
#include "hichannel_host_comm.h"
#include "hi_base.h"
#include "securec.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*****************************************************************************
2 宏定义、全局变量
@@ -24,23 +25,20 @@ static sample_cmd_common g_cmd_com = {0};
/*****************************************************************************
4 函数实现
*****************************************************************************/
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) {
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset)
{
const hi_char *pc_cmd_copy = HI_NULL;
hi_u32 pos = 0;
if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) ||
(pul_cmd_offset == HI_NULL)) {
sample_log_print(
"pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", pc_cmd,
pc_arg, pul_cmd_offset);
if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || (pul_cmd_offset == HI_NULL)) {
sample_log_print("pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", \
pc_cmd, pc_arg, pul_cmd_offset);
return HI_FAILURE;
}
pc_cmd_copy = pc_cmd;
while (*pc_cmd_copy != '\0' &&
!((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) {
while (*pc_cmd_copy != '\0' && !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) {
if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) {
++pc_cmd_copy;
continue;
@@ -67,8 +65,8 @@ hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
return HI_SUCCESS;
}
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
hi_void *msg) {
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg)
{
hi_u8 cmd_id;
hi_u32 off_set = 0;
hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0};
@@ -77,8 +75,7 @@ hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
return HI_FAILURE;
}
if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) !=
HI_SUCCESS) {
if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != HI_SUCCESS) {
return HI_FAILURE;
}
cmd += (off_set + 1);
@@ -96,8 +93,8 @@ hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
return HI_FAILURE;
}
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
hi_void *msg) {
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg)
{
hi_char *pcmd = HI_NULL;
hi_char *pcmd_tmp = HI_NULL;
if (len > SAMPLE_CMD_MAX_LEN) {
@@ -126,7 +123,8 @@ hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
return HI_SUCCESS;
}
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) {
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num)
{
hi_u32 i;
sample_cmd_common *tmp_list = HI_NULL;
tmp_list = (sample_cmd_common *)&g_cmd_com;
@@ -140,3 +138,4 @@ hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) {
tmp_list->count = num;
return HI_SUCCESS;
}
@@ -1,7 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights
* reserved. Description: sample common file. Author: Hisilicon Create:
* 2018-08-04
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved.
* Description: sample common file.
* Author: Hisilicon
* Create: 2018-08-04
*/
#ifndef __SAMPLE_COMMON_H__
@@ -19,8 +20,7 @@
/*****************************************************************************
3 枚举、结构体定义
*****************************************************************************/
typedef hi_s32 (*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg);
typedef hi_s32(*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
typedef struct {
hi_char *cmd_name; /* 命令字符串 */
sample_cmd_func func; /* 命令对应处理函数 */
@@ -34,15 +34,13 @@ typedef struct {
/*****************************************************************************
4 函数声明
*****************************************************************************/
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset);
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset);
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
hi_void *msg);
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg);
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
hi_void *msg);
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg);
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num);
#endif
@@ -1,33 +1,33 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "hichannel_host_comm.h"
#include "securec.h"
/*****************************************************************************
2 宏定义、全局变量
*****************************************************************************/
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg);
static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg);
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
static const sample_cmd_entry_stru g_sample_cmd[] = {
{"help", sample_help_cmd_process},
@@ -84,19 +84,19 @@ typedef struct {
static hi_bool g_terminate = HI_FALSE;
static sample_link_s *g_sample_link = HI_NULL;
static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac", "cmd_get_ip",
"cmd_set_filter"};
static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac", "cmd_get_ip", "cmd_set_filter"};
/*****************************************************************************
4 函数实现
*****************************************************************************/
static hi_void sample_usage(hi_void) {
static hi_void sample_usage(hi_void)
{
printf("\nUsage:\n");
printf("\tsample_cli quit quit sample_ap\n");
printf("\tsample_cli help show this message\n");
}
hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg) {
hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_message_s *msg = (sample_message_s *)pmsg;
msg->what = SAMPLE_CMD_IOCTL;
@@ -106,8 +106,8 @@ hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
return HI_SUCCESS;
}
hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg) {
hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_unused(param);
sample_unused(len);
@@ -116,8 +116,8 @@ hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
return HI_SUCCESS;
}
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg) {
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_unused(param);
sample_unused(len);
@@ -126,7 +126,8 @@ static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
return HI_SUCCESS;
}
static hi_void sample_cleanup(hi_void) {
static hi_void sample_cleanup(hi_void)
{
sample_log_print("sample_cleanup enter\n");
if (g_sample_link->sock_thread) {
pthread_cancel(g_sample_link->sock_thread);
@@ -146,22 +147,26 @@ static hi_void sample_cleanup(hi_void) {
}
}
static hi_void sample_terminate(hi_s32 sig) {
static hi_void sample_terminate(hi_s32 sig)
{
sample_unused(sig);
sample_cleanup();
g_terminate = HI_TRUE;
_exit(0);
}
static hi_void sample_power(hi_s32 sig) { sample_unused(sig); }
static hi_void sample_power(hi_s32 sig)
{
sample_unused(sig);
}
static hi_s32 sample_wlan_init_up(hi_void) {
static hi_s32 sample_wlan_init_up(hi_void)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -175,7 +180,8 @@ static hi_s32 sample_wlan_init_up(hi_void) {
return HI_SUCCESS;
}
static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
@@ -184,8 +190,7 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -196,11 +201,9 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"ifconfig %s hw ether %x:%x:%x:%x:%x:%x",
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %x:%x:%x:%x:%x:%x",
/* 2, 3, 4, 5: MAC地址的第2, 3, 4, 5 Byte */
SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2],
mac_addr[3], mac_addr[4], mac_addr[5]) == -1) {
SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -211,8 +214,7 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -227,19 +229,18 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
return HI_SUCCESS;
}
static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) {
static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
sample_unused(len);
if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) &&
(ip_addr[3] == 0)) { /* 1 2 3 ipaddr */
if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */
return HI_SUCCESS;
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -254,8 +255,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) {
"ifconfig %s %d.%d.%d.%d netmask %d.%d.%d.%d",
SYSTEM_NETDEV_NAME,
/* 2, 3, 4, 5, 6, 7: 分别为IP地址的第2, 3, 4, 5, 6, 7 Byte */
ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], ip_addr[4],
ip_addr[5], ip_addr[6], ip_addr[7]) == -1) {
ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], ip_addr[4], ip_addr[5], ip_addr[6], ip_addr[7]) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -267,8 +267,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -283,13 +282,13 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) {
return HI_SUCCESS;
}
static hi_void set_lo_ipaddr(hi_void) {
static hi_void set_lo_ipaddr(hi_void)
{
hi_s32 results;
hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */
hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL};
results = sprintf_s(
cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */
results = sprintf_s(cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */
spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */
if (results < EOK) {
sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n");
@@ -299,7 +298,8 @@ static hi_void set_lo_ipaddr(hi_void) {
system(cmd);
}
static hi_s32 sample_sock_create(hi_void) {
static hi_s32 sample_sock_create(hi_void)
{
if (g_sample_link == HI_NULL) {
return HI_FAILURE;
}
@@ -315,8 +315,7 @@ static hi_s32 sample_sock_create(hi_void) {
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SOCK_PORT);
if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr,
sizeof(servaddr)) == -1) {
if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
sample_log_print("error:%s", strerror(errno));
return HI_FAILURE;
}
@@ -324,8 +323,8 @@ static hi_s32 sample_sock_create(hi_void) {
return HI_SUCCESS;
}
static hi_s32 sample_enqueue(struct squeue *pqueue,
const sample_message_s *element) {
static hi_s32 sample_enqueue(struct squeue *pqueue, const sample_message_s *element)
{
struct snode *pnew = HI_NULL;
if (pqueue == HI_NULL || element == HI_NULL) {
@@ -351,7 +350,8 @@ static hi_s32 sample_enqueue(struct squeue *pqueue,
return HI_SUCCESS;
}
static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) {
static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element)
{
struct snode *p = HI_NULL;
if (pqueue == HI_NULL || element == HI_NULL) {
@@ -374,7 +374,8 @@ static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) {
return HI_SUCCESS;
}
static hi_void *sample_sock_thread(hi_void *args) {
static hi_void *sample_sock_thread(hi_void *args)
{
hi_char link_buf[SOCK_BUF_MAX];
ssize_t recvbytes;
sample_message_s message;
@@ -383,11 +384,9 @@ static hi_void *sample_sock_thread(hi_void *args) {
sample_unused(args);
while (1) {
/* 安全编程规则6.6例外(1)
* 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
/* 安全编程规则6.6例外(1) 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
(hi_void)memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf));
/* 安全编程规则6.6例外(1)
* 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
/* 安全编程规则6.6例外(1) 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
(hi_void)memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen);
recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0,
@@ -402,15 +401,13 @@ static hi_void *sample_sock_thread(hi_void *args) {
}
}
if (sample_sock_cmd_entry(g_sample_link, link_buf, recvbytes,
(hi_void *)&message) != HI_SUCCESS) {
if (sample_sock_cmd_entry(g_sample_link, link_buf, recvbytes, (hi_void *)&message) != HI_SUCCESS) {
sample_log_print("sample_str_cmd_process entry\n");
sample_str_cmd_process(g_sample_link, link_buf, recvbytes,
(hi_void *)&message);
sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message);
}
if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT,
(const struct sockaddr *)&clientaddr, addrlen) == -1) {
if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, (const struct sockaddr *)&clientaddr,
addrlen) == -1) {
sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd);
}
@@ -422,7 +419,8 @@ static hi_void *sample_sock_thread(hi_void *args) {
}
}
void sample_link_rec_cb(unsigned char *msg_data, int len) {
void sample_link_rec_cb(unsigned char *msg_data, int len)
{
hi_s32 ret;
hi_s32 index;
@@ -447,7 +445,8 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
}
}
void main_process(void) {
void main_process(void)
{
/* main loop */
while (!g_terminate) {
sample_message_s message;
@@ -456,8 +455,7 @@ void main_process(void) {
pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut);
}
pthread_mutex_unlock(&g_sample_link->mut);
sample_log_print("=====SAMPLE LOOP RECIEVE MSG:%d LEN:%d=====\n",
message.what, message.len);
sample_log_print("=====SAMPLE LOOP RECIEVE MSG:%d LEN:%d=====\n", message.what, message.len);
fflush(stdout);
switch (message.what) {
@@ -478,7 +476,8 @@ void main_process(void) {
}
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
hi_s32 ret;
sample_unused(argc);
sample_unused(argv);
@@ -493,8 +492,7 @@ int main(int argc, char *argv[]) {
return -1;
}
(void)memset_s(g_sample_link, sizeof(sample_link_s), 0,
sizeof(sample_link_s));
(void)memset_s(g_sample_link, sizeof(sample_link_s), 0, sizeof(sample_link_s));
pthread_mutex_init(&g_sample_link->mut, HI_NULL);
pthread_cond_init(&g_sample_link->cond, HI_NULL);
@@ -507,11 +505,9 @@ int main(int argc, char *argv[]) {
}
hi_channel_register_rx_cb(sample_link_rec_cb);
hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC],
(hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC]));
hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC]));
if (sample_register_cmd((sample_cmd_entry_stru *)&g_sample_cmd,
SAMPLE_CMD_NUM) != HI_SUCCESS) {
if (sample_register_cmd((sample_cmd_entry_stru *)&g_sample_cmd, SAMPLE_CMD_NUM) != HI_SUCCESS) {
sample_log_print("register wlan cmd is fail\n");
goto link_out;
}
@@ -521,8 +517,7 @@ int main(int argc, char *argv[]) {
goto link_out;
}
ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread,
HI_NULL);
ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, HI_NULL);
if (ret != HI_SUCCESS) {
sample_log_print("create sock thread is fail\n");
goto link_out;
@@ -534,3 +529,4 @@ link_out:
sample_cleanup();
return 0;
}
+998 -675
View File
File diff suppressed because it is too large Load Diff
+84 -172
View File
@@ -24,27 +24,23 @@
#define cJSON__h
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#if !defined(__WINDOWS__) && \
(defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid
issues where we are being called from a project with a different default calling
convention. For windows you have 3 define options:
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever
dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you
want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you
want to dllimport symbol
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar
behavior by
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
@@ -52,18 +48,15 @@ or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way
CJSON_EXPORT_SYMBOLS does
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and
* header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
!defined(CJSON_EXPORT_SYMBOLS)
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
@@ -78,8 +71,7 @@ CJSON_EXPORT_SYMBOLS does
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \
defined(CJSON_API_VISIBILITY)
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
@@ -108,13 +100,12 @@ CJSON_EXPORT_SYMBOLS does
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON {
/* next/prev allow you to walk array/object chains. Alternatively, use
* GetArraySize/GetArrayItem/GetObjectItem */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of
* the items in the array/object. */
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
@@ -127,23 +118,21 @@ typedef struct cJSON {
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of
* subitems of an object. */
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks {
/* malloc/free are CDECL on Windows regardless of the default calling
* convention of the compiler, so ensure the hooks allow passing those
* functions directly. */
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse
* them. This is to prevent stack overflows. */
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
@@ -154,64 +143,36 @@ CJSON_PUBLIC(const char *) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from
* all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib
* free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is
* cJSON_PrintPreallocated, where the caller has full responsibility of the
* buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate.
*/
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null
* terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then
* return_parse_end will contain a pointer to the error so will match
* cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithOpts(const char *value, const char **return_parse_end,
cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length,
const char **return_parse_end,
cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
* at the final size. guessing well reduces reallocation. fmt=0 gives
* unformatted, =1 gives formatted */
CJSON_PUBLIC(char *)
cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with
* given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will
* use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool)
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length,
const cJSON_bool format);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if
* unsuccessful. */
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *)
cJSON_GetObjectItem(const cJSON *const object, const char *const string);
CJSON_PUBLIC(cJSON *)
cJSON_GetObjectItemCaseSensitive(const cJSON *const object,
const char *const string);
CJSON_PUBLIC(cJSON_bool)
cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error.
* You'll probably need to look a few chars back to make sense of it. Defined
* when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
@@ -251,126 +212,77 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the
* number array, otherwise array access will be out of bounds.*/
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *)
cJSON_CreateStringArray(const char *const *strings, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and
* will definitely survive the cJSON object. WARNING: When this function was
* used, make sure to always check that (item->type & cJSON_StringIsConst) is
* zero before writing to `item->string` */
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you
* want to add an existing cJSON to a new cJSON, but don't want to corrupt your
* existing cJSON. */
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool)
cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *)
cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool)
cJSON_InsertItemInArray(
cJSON *array, int which,
cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item,
cJSON *replacement);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool)
cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string,
cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new
* memory that will need to be released. With recurse!=0, it will duplicate any
* children connected to the item. The item->next and ->prev pointers are always
* zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or
* invalid, they will be considered unequal. case_sensitive determines if object
* keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool)
cJSON_Compare(const cJSON *const a, const cJSON *const b,
const cJSON_bool case_sensitive);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from
* strings. The input pointer json cannot point to a read-only address area,
* such as a string constant, but should point to a readable and writable adress
* area. */
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON *)
cJSON_AddNullToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddTrueToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddFalseToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddBoolToObject(cJSON *const object, const char *const name,
const cJSON_bool boolean);
CJSON_PUBLIC(cJSON *)
cJSON_AddNumberToObject(cJSON *const object, const char *const name,
const double number);
CJSON_PUBLIC(cJSON *)
cJSON_AddStringToObject(cJSON *const object, const char *const name,
const char *const string);
CJSON_PUBLIC(cJSON *)
cJSON_AddRawToObject(cJSON *const object, const char *const name,
const char *const raw);
CJSON_PUBLIC(cJSON *)
cJSON_AddObjectToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *)
cJSON_AddArrayToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble
* too. */
#define cJSON_SetIntValue(object, number) \
((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) \
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type
* of object is cJSON_String */
CJSON_PUBLIC(char *)
cJSON_SetValuestring(cJSON *object, const char *valuestring);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) \
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
element = element->next)
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with
* cJSON_InitHooks */
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
+26 -22
View File
@@ -1,24 +1,26 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/netlink.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "securec.h"
/*****************************************************************************
2 宏定义、全局变量
@@ -42,7 +44,8 @@ static netlink_monitor_s *g_channel_monitor = HI_NULL;
/*****************************************************************************
4 函数实现
*****************************************************************************/
static hi_void *hi_channel_host_thread(hi_void *args) {
static hi_void *hi_channel_host_thread(hi_void *args)
{
hi_s32 rev_len;
hi_s32 payload_len;
hi_char msg[SYSTEM_CMD_SIZE];
@@ -72,8 +75,7 @@ static hi_void *hi_channel_host_thread(hi_void *args) {
nlh = (struct nlmsghdr *)msg;
payload_len = rev_len - NLMSG_HDRLEN;
sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type,
payload_len, rev_len, NLMSG_HDRLEN);
sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, payload_len, rev_len, NLMSG_HDRLEN);
if (g_channel_monitor->rx_func != HI_NULL) {
g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len);
}
@@ -82,7 +84,8 @@ static hi_void *hi_channel_host_thread(hi_void *args) {
return HI_NULL;
}
hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) {
hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func)
{
if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) {
sample_log_print("hi_channel_register_rx_cb is fail\n");
return HI_FAILURE;
@@ -92,7 +95,8 @@ hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) {
return HI_SUCCESS;
}
hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) {
hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len)
{
int ret;
struct nlmsghdr *nlh = HI_NULL;
struct sockaddr_nl daddr;
@@ -126,7 +130,8 @@ hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) {
return 0;
}
hi_s32 hi_channel_init(hi_void) {
hi_s32 hi_channel_init(hi_void)
{
hi_s32 ret;
struct sockaddr_nl saddr = {0};
@@ -141,11 +146,9 @@ hi_s32 hi_channel_init(hi_void) {
}
g_channel_terminate = HI_FALSE;
(hi_void) memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0,
sizeof(netlink_monitor_s));
(hi_void)memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, sizeof(netlink_monitor_s));
g_channel_monitor->skfd = -1;
g_channel_monitor->skfd =
socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID);
g_channel_monitor->skfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID);
if (g_channel_monitor->skfd == -1) {
sample_log_print("create is fail:%s\n", strerror(errno));
goto deinit;
@@ -160,8 +163,7 @@ hi_s32 hi_channel_init(hi_void) {
goto deinit;
}
ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL,
hi_channel_host_thread, HI_NULL);
ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, hi_channel_host_thread, HI_NULL);
if (ret != HI_SUCCESS) {
goto deinit;
}
@@ -180,7 +182,8 @@ deinit:
return HI_FAILURE;
}
hi_s32 hi_channel_deinit(hi_void) {
hi_s32 hi_channel_deinit(hi_void)
{
if (g_channel_monitor == HI_NULL) {
sample_log_print("hi_channel_deinit is fail\n");
return HI_FAILURE;
@@ -205,3 +208,4 @@ hi_s32 hi_channel_deinit(hi_void) {
return HI_SUCCESS;
}
+4 -2
View File
@@ -1,6 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample link file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample link file.
* Author: Hisilicon
* Create: 2020-09-09
*/
#ifndef HISI_LINK_H
+24 -25
View File
@@ -1,20 +1,21 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights
* reserved. Description: sample common file. Author: Hisilicon Create:
* 2018-08-04
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved.
* Description: sample common file.
* Author: Hisilicon
* Create: 2018-08-04
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "securec.h"
#include "hichannel_host_comm.h"
#include "hi_base.h"
#include "securec.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*****************************************************************************
2 宏定义、全局变量
@@ -24,23 +25,20 @@ static sample_cmd_common g_cmd_com = {0};
/*****************************************************************************
4 函数实现
*****************************************************************************/
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) {
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset)
{
const hi_char *pc_cmd_copy = HI_NULL;
hi_u32 pos = 0;
if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) ||
(pul_cmd_offset == HI_NULL)) {
sample_log_print(
"pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", pc_cmd,
pc_arg, pul_cmd_offset);
if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || (pul_cmd_offset == HI_NULL)) {
sample_log_print("pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", \
pc_cmd, pc_arg, pul_cmd_offset);
return HI_FAILURE;
}
pc_cmd_copy = pc_cmd;
while (*pc_cmd_copy != '\0' &&
!((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) {
while (*pc_cmd_copy != '\0' && !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) {
if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) {
++pc_cmd_copy;
continue;
@@ -67,8 +65,8 @@ hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
return HI_SUCCESS;
}
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
hi_void *msg) {
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg)
{
hi_u8 cmd_id;
hi_u32 off_set = 0;
hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0};
@@ -77,8 +75,7 @@ hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
return HI_FAILURE;
}
if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) !=
HI_SUCCESS) {
if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != HI_SUCCESS) {
return HI_FAILURE;
}
cmd += (off_set + 1);
@@ -96,8 +93,8 @@ hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
return HI_FAILURE;
}
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
hi_void *msg) {
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg)
{
hi_char *pcmd = HI_NULL;
hi_char *pcmd_tmp = HI_NULL;
if (len > SAMPLE_CMD_MAX_LEN) {
@@ -126,7 +123,8 @@ hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
return HI_SUCCESS;
}
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) {
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num)
{
hi_u32 i;
sample_cmd_common *tmp_list = HI_NULL;
tmp_list = (sample_cmd_common *)&g_cmd_com;
@@ -140,3 +138,4 @@ hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) {
tmp_list->count = num;
return HI_SUCCESS;
}
+9 -11
View File
@@ -1,7 +1,8 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights
* reserved. Description: sample common file. Author: Hisilicon Create:
* 2018-08-04
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved.
* Description: sample common file.
* Author: Hisilicon
* Create: 2018-08-04
*/
#ifndef __SAMPLE_COMMON_H__
@@ -19,8 +20,7 @@
/*****************************************************************************
3 枚举、结构体定义
*****************************************************************************/
typedef hi_s32 (*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg);
typedef hi_s32(*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
typedef struct {
hi_char *cmd_name; /* 命令字符串 */
sample_cmd_func func; /* 命令对应处理函数 */
@@ -57,15 +57,13 @@ typedef struct {
/*****************************************************************************
4 函数声明
*****************************************************************************/
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg,
hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset);
hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset);
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len,
hi_void *msg);
hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg);
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len,
hi_void *msg);
hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg);
hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num);
#endif
+70 -92
View File
@@ -1,26 +1,26 @@
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "hichannel_host_comm.h"
#include "securec.h"
#include "cJSON.h"
#define VLINK_SEND_MSG_MAX_LEN (SYSTEM_CMD_SIZE - 4)
#define VLINK_SEND_MSG_HEAD_LEN 3
hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char *ssid, hi_char *key,
hi_char *sendmsg, hi_u32 *sendmsg_len) {
hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char* ssid, hi_char* key, hi_char* sendmsg, hi_u32 *sendmsg_len)
{
cJSON * pJsonRoot = NULL;
cJSON *pJson = NULL;
hi_u32 datalen = 0;
@@ -35,9 +35,7 @@ hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char *ssid, hi_char *key,
pJson = cJSON_Print(pJsonRoot);
sample_log_print(
"vlink_hi_channel_netcfg_info-----------pJson[%s]-len[%d]--\n", pJson,
strlen(pJson));
sample_log_print("vlink_hi_channel_netcfg_info-----------pJson[%s]-len[%d]--\n", pJson, strlen(pJson));
datalen = strlen(pJson);
*sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
@@ -48,9 +46,7 @@ hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char *ssid, hi_char *key,
sendcmdbuf[1] = (datalen >> 8) & 0xFF;
sendcmdbuf[2] = datalen & 0xFF;
sample_log_print(
"vlink_hi_channel_netcfg_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_netcfg_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen);
free(pJson);
@@ -61,7 +57,8 @@ hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char *ssid, hi_char *key,
return 0;
}
hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -75,9 +72,7 @@ hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getmac_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getmac_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getmac_info--send fail\n");
@@ -88,7 +83,8 @@ hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getip_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getip_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -102,9 +98,7 @@ hi_u32 vlink_hi_channel_cmd_getip_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getip_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getip_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getip_info--send fail\n");
@@ -115,7 +109,8 @@ hi_u32 vlink_hi_channel_cmd_getip_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char *device) {
hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char* device)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
cJSON * pJsonRoot = NULL;
@@ -128,8 +123,7 @@ hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char *device) {
cJSON_AddStringToObject(pJsonRoot, "device", device);
pJson = cJSON_Print(pJsonRoot);
sample_log_print("vlink_hi_channel_cmd_setfilter_info-------pJson[%s]---\n",
pJson);
sample_log_print("vlink_hi_channel_cmd_setfilter_info-------pJson[%s]---\n", pJson);
datalen = strlen(pJson);
@@ -141,9 +135,7 @@ hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char *device) {
sendcmdbuf[1] = (datalen >> 8) & 0xFF;
sendcmdbuf[2] = datalen & 0xFF;
sample_log_print("vlink_hi_channel_cmd_setfilter_info-------sendcmdbuf-[%02X]"
"-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_setfilter_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen);
free(pJson);
@@ -159,8 +151,8 @@ hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char *device) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char *serverip, hi_char *port,
hi_char *expire) {
hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char* serverip, hi_char* port, hi_char* expire)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
cJSON * pJsonRoot = NULL;
@@ -175,8 +167,7 @@ hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char *serverip, hi_char *port,
cJSON_AddStringToObject(pJsonRoot, "expire", expire);
pJson = cJSON_Print(pJsonRoot);
sample_log_print("vlink_hi_channel_cmd_keeplive_info-------pJson[%s]---\n",
pJson);
sample_log_print("vlink_hi_channel_cmd_keeplive_info-------pJson[%s]---\n", pJson);
datalen = strlen(pJson);
@@ -188,9 +179,7 @@ hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char *serverip, hi_char *port,
sendcmdbuf[1] = (datalen >> 8) & 0xFF;
sendcmdbuf[2] = datalen & 0xFF;
sample_log_print("vlink_hi_channel_cmd_keeplive_info-------sendcmdbuf-[%02X]-"
"[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_keeplive_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen);
free(pJson);
@@ -207,7 +196,9 @@ hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char *serverip, hi_char *port,
return 0;
}
hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -220,9 +211,7 @@ hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void) {
sendcmdbuf[2] = datalen & 0xFF;
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_deepsleep_info-------sendcmdbuf-[%02X]"
"-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_deepsleep_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_deepsleep_info--send fail\n");
@@ -233,7 +222,8 @@ hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_startap_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_startap_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -246,9 +236,7 @@ hi_u32 vlink_hi_channel_cmd_startap_info(hi_void) {
sendcmdbuf[2] = datalen & 0xFF;
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_startap_info-------sendcmdbuf-[%02X]-["
"%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_startap_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_startap_info--send fail\n");
@@ -259,7 +247,8 @@ hi_u32 vlink_hi_channel_cmd_startap_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_startota(hi_void) {
hi_u32 vlink_hi_channel_cmd_startota(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -273,9 +262,7 @@ hi_u32 vlink_hi_channel_cmd_startota(hi_void) {
sendcmdbuf[2] = datalen & 0xFF;
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print(
"vlink_hi_channel_cmd_startota-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_startota-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sleep(2);
@@ -288,7 +275,9 @@ hi_u32 vlink_hi_channel_cmd_startota(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -303,9 +292,7 @@ hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getrssi_info-------sendcmdbuf-[%02X]-["
"%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getrssi_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getrssi_info--send fail\n");
@@ -315,7 +302,8 @@ hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -328,9 +316,7 @@ hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getversion_info-------sendcmdbuf-[%"
"02X]-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getversion_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getversion_info--send fail\n");
@@ -340,7 +326,8 @@ hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -353,9 +340,7 @@ hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getwakecode_info-------sendcmdbuf-[%"
"02X]-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getwakecode_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getwakecode_info--send fail\n");
@@ -365,7 +350,8 @@ hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -378,9 +364,7 @@ hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_factoryreset_info-------sendcmdbuf-[%"
"02X]-[%02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_factoryreset_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_factoryreset_info--send fail\n");
@@ -390,7 +374,8 @@ hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -403,9 +388,7 @@ hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getpir_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getpir_info--send fail\n");
@@ -415,7 +398,8 @@ hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) {
hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
@@ -436,8 +420,7 @@ hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) {
pJson = cJSON_Print(pJsonRoot);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n",
pJson);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", pJson);
datalen = strlen(pJson);
@@ -449,9 +432,7 @@ hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) {
sendcmdbuf[1] = (datalen >> 8) & 0xFF;
sendcmdbuf[2] = datalen & 0xFF;
sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen);
free(pJson);
@@ -467,7 +448,9 @@ hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void)
{
#define TUYA_IP "42.192.35.108"
#define TUYA_PORT 443
@@ -490,8 +473,7 @@ hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) {
pJson = cJSON_Print(pJsonRoot);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n",
pJson);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", pJson);
datalen = strlen(pJson);
@@ -503,9 +485,7 @@ hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) {
sendcmdbuf[1] = (datalen >> 8) & 0xFF;
sendcmdbuf[2] = datalen & 0xFF;
sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen);
free(pJson);
@@ -519,7 +499,8 @@ hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_getall_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_getall_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -533,9 +514,7 @@ hi_u32 vlink_hi_channel_cmd_getall_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_getall_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_getall_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_getall_info--send fail\n");
@@ -546,7 +525,8 @@ hi_u32 vlink_hi_channel_cmd_getall_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void) {
hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -560,9 +540,7 @@ hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void) {
sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN;
sample_log_print("vlink_hi_channel_cmd_clrpir_info-------sendcmdbuf-[%02X]-[%"
"02X]-[%02X]-\n",
sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
sample_log_print("vlink_hi_channel_cmd_clrpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_clrpir_info--send fail\n");
@@ -573,7 +551,8 @@ hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void) {
return 0;
}
hi_u32 vlink_hi_channel_cmd_reboot(hi_void) {
hi_u32 vlink_hi_channel_cmd_reboot(hi_void)
{
hi_u32 datalen = 0;
hi_u32 sendmsg_len = 0;
//cmd 1-byte, len 2-bytes, data 380
@@ -587,8 +566,7 @@ hi_u32 vlink_hi_channel_cmd_reboot(hi_void) {
sendmsg_len = 1;
sample_log_print("vlink_hi_channel_cmd_reboot-------sendcmdbuf-[%02X]-\n",
sendcmdbuf[0]);
sample_log_print("vlink_hi_channel_cmd_reboot-------sendcmdbuf-[%02X]-\n", sendcmdbuf[0]);
if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) {
sample_log_print("vlink_hi_channel_cmd_reboot--send fail\n");
@@ -1,35 +1,35 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 头文件包含
*****************************************************************************/
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "hichannel_host_comm.h"
#include "securec.h"
#include "cJSON.h"
/*****************************************************************************
2 宏定义、全局变量
*****************************************************************************/
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg);
static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg);
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg);
static const sample_cmd_entry_stru g_sample_cmd[] = {
{"help", sample_help_cmd_process},
@@ -87,14 +87,13 @@ typedef struct {
static hi_bool g_terminate = HI_FALSE;
static sample_link_s *g_sample_link = HI_NULL;
static hi_char host_cmd[][MAX_CMD_LEN] = {
"cmd_get_mac", "cmd_get_ip", "cmd_set_filter", "cmd_set_netcfg",
"cmd_set_keeplive", "cmd_set_standby", "cmd_set_deepsleep"};
static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac","cmd_get_ip","cmd_set_filter", "cmd_set_netcfg", "cmd_set_keeplive", "cmd_set_standby", "cmd_set_deepsleep"};
static hi_u8 g_netsta = 0;
/*****************************************************************************
4 函数实现
*****************************************************************************/
static hi_void sample_usage(hi_void) {
static hi_void sample_usage(hi_void)
{
printf("\nUsage:\n");
printf("\tsample_cli quit quit sample_ap\n");
printf("\tsample_cli help show this message\n");
@@ -104,8 +103,8 @@ static hi_void sample_usage(hi_void) {
printf("\tsample_cli deepsleep wifi deep sleep\n");
}
hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg) {
hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_message_s *msg = (sample_message_s *)pmsg;
msg->what = SAMPLE_CMD_IOCTL;
@@ -115,8 +114,8 @@ hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
return HI_SUCCESS;
}
hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
hi_void *pmsg) {
hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_unused(param);
sample_unused(len);
@@ -125,8 +124,8 @@ hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len,
return HI_SUCCESS;
}
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
hi_u32 len, hi_void *pmsg) {
static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg)
{
sample_unused(wdata);
sample_unused(param);
sample_unused(len);
@@ -135,7 +134,8 @@ static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param,
return HI_SUCCESS;
}
static hi_void sample_cleanup(hi_void) {
static hi_void sample_cleanup(hi_void)
{
sample_log_print("sample_cleanup enter\n");
vlink_hi_channel_cmd_reboot();
@@ -163,22 +163,26 @@ static hi_void sample_cleanup(hi_void) {
}
}
static hi_void sample_terminate(hi_s32 sig) {
static hi_void sample_terminate(hi_s32 sig)
{
sample_unused(sig);
sample_cleanup();
g_terminate = HI_TRUE;
_exit(0);
}
static hi_void sample_power(hi_s32 sig) { sample_unused(sig); }
static hi_void sample_power(hi_s32 sig)
{
sample_unused(sig);
}
static hi_s32 sample_wlan_init_up(hi_void) {
static hi_s32 sample_wlan_init_up(hi_void)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -192,7 +196,8 @@ static hi_s32 sample_wlan_init_up(hi_void) {
return HI_SUCCESS;
}
static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
@@ -201,8 +206,7 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -217,9 +221,7 @@ static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %x:%x:%x:%x:%x:%x",
SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]) == -1) {
#else
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"ifconfig %s hw ether %s", SYSTEM_NETDEV_NAME,
mac_addr) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %s", SYSTEM_NETDEV_NAME, mac_addr) == -1) {
#endif
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
@@ -231,8 +233,7 @@ if (ret == -1) {
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -247,21 +248,18 @@ sample_log_print("net device set mac success\n");
return HI_SUCCESS;
}
static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
hi_u8 *gateway, hi_u8 *dnsfirst,
hi_u8 *dnssec, hi_u8 len) {
static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask, hi_u8 *gateway, hi_u8 *dnsfirst, hi_u8 *dnssec, hi_u8 len)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
sample_unused(len);
if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) &&
(ip_addr[3] == 0)) { /* 1 2 3 ipaddr */
if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */
return HI_SUCCESS;
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -280,9 +278,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
return HI_FAILURE;
}
#else
(hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"ifconfig %s %s netmask %s", SYSTEM_NETDEV_NAME, ip_addr,
netmask);
(hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s %s netmask %s", SYSTEM_NETDEV_NAME, ip_addr, netmask);
#endif
ret = system(cmd);
if (ret == -1) {
@@ -291,8 +287,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up",
SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -305,16 +300,14 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
//route table
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
(hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"route del default dev %s", SYSTEM_NETDEV_NAME);
(hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "route del default dev %s", SYSTEM_NETDEV_NAME);
ret = system(cmd);
if (ret == -1) {
sample_log_print("%s error\n", cmd);
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
(hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"route add default gw %s", gateway);
(hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "route add default gw %s", gateway);
ret = system(cmd);
if (ret == -1) {
sample_log_print("%s error\n", cmd);
@@ -329,8 +322,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
(hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"echo nameserver %s >> /etc/resolv.conf", dnsfirst);
(hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "echo nameserver %s >> /etc/resolv.conf", dnsfirst);
ret = system(cmd);
if (ret == -1) {
sample_log_print("%s error\n", cmd);
@@ -338,8 +330,7 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
}
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
(hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"echo nameserver %s >> /etc/resolv.conf", dnssec);
(hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "echo nameserver %s >> /etc/resolv.conf", dnssec);
ret = system(cmd);
if (ret == -1) {
sample_log_print("%s error\n", cmd);
@@ -349,13 +340,13 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask,
return HI_SUCCESS;
}
static hi_s32 sample_wlan_flush_ip(hi_void) {
static hi_s32 sample_wlan_flush_ip(hi_void)
{
hi_s32 ret;
hi_char cmd[SYSTEM_CMD_SIZE] = {0};
(hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE);
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1,
"ifconfig %s 0.0.0.0", SYSTEM_NETDEV_NAME) == -1) {
if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s 0.0.0.0", SYSTEM_NETDEV_NAME) == -1) {
sample_log_print("snprintf_s fail\n");
return HI_FAILURE;
}
@@ -367,13 +358,13 @@ static hi_s32 sample_wlan_flush_ip(hi_void) {
sample_log_print("net device flush ip success\n");
}
static hi_void set_lo_ipaddr(hi_void) {
static hi_void set_lo_ipaddr(hi_void)
{
hi_s32 results;
hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */
hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL};
results = sprintf_s(
cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */
results = sprintf_s(cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */
spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */
if (results < EOK) {
sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n");
@@ -383,7 +374,8 @@ static hi_void set_lo_ipaddr(hi_void) {
system(cmd);
}
static hi_s32 sample_sock_create(hi_void) {
static hi_s32 sample_sock_create(hi_void)
{
if (g_sample_link == HI_NULL) {
return HI_FAILURE;
}
@@ -399,8 +391,7 @@ static hi_s32 sample_sock_create(hi_void) {
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SOCK_PORT);
if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr,
sizeof(servaddr)) == -1) {
if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
sample_log_print("error:%s", strerror(errno));
return HI_FAILURE;
}
@@ -414,8 +405,8 @@ static hi_s32 sample_sock_create(hi_void) {
return HI_SUCCESS;
}
static hi_s32 sample_enqueue(struct squeue *pqueue,
const sample_message_s *element) {
static hi_s32 sample_enqueue(struct squeue *pqueue, const sample_message_s *element)
{
struct snode *pnew = HI_NULL;
if (pqueue == HI_NULL || element == HI_NULL) {
@@ -441,7 +432,8 @@ static hi_s32 sample_enqueue(struct squeue *pqueue,
return HI_SUCCESS;
}
static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) {
static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element)
{
struct snode *p = HI_NULL;
if (pqueue == HI_NULL || element == HI_NULL) {
@@ -464,7 +456,8 @@ static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) {
return HI_SUCCESS;
}
hi_s32 get_netcfg_info(char *ssid, char *password) {
hi_s32 get_netcfg_info(char *ssid, char *password)
{
FILE *fp;
int ret;
@@ -486,7 +479,8 @@ failure:
return HI_FAILURE;
}
hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg) {
hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg)
{
sample_log_print("vlink_sample_str_cmd_process====pmsg=[%s]==\n", pmsg);
if (strncmp(pmsg, "netcfg", 6) == 0) {
char sendmsg[120] = {0};
@@ -499,11 +493,9 @@ hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg) {
#if 1
vlink_hi_channel_cmd_netcfg_info("VLink", "Vlink8888", sendmsg, &msglen);
#else
vlink_hi_channel_cmd_netcfg_info("TP-LINK_AA04", "1427021981", sendmsg,
&msglen);
vlink_hi_channel_cmd_netcfg_info("TP-LINK_AA04", "1427021981", sendmsg, &msglen);
#endif
// sample_log_print("vlink_sample_str_cmd_process====sendmsg=[%s]==\n",
// sendmsg);
//sample_log_print("vlink_sample_str_cmd_process====sendmsg=[%s]==\n", sendmsg);
}
hi_channel_send_to_dev(sendmsg, msglen);
} else if (strncmp(pmsg, "getip", 5) == 0) {
@@ -551,7 +543,9 @@ hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg) {
return HI_SUCCESS;
}
static hi_void *sample_sock_thread(hi_void *args) {
static hi_void *sample_sock_thread(hi_void *args)
{
hi_char link_buf[SOCK_BUF_MAX];
ssize_t recvbytes = 0;
sample_message_s message;
@@ -563,8 +557,7 @@ static hi_void *sample_sock_thread(hi_void *args) {
(hi_void)memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf));
(hi_void)memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen);
recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0,
(struct sockaddr *)&clientaddr, &addrlen);
recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0, (struct sockaddr *)&clientaddr, &addrlen);
if (recvbytes < 0) {
if (errno == EINTR) {
usleep(SLEEP_TIME);
@@ -584,18 +577,16 @@ static hi_void *sample_sock_thread(hi_void *args) {
}
sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message);
#endif
sample_log_print("sample_sock_thread====recvfrom string=[%s]==\n",
link_buf);
sample_log_print("sample_sock_thread====recvfrom string=[%s]==\n", link_buf);
if (vlink_sample_str_cmd_process(link_buf) != HI_SUCCESS) {
sample_log_print("vlink_sample_str_cmd_process error\n");
}
// sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void
// *)&message);
//sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message);
if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT,
(const struct sockaddr *)&clientaddr, addrlen) == -1) {
if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, (const struct sockaddr *)&clientaddr,
addrlen) == -1) {
sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd);
}
@@ -634,12 +625,12 @@ void sample_link_rec_cb(unsigned char *msg_data, int len)
}
}
#else
hi_s32 vlink_hi_channel_set_mac(hi_char *macaddr) {
hi_s32 vlink_hi_channel_set_mac(hi_char *macaddr)
{
hi_s32 ret;
//hi_u8 mactmp[6] = {0};
// sscanf(macaddr, "%02X:%02X:%02X:%02X:%02X:%02X", mactmp[0], mactmp[1],
// mactmp[2], mactmp[3], mactmp[4], mactmp[5]);
//sscanf(macaddr, "%02X:%02X:%02X:%02X:%02X:%02X", mactmp[0], mactmp[1], mactmp[2], mactmp[3], mactmp[4], mactmp[5]);
sample_log_print("vlink_hi_channel_set_mac======mac_addr:%s\n", macaddr);
ret = sample_wlan_init_mac(macaddr, WIFI_MAC_LEN);
@@ -650,7 +641,8 @@ hi_s32 vlink_hi_channel_set_mac(hi_char *macaddr) {
return ret;
}
hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus) {
hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus)
{
hi_s32 ret;
/*
VLINK_WIFI_NETWORK_NETCFG = 0,
@@ -663,10 +655,10 @@ hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus) {
VLINK_WIFI_NETWORK_PWD_ERR,
VLINK_WIFI_NETWORK_OTH_ERR,
*/
sample_log_print("vlink_wifi_work_status_ret======workstatus:%s\n",
workstatus);
sample_log_print("vlink_wifi_work_status_ret======workstatus:%s\n", workstatus);
switch (atoi(workstatus)) {
switch(atoi(workstatus))
{
case 0:
sample_log_print("vlink_wifi_work_status_ret======net config\n");
break;
@@ -699,15 +691,15 @@ hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus) {
return ret;
}
hi_s32 sample_send_event(unsigned char *msg_data, int len) {
hi_s32 sample_send_event(unsigned char *msg_data, int len)
{
struct sockaddr_in servaddr;
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(SOCK_EVENT_PORT);
if (sendto(g_sample_link->eventfd, msg_data, len, MSG_DONTWAIT,
(const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
if (sendto(g_sample_link->eventfd, msg_data, len, MSG_DONTWAIT, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
sample_log_print("sendto error!fd:%d\n", g_sample_link->eventfd);
return HI_FAILURE;
}
@@ -715,7 +707,8 @@ hi_s32 sample_send_event(unsigned char *msg_data, int len) {
return HI_SUCCESS;
}
void sample_link_rec_cb(unsigned char *msg_data, int len) {
void sample_link_rec_cb(unsigned char *msg_data, int len)
{
hi_s32 ret;
hi_s32 index;
@@ -726,29 +719,35 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
}
sample_log_print("sample_link_rec_cb:msg_data-[%s]-[%d]--\n", msg_data, len);
cJSON* root = cJSON_Parse(msg_data);
if (NULL == root) {
if(NULL == root)
{
sample_log_print("sample_link_rec_cb:parseJson---Parse fail\n");
return;
}
item = cJSON_GetObjectItem(root, "cmd");
if (NULL != item) {
if(NULL != item)
{
hi_u8 cmdval = atoi(item->valuestring);
switch (cmdval) {
switch(cmdval)
{
case 1:
break;
case 2: {
case 2:
{
hi_char macaddr[20] = {0};
item = cJSON_GetObjectItem(root, "mac");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
vlink_hi_channel_set_mac(item->valuestring);
}
sample_send_event(msg_data, len);
} break;
case 3: {
}
break;
case 3:
{
hi_char ipaddr[20] = {0};
hi_char nwaddr[20] = {0};
hi_char gwaddr[20] = {0};
@@ -756,38 +755,40 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
hi_char dnssaddr[20] = {0};
item = cJSON_GetObjectItem(root, "ip");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
memcpy_s(ipaddr, 20, item->valuestring, strlen(item->valuestring));
if (strcmp(ipaddr, "0.0.0.0") != 0) {
if(strcmp(ipaddr, "0.0.0.0") != 0)
{
g_netsta = 4;
}
}
item = cJSON_GetObjectItem(root, "nm");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
memcpy_s(nwaddr, 20, item->valuestring, strlen(item->valuestring));
}
item = cJSON_GetObjectItem(root, "gw");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
memcpy_s(gwaddr, 20, item->valuestring, strlen(item->valuestring));
}
item = cJSON_GetObjectItem(root, "dns1");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
memcpy_s(dnsfaddr, 20, item->valuestring, strlen(item->valuestring));
}
item = cJSON_GetObjectItem(root, "dns2");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
memcpy_s(dnssaddr, 20, item->valuestring, strlen(item->valuestring));
}
sample_wlan_init_ip(ipaddr, nwaddr, gwaddr, dnsfaddr, dnssaddr, 0);
sample_send_event(msg_data, len);
} break;
}
break;
case 4:
break;
@@ -811,8 +812,8 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
break;
case 11://writeret
item = cJSON_GetObjectItem(root, "ret");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
vlink_wifi_ota_process_write_ret(item->valuestring);
}
break;
@@ -821,27 +822,27 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
break;
case 13:
item = cJSON_GetObjectItem(root, "ret");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
vlink_wifi_work_status_ret(item->valuestring);
}
break;
case 14:
item = cJSON_GetObjectItem(root, "rssi");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
sample_log_print(":rssi-[%s]--\n", item->valuestring);
}
break;
case 15:
item = cJSON_GetObjectItem(root, "ver");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
sample_log_print(":ver-[%s]--\n", item->valuestring);
}
item = cJSON_GetObjectItem(root, "ker");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
sample_log_print(":ker-[%s]--\n", item->valuestring);
}
@@ -849,8 +850,8 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
break;
case 16:
item = cJSON_GetObjectItem(root, "code");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
sample_log_print(":code-[%s]--\n", item->valuestring);
}
break;
@@ -862,27 +863,31 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
break;
case 19:
item = cJSON_GetObjectItem(root, "enable");
if ((NULL != item) && (NULL != item->valuestring) &&
(0 != strlen(item->valuestring))) {
if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring)))
{
sample_log_print(":pir enable-[%s]--\n", item->valuestring);
}
break;
case 20:
sample_send_event(msg_data, len);
break;
case 21: {
case 21:
{
hi_u8 netsta;
item = cJSON_GetObjectItem(root, "netsta");
if ((NULL != item)) {
if((NULL != item))
{
sample_log_print(":netsta-[%d]--\n", item->valueint);
netsta = item->valueint;
if ((g_netsta != netsta) && (netsta == 6)) {
if((g_netsta != netsta) && (netsta == 6))
{
sample_wlan_flush_ip();
}
g_netsta = netsta;
}
} break;
}
break;
case 22:
sample_send_event(msg_data, len);
break;
@@ -902,7 +907,8 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) {
}
#endif
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
hi_s32 ret;
sample_unused(argc);
sample_unused(argv);
@@ -917,8 +923,7 @@ int main(int argc, char *argv[]) {
return -1;
}
(void)memset_s(g_sample_link, sizeof(sample_link_s), 0,
sizeof(sample_link_s));
(void)memset_s(g_sample_link, sizeof(sample_link_s), 0, sizeof(sample_link_s));
pthread_mutex_init(&g_sample_link->mut, HI_NULL);
pthread_cond_init(&g_sample_link->cond, HI_NULL);
@@ -928,23 +933,23 @@ int main(int argc, char *argv[]) {
if (hi_channel_init() != HI_SUCCESS) {
sample_log_print("hi_channel_init is fail\n");
} else {
}
else
{
sample_log_print("hi_channel_init is ok\n");
}
hi_channel_register_rx_cb(sample_link_rec_cb);
//vlink_hi_channel_cmd_getmac_info();
// hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC],
// (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC])); hi_channel_send_to_dev((hi_u8
// *)host_cmd[HOST_CMD_GET_IP], (hi_s32)strlen(host_cmd[HOST_CMD_GET_IP]));
//hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC]));
//hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_IP], (hi_s32)strlen(host_cmd[HOST_CMD_GET_IP]));
if (sample_sock_create() != HI_SUCCESS) {
sample_log_print("create sock is fail\n");
goto link_out;
}
ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread,
HI_NULL);
ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, HI_NULL);
if (ret != HI_SUCCESS) {
sample_log_print("create sock thread is fail\n");
goto link_out;
@@ -960,8 +965,7 @@ int main(int argc, char *argv[]) {
pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut);
}
pthread_mutex_unlock(&g_sample_link->mut);
sample_log_print("=====SAMPLE LOOP RECIEVE MSG-what[%d]:[%s] LEN:%d=====\n",
message.what, message.obj, message.len);
sample_log_print("=====SAMPLE LOOP RECIEVE MSG-what[%d]:[%s] LEN:%d=====\n", message.what, message.obj, message.len);
fflush(stdout);
/*
@@ -973,8 +977,9 @@ int main(int argc, char *argv[]) {
g_terminate = HI_TRUE;
break;
case SAMPLE_CMD_IOCTL:
if (hi_channel_send_to_dev(message.obj, message.len) !=
HI_SUCCESS) { SAMPLE_LOG_PRINT("sample_iwpriv_cmd send fail\n"); } else {
if (hi_channel_send_to_dev(message.obj, message.len) != HI_SUCCESS) {
SAMPLE_LOG_PRINT("sample_iwpriv_cmd send fail\n");
} else {
SAMPLE_LOG_PRINT("sample_iwpriv_cmd send ok\n");
}
break;
@@ -982,8 +987,10 @@ int main(int argc, char *argv[]) {
break;
}
*/
}
link_out:
sample_cleanup();
return 0;
}
@@ -1,38 +1,41 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 Í·Îļþ°üº¬
*****************************************************************************/
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "hichannel_host_comm.h"
#include "securec.h"
#include "cJSON.h"
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#define MAXLINE 4096
#define TCP_PORT 20000
void *vlink_tcp_socket_thread(void *arg) {
void* vlink_tcp_socket_thread(void* arg)
{
int listenfd, connfd;
struct sockaddr_in servaddr;
char buff[4096];
@@ -58,8 +61,7 @@ void *vlink_tcp_socket_thread(void *arg) {
return 0;
}
printf("======waiting for client's request===ip[%s]=port[%d]==\n",
"192.168.43.1", TCP_PORT);
printf("======waiting for client's request===ip[%s]=port[%d]==\n", "192.168.43.1", TCP_PORT);
while(1){
if( (connfd = accept(listenfd, (struct sockaddr*)NULL, NULL)) == -1){
printf("accept socket error: %s(errno: %d)",strerror(errno),errno);
@@ -80,7 +82,8 @@ void *vlink_tcp_socket_thread(void *arg) {
return 0;
}
int vlink_tcp_socket_start_info(void) {
int vlink_tcp_socket_start_info(void)
{
pthread_t tcpserver;
int rc1 = 0;
rc1 = pthread_create(&tcpserver, NULL, vlink_tcp_socket_thread, NULL);
@@ -89,3 +92,6 @@ int vlink_tcp_socket_start_info(void) {
pthread_detach(tcpserver);
}
+63 -34
View File
@@ -1,33 +1,35 @@
/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights
* reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: sample cli file.
* Author: Hisilicon
* Create: 2020-09-09
*/
/*****************************************************************************
1 Í·Îļþ°üº¬
*****************************************************************************/
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "securec.h"
#include "hi_base.h"
#include "hichannel_host.h"
#include "hichannel_host_comm.h"
#include "securec.h"
#include "cJSON.h"
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <sys/un.h>
@@ -37,13 +39,17 @@
#define MAXLINE 4096
#define TCP_PORT 20000
static int create_wifi_ota_server_socket(void) {
static int create_wifi_ota_server_socket(void)
{
int listen_fd;
int ret;
struct sockaddr_un srv_addr;
listen_fd = socket(PF_LOCAL, SOCK_DGRAM, 0);
if (listen_fd < 0) {
if(listen_fd < 0)
{
printf("cannot create communication socket\n");
return -1;
}
@@ -53,7 +59,8 @@ static int create_wifi_ota_server_socket(void) {
unlink(SOCKET_DOMAIN);
//bind sockfd & addr
ret = bind(listen_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
if (ret == -1) {
if(ret == -1)
{
printf("cannot bind server socket\n");
close(listen_fd);
unlink(SOCKET_DOMAIN);
@@ -63,49 +70,60 @@ static int create_wifi_ota_server_socket(void) {
return listen_fd;
}
void vlink_wifi_ota_process_write_ret(char *result) {
void vlink_wifi_ota_process_write_ret(char* result)
{
#define SENDSTRING "OK"
int ret = atoi(result);
printf("vlink_wifi_ota_process_write_ret-[%d]-\n", ret);
if (ret == 0) {
if (ret == 0)
{
int fd = -1;
struct sockaddr_un srv_addr;
//create socket
fd = socket(PF_LOCAL, SOCK_DGRAM, 0);
if (fd < 0) {
if (fd < 0)
{
printf("cannot bind server socket\n");
return;
}
srv_addr.sun_family = AF_LOCAL;
strcpy(srv_addr.sun_path, SOCKET_DOMAIN);
sendto(fd, SENDSTRING, strlen(SENDSTRING), 0, (struct sockaddr *)&srv_addr,
sizeof(struct sockaddr_un));
}
sendto(fd, SENDSTRING, strlen(SENDSTRING), 0, (struct sockaddr *)&srv_addr, sizeof(struct sockaddr_un));
}
int getIndexOfSigns(char ch) {
if (ch >= '0' && ch <= '9') {
}
int getIndexOfSigns(char ch)
{
if(ch >= '0' && ch <= '9')
{
return ch - '0';
}
if (ch >= 'A' && ch <= 'F') {
if(ch >= 'A' && ch <='F')
{
return ch - 'A' + 10;
}
if (ch >= 'a' && ch <= 'f') {
if(ch >= 'a' && ch <= 'f')
{
return ch - 'a' + 10;
}
return -1;
}
int hexToDec(char *source) {
int hexToDec(char *source)
{
int sum = 0;
int t = 1;
int i, len;
len = strlen(source);
for (i = len - 1; i >= 0; i--) {
for(i=len-1; i>=0; i--)
{
sum += t * getIndexOfSigns(*(source + i));
t *= 16;
}
@@ -113,7 +131,8 @@ int hexToDec(char *source) {
return sum;
}
void *vlink_wifi_ota_thread(void *arg) {
void* vlink_wifi_ota_thread(void* arg)
{
#define BUFFSIZE 1450
int listen_fd = create_wifi_ota_server_socket();
char recv_buf[5];
@@ -124,7 +143,8 @@ void *vlink_wifi_ota_thread(void *arg) {
FILE *fpRead = NULL;
printf("vlink_wifi_ota_thread------start-----------\n");
if (listen_fd < 0) {
if(listen_fd < 0)
{
printf("vlink_wifi_ota_thread--cannot creatServerSocket\n");
unlink(SOCKET_DOMAIN);
return NULL;
@@ -132,17 +152,22 @@ void *vlink_wifi_ota_thread(void *arg) {
fpRead = fopen(VLINK_WIFI_OTA_PATH, "rb");
fseek(fpRead, 0, SEEK_SET);
while (1) {
while (1)
{
int num = 0;
memset(recv_buf, 0, 5);
num = recvfrom (listen_fd, recv_buf, 5, 0, NULL, NULL);
if (num > 0) {
if (num > 0)
{
recv_buf[num] = '\0';
if (strcmp(recv_buf, "OK") == 0) {
if (strcmp(recv_buf, "OK") == 0)
{
memset(send_buf, 0, SAMPLE_CMD_MAX_LEN);
send_buf[0] = CMD_SENDMSG_OTADATA;
if (file_end == 0) {
if (file_end == 0)
{
bzero (read_buf, BUFFSIZE);
int count = fread(read_buf, sizeof (char), BUFFSIZE, fpRead);
file_end = feof(fpRead);
@@ -167,7 +192,8 @@ void *vlink_wifi_ota_thread(void *arg) {
return NULL;
}
int vlink_wifi_ota_start_info(void) {
int vlink_wifi_ota_start_info(void)
{
pthread_t wifiota;
int rc1 = 0;
rc1 = pthread_create(&wifiota, NULL, vlink_wifi_ota_thread, NULL);
@@ -176,3 +202,6 @@ int vlink_wifi_ota_start_info(void) {
pthread_detach(wifiota);
}
@@ -10,13 +10,12 @@
/*
* <FUNCTION DESCRIPTION>
* The fscanf_s function is equivalent to fscanf except that the c, s,
* and [ conversion specifiers apply to a pair of arguments (unless
* assignment suppression is indicated by a*) The fscanf function reads data
* from the current position of stream into the locations given by argument (if
* any). Each argument must be a pointer to a variable of a type that
* corresponds to a type specifier in format. format controls the interpretation
* of the input fields and has the same form and function as the format argument
* for scanf.
* and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*)
* The fscanf function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
@@ -27,20 +26,22 @@
* ... The convered value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fscanf_s(FILE *stream, const char *format, ...) {
int fscanf_s(FILE *stream, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -9,12 +9,12 @@
/*
* <FUNCTION DESCRIPTION>
* The fwscanf_s function is the wide-character equivalent of the
* fscanf_s function The fwscanf_s function reads data from the current position
* of stream into the locations given by argument (if any). Each argument must
* be a pointer to a variable of a type that corresponds to a type specifier in
* format. format controls the interpretation of the input fields and has the
* same form and function as the format argument for scanf.
* The fwscanf_s function is the wide-character equivalent of the fscanf_s function
* The fwscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
@@ -22,24 +22,25 @@
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned
* address
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fwscanf_s(FILE *stream, const wchar_t *format, ...) {
int fwscanf_s(FILE *stream, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfwscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -7,11 +7,11 @@
#include "securecutil.h"
SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) {
SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len)
{
int i;
/* No need to determine whether integer overflow exists */
for (i = (int)(len - 1); i >= 0 && (buffer[i] == '\r' || buffer[i] == '\n');
--i) {
for (i = (int)(len - 1); i >= 0 && (buffer[i] == '\r' || buffer[i] == '\n'); --i) {
buffer[i] = '\0';
}
}
@@ -19,12 +19,12 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) {
/*
* <FUNCTION DESCRIPTION>
* The gets_s function reads at most one less than the number of characters
* specified by destMax from the std input stream, into the array pointed to
* by buffer The line consists of all characters up to and including the first
* newline character ('\n'). gets_s then replaces the newline character with a
* null character ('\0') before returning the line. If the first character read
* is the end-of-file character, a null character is stored at the beginning of
* buffer and NULL is returned.
* specified by destMax from the std input stream, into the array pointed to by buffer
* The line consists of all characters up to and including
* the first newline character ('\n'). gets_s then replaces the newline
* character with a null character ('\0') before returning the line.
* If the first character read is the end-of-file character, a null character
* is stored at the beginning of buffer and NULL is returned.
*
* <INPUT PARAMETERS>
* buffer Storage location for input string.
@@ -37,17 +37,16 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) {
* buffer Successful operation
* NULL Improper parameter or read fail
*/
char *gets_s(char *buffer, size_t numberOfElements) {
char *gets_s(char *buffer, size_t numberOfElements)
{
size_t len;
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN
: numberOfElements);
size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN : numberOfElements);
#else
size_t bufferSize = numberOfElements;
#endif
if (buffer == NULL || bufferSize == 0 ||
bufferSize > SECUREC_STRING_MAX_LEN) {
if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("gets_s");
return NULL;
}
@@ -63,3 +62,4 @@ char *gets_s(char *buffer, size_t numberOfElements) {
return buffer;
}
@@ -6,9 +6,8 @@
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain
* platform compatibility. And sufficient input validation is performed before
* calling
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
@@ -22,8 +21,7 @@
#define SECUREC_MEMCOPY_THRESHOLD_SIZE 64UL
#endif
#define SECUREC_SMALL_MEM_COPY(dest, src, count) \
do { \
#define SECUREC_SMALL_MEM_COPY(dest, src, count) do { \
if (SECUREC_ADDR_ALIGNED_8(dest) && SECUREC_ADDR_ALIGNED_8(src)) { \
/* Use struct assignment */ \
switch (count) { \
@@ -422,28 +420,25 @@
break; \
} \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
/*
* Performance optimization
*/
#define SECUREC_MEMCPY_OPT(dest, src, count) \
do { \
#define SECUREC_MEMCPY_OPT(dest, src, count) do { \
if ((count) > SECUREC_MEMCOPY_THRESHOLD_SIZE) { \
SECUREC_MEMCPY_WARP_OPT((dest), (src), (count)); \
} else { \
SECUREC_SMALL_MEM_COPY((dest), (src), (count)); \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#endif
/*
* Handling errors
*/
SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax,
const void *src, size_t count) {
SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, const void *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memcpy_s");
return ERANGE;
@@ -475,21 +470,18 @@ SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax,
* The fread API in windows will call memcpy_s and pass 0xffffffff to destMax.
* To avoid the failure of fread, we don't check desMax limit.
*/
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) \
(SECUREC_LIKELY((count) <= (destMax) && (dest) != NULL && (src) != NULL && \
(count) > 0 && \
SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
(dest) != NULL && (src) != NULL && \
(count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#else
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) \
(SECUREC_LIKELY((count) <= (destMax) && (dest) != NULL && (src) != NULL && \
(destMax) <= SECUREC_MEM_MAX_LEN && (count) > 0 && \
SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
(dest) != NULL && (src) != NULL && (destMax) <= SECUREC_MEM_MAX_LEN && \
(count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#endif
/*
* <FUNCTION DESCRIPTION>
* The memcpy_s function copies n characters from the object pointed to by
* src into the object pointed to by dest
* The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest
*
* <INPUT PARAMETERS>
* dest Destination buffer.
@@ -502,20 +494,21 @@ SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and destMax <=
* SECUREC_MEM_MAX_LEN EINVAL_AND_RESET dest != NULL and src is NULLL
* and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN ERANGE destMax >
* SECUREC_MEM_MAX_LEN or destMax is 0 ERANGE_AND_RESET count > destMax
* and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL and
* src != NULL EOVERLAP_AND_RESET dest buffer and source buffer are
* overlapped and count <= destMax destMax != 0 and destMax <=
* SECUREC_MEM_MAX_LEN and dest != NULL and src != NULL and dest != src
* EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* and dest != NULL and src != NULL
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* count <= destMax destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
* and src != NULL and dest != src
*
* if an error occured, dest will be filled with 0.
* If the source and destination overlap, the behavior of memcpy_s is
* undefined. Use memmove_s to handle overlapping regions.
* If the source and destination overlap, the behavior of memcpy_s is undefined.
* Use memmove_s to handle overlapping regions.
*/
errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count) {
errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
#if SECUREC_MEMCOPY_WITH_PERFORMANCE
SECUREC_MEMCPY_OPT(dest, src, count);
@@ -536,8 +529,8 @@ EXPORT_SYMBOL(memcpy_s);
/*
* Performance optimization
*/
errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src,
size_t count) {
errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
SECUREC_MEMCPY_OPT(dest, src, count);
return EOK;
@@ -547,11 +540,10 @@ errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src,
}
/* Trim judgement on "destMax <= SECUREC_MEM_MAX_LEN" */
errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src,
size_t count) {
if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL &&
count > 0 &&
SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) {
errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL && \
count > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) {
SECUREC_MEMCPY_OPT(dest, src, count);
return EOK;
}
@@ -559,3 +551,4 @@ errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src,
return SecMemcpyError(dest, destMax, src, count);
}
#endif
@@ -6,9 +6,8 @@
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain
* platform compatibility. And sufficient input validation is performed before
* calling
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
@@ -17,7 +16,8 @@
/*
* Implementing memory data movement
*/
SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) {
SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count)
{
unsigned char *pDest = (unsigned char *)dst;
const unsigned char *pSrc = (const unsigned char *)src;
size_t maxCount = count;
@@ -63,19 +63,19 @@ SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) {
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and destMax <=
* SECUREC_MEM_MAX_LEN EINVAL_AND_RESET dest != NULL and src is NULLL and
* destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN ERANGE destMax >
* SECUREC_MEM_MAX_LEN or destMax is 0 ERANGE_AND_RESET count > destMax
* and dest != NULL and src != NULL and destMax != 0 and destMax <=
* SECUREC_MEM_MAX_LEN
* EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0
* and destMax <= SECUREC_MEM_MAX_LEN
*
* If an error occured, dest will be filled with 0 when dest and destMax
* valid. If some regions of the source area and the destination overlap,
* memmove_s ensures that the original source bytes in the overlapping region
* are copied before being overwritten.
* If an error occured, dest will be filled with 0 when dest and destMax valid.
* If some regions of the source area and the destination overlap, memmove_s
* ensures that the original source bytes in the overlapping region are copied
* before being overwritten.
*/
errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count) {
errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memmove_s");
return ERANGE;
@@ -111,3 +111,4 @@ errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(memmove_s);
#endif
+104 -173
View File
@@ -6,9 +6,8 @@
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain
* platform compatibility. And sufficient input validation is performed before
* calling
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
@@ -17,9 +16,8 @@
#define SECUREC_MEMSET_WITH_PERFORMANCE 0
#endif
#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) \
(SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && (dest) != NULL && \
(count) <= (destMax)))
#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && \
(dest) != NULL && (count) <= (destMax)))
#if SECUREC_WITH_PERFORMANCE_ADDONS || SECUREC_MEMSET_WITH_PERFORMANCE
@@ -59,18 +57,22 @@ typedef union {
SecStrBuf1 buf1;
} SecStrBuf32Union;
/* C standard initializes the first member of the consortium. */
static const SecStrBuf32 g_allZero = {
{'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}};
static const SecStrBuf32 g_allFF = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
static const SecStrBuf32 g_allZero = {{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}};
static const SecStrBuf32 g_allFF = {{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}};
/* Clear coversion warning strict aliasing" */
SECUREC_INLINE const SecStrBuf32Union *
SecStrictAliasingCast(const SecStrBuf32 *buf) {
SECUREC_INLINE const SecStrBuf32Union *SecStrictAliasingCast(const SecStrBuf32 *buf)
{
return (const SecStrBuf32Union *)buf;
}
@@ -78,8 +80,7 @@ SecStrictAliasingCast(const SecStrBuf32 *buf) {
#define SECUREC_MEMSET_THRESHOLD_SIZE 32UL
#endif
#define SECUREC_UNALIGNED_SET(dest, c, count) \
do { \
#define SECUREC_UNALIGNED_SET(dest, c, count) do { \
char *pcDest = (char *)(dest); \
switch (count) { \
case 32: \
@@ -181,141 +182,107 @@ SecStrictAliasingCast(const SecStrBuf32 *buf) {
default: \
break; \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) \
do { \
#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) do { \
switch (c) { \
case 0: \
switch (count) { \
case 1: \
*(SecStrBuf1 *)(dest) = *( \
const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allZero))->buf1)); \
*(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allZero))->buf1)); \
break; \
case 2: \
*(SecStrBuf2 *)(dest) = *( \
const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allZero))->buf2)); \
*(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allZero))->buf2)); \
break; \
case 3: \
*(SecStrBuf3 *)(dest) = *( \
const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allZero))->buf3)); \
*(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allZero))->buf3)); \
break; \
case 4: \
*(SecStrBuf4 *)(dest) = *( \
const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allZero))->buf4)); \
*(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allZero))->buf4)); \
break; \
case 5: \
*(SecStrBuf5 *)(dest) = *( \
const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allZero))->buf5)); \
*(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allZero))->buf5)); \
break; \
case 6: \
*(SecStrBuf6 *)(dest) = *( \
const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allZero))->buf6)); \
*(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allZero))->buf6)); \
break; \
case 7: \
*(SecStrBuf7 *)(dest) = *( \
const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allZero))->buf7)); \
*(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allZero))->buf7)); \
break; \
case 8: \
*(SecStrBuf8 *)(dest) = *( \
const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allZero))->buf8)); \
*(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allZero))->buf8)); \
break; \
case 9: \
*(SecStrBuf9 *)(dest) = *( \
const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allZero))->buf9)); \
*(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allZero))->buf9)); \
break; \
case 10: \
*(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf10)); \
*(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allZero))->buf10)); \
break; \
case 11: \
*(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf11)); \
*(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allZero))->buf11)); \
break; \
case 12: \
*(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf12)); \
*(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allZero))->buf12)); \
break; \
case 13: \
*(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf13)); \
*(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allZero))->buf13)); \
break; \
case 14: \
*(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf14)); \
*(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allZero))->buf14)); \
break; \
case 15: \
*(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf15)); \
*(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allZero))->buf15)); \
break; \
case 16: \
*(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf16)); \
*(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allZero))->buf16)); \
break; \
case 17: \
*(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf17)); \
*(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allZero))->buf17)); \
break; \
case 18: \
*(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf18)); \
*(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allZero))->buf18)); \
break; \
case 19: \
*(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf19)); \
*(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allZero))->buf19)); \
break; \
case 20: \
*(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf20)); \
*(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allZero))->buf20)); \
break; \
case 21: \
*(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf21)); \
*(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allZero))->buf21)); \
break; \
case 22: \
*(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf22)); \
*(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allZero))->buf22)); \
break; \
case 23: \
*(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf23)); \
*(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allZero))->buf23)); \
break; \
case 24: \
*(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf24)); \
*(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allZero))->buf24)); \
break; \
case 25: \
*(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf25)); \
*(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allZero))->buf25)); \
break; \
case 26: \
*(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf26)); \
*(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allZero))->buf26)); \
break; \
case 27: \
*(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf27)); \
*(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allZero))->buf27)); \
break; \
case 28: \
*(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf28)); \
*(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allZero))->buf28)); \
break; \
case 29: \
*(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf29)); \
*(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allZero))->buf29)); \
break; \
case 30: \
*(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf30)); \
*(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allZero))->buf30)); \
break; \
case 31: \
*(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf31)); \
*(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allZero))->buf31)); \
break; \
case 32: \
*(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&( \
(SecStrictAliasingCast(&g_allZero))->buf32)); \
*(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allZero))->buf32)); \
break; \
default: \
break; \
@@ -324,132 +291,100 @@ SecStrictAliasingCast(const SecStrBuf32 *buf) {
case 0xFF: \
switch (count) { \
case 1: \
*(SecStrBuf1 *)(dest) = \
*(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allFF))->buf1)); \
*(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allFF))->buf1)); \
break; \
case 2: \
*(SecStrBuf2 *)(dest) = \
*(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allFF))->buf2)); \
*(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allFF))->buf2)); \
break; \
case 3: \
*(SecStrBuf3 *)(dest) = \
*(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allFF))->buf3)); \
*(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allFF))->buf3)); \
break; \
case 4: \
*(SecStrBuf4 *)(dest) = \
*(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allFF))->buf4)); \
*(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allFF))->buf4)); \
break; \
case 5: \
*(SecStrBuf5 *)(dest) = \
*(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allFF))->buf5)); \
*(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allFF))->buf5)); \
break; \
case 6: \
*(SecStrBuf6 *)(dest) = \
*(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allFF))->buf6)); \
*(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allFF))->buf6)); \
break; \
case 7: \
*(SecStrBuf7 *)(dest) = \
*(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allFF))->buf7)); \
*(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allFF))->buf7)); \
break; \
case 8: \
*(SecStrBuf8 *)(dest) = \
*(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allFF))->buf8)); \
*(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allFF))->buf8)); \
break; \
case 9: \
*(SecStrBuf9 *)(dest) = \
*(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allFF))->buf9)); \
*(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allFF))->buf9)); \
break; \
case 10: \
*(SecStrBuf10 *)(dest) = *( \
const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allFF))->buf10)); \
*(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allFF))->buf10)); \
break; \
case 11: \
*(SecStrBuf11 *)(dest) = *( \
const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allFF))->buf11)); \
*(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allFF))->buf11)); \
break; \
case 12: \
*(SecStrBuf12 *)(dest) = *( \
const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allFF))->buf12)); \
*(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allFF))->buf12)); \
break; \
case 13: \
*(SecStrBuf13 *)(dest) = *( \
const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allFF))->buf13)); \
*(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allFF))->buf13)); \
break; \
case 14: \
*(SecStrBuf14 *)(dest) = *( \
const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allFF))->buf14)); \
*(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allFF))->buf14)); \
break; \
case 15: \
*(SecStrBuf15 *)(dest) = *( \
const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allFF))->buf15)); \
*(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allFF))->buf15)); \
break; \
case 16: \
*(SecStrBuf16 *)(dest) = *( \
const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allFF))->buf16)); \
*(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allFF))->buf16)); \
break; \
case 17: \
*(SecStrBuf17 *)(dest) = *( \
const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allFF))->buf17)); \
*(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allFF))->buf17)); \
break; \
case 18: \
*(SecStrBuf18 *)(dest) = *( \
const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allFF))->buf18)); \
*(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allFF))->buf18)); \
break; \
case 19: \
*(SecStrBuf19 *)(dest) = *( \
const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allFF))->buf19)); \
*(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allFF))->buf19)); \
break; \
case 20: \
*(SecStrBuf20 *)(dest) = *( \
const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allFF))->buf20)); \
*(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allFF))->buf20)); \
break; \
case 21: \
*(SecStrBuf21 *)(dest) = *( \
const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allFF))->buf21)); \
*(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allFF))->buf21)); \
break; \
case 22: \
*(SecStrBuf22 *)(dest) = *( \
const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allFF))->buf22)); \
*(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allFF))->buf22)); \
break; \
case 23: \
*(SecStrBuf23 *)(dest) = *( \
const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allFF))->buf23)); \
*(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allFF))->buf23)); \
break; \
case 24: \
*(SecStrBuf24 *)(dest) = *( \
const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allFF))->buf24)); \
*(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allFF))->buf24)); \
break; \
case 25: \
*(SecStrBuf25 *)(dest) = *( \
const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allFF))->buf25)); \
*(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allFF))->buf25)); \
break; \
case 26: \
*(SecStrBuf26 *)(dest) = *( \
const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allFF))->buf26)); \
*(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allFF))->buf26)); \
break; \
case 27: \
*(SecStrBuf27 *)(dest) = *( \
const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allFF))->buf27)); \
*(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allFF))->buf27)); \
break; \
case 28: \
*(SecStrBuf28 *)(dest) = *( \
const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allFF))->buf28)); \
*(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allFF))->buf28)); \
break; \
case 29: \
*(SecStrBuf29 *)(dest) = *( \
const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allFF))->buf29)); \
*(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allFF))->buf29)); \
break; \
case 30: \
*(SecStrBuf30 *)(dest) = *( \
const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allFF))->buf30)); \
*(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allFF))->buf30)); \
break; \
case 31: \
*(SecStrBuf31 *)(dest) = *( \
const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allFF))->buf31)); \
*(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allFF))->buf31)); \
break; \
case 32: \
*(SecStrBuf32 *)(dest) = *( \
const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allFF))->buf32)); \
*(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allFF))->buf32)); \
break; \
default: \
break; \
@@ -458,39 +393,33 @@ SecStrictAliasingCast(const SecStrBuf32 *buf) {
default: \
SECUREC_UNALIGNED_SET((dest), (c), (count)); \
} /* END switch */ \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#define SECUREC_SMALL_MEM_SET(dest, c, count) \
; \
do { \
#define SECUREC_SMALL_MEM_SET(dest, c, count); do { \
if (SECUREC_ADDR_ALIGNED_8((dest))) { \
SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \
} else { \
SECUREC_UNALIGNED_SET((dest), (c), (count)); \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
/*
* Performance optimization
*/
#define SECUREC_MEMSET_OPT(dest, c, count) \
do { \
#define SECUREC_MEMSET_OPT(dest, c, count) do { \
if ((count) > SECUREC_MEMSET_THRESHOLD_SIZE) { \
SECUREC_MEMSET_WARP_OPT((dest), (c), (count)); \
} else { \
SECUREC_SMALL_MEM_SET((dest), (c), (count)); \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#endif
/*
* Handling errors
*/
SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c,
size_t count) {
SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, size_t count)
{
/* Check destMax is 0 compatible with _sp macro */
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memset_s");
@@ -510,9 +439,8 @@ SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c,
/*
* <FUNCTION DESCRIPTION>
* The memset_s function copies the value of c (converted to an unsigned
* char) into each of the first count characters of the object pointed to by
* dest.
* The memset_s function copies the value of c (converted to an unsigned char)
* into each of the first count characters of the object pointed to by dest.
*
* <INPUT PARAMETERS>
* dest Pointer to destination.
@@ -525,14 +453,14 @@ SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c,
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest == NULL and destMax != 0 and destMax <=
* SECUREC_MEM_MAX_LEN ERANGE destMax > SECUREC_MEM_MAX_LEN or
* (destMax is 0 and count > destMax) ERANGE_AND_RESET count > destMax and
* destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
* EINVAL dest == NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or (destMax is 0 and count > destMax)
* ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
*
* if return ERANGE_AND_RESET then fill dest to c ,fill length is destMax
*/
errno_t memset_s(void *dest, size_t destMax, int c, size_t count) {
errno_t memset_s(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
#if SECUREC_MEMSET_WITH_PERFORMANCE
SECUREC_MEMSET_OPT(dest, c, count);
@@ -553,7 +481,8 @@ EXPORT_SYMBOL(memset_s);
/*
* Performance optimization
*/
errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count) {
errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
SECUREC_MEMSET_OPT(dest, c, count);
return EOK;
@@ -565,7 +494,8 @@ errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count) {
/*
* Performance optimization, trim judgement on "destMax <= SECUREC_MEM_MAX_LEN"
*/
errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count) {
errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_LIKELY(count <= destMax && dest != NULL)) {
SECUREC_MEMSET_OPT(dest, c, count);
return EOK;
@@ -574,3 +504,4 @@ errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count) {
return SecMemsetError(dest, destMax, c, count);
}
#endif
@@ -9,20 +9,19 @@
/*
* <FUNCTION DESCRIPTION>
* The scanf_s function is equivalent to fscanf_s with the argument stdin
* interposed before the arguments to scanf_s The scanf_s function reads data
* from the standard input stream stdin and writes the data into the location
* that's given by argument. Each argument must be a pointer to a variable of a
* type that corresponds to a type specifier in format. If copying occurs
* between strings that overlap, the behavior is undefined.
* The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s
* The scanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned
* address
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
@@ -30,15 +29,17 @@
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int scanf_s(const char *format, ...) {
int scanf_s(const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vscanf_s(format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -38,8 +38,7 @@ typedef struct {
char *base; /* The pointer to the header of buffered string */
#if SECUREC_ENABLE_SCANF_FILE
FILE *pf; /* The file pointer */
long oriFilePos; /* The original position of file offset when fscanf is called
*/
long oriFilePos; /* The original position of file offset when fscanf is called */
int fileRealRead;
#ifdef SECUREC_NO_STD_UNGETC
unsigned int lastChar; /* The char code of last input */
@@ -52,8 +51,8 @@ typedef struct {
/*
* This initialization for eliminating redundant initialization.
*/
SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream,
const char *cur, int count) {
SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream, const char *cur, int count)
{
stream->flag = SECUREC_MEM_STR_FLAG;
stream->count = count;
stream->cur = cur;
@@ -74,7 +73,8 @@ SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream,
/*
* This initialization for eliminating redundant initialization.
*/
SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream) {
SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream)
{
stream->flag = SECUREC_PIPE_STREAM_FLAG;
stream->count = 0;
stream->cur = NULL;
@@ -91,14 +91,15 @@ SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream) {
}
#endif
#ifdef SECUREC_INLINE_INIT_FILE_STREAM_FILE
/*
* This initialization for eliminating redundant initialization.
* Compared with the previous version initialization 0,
* the current code causes the binary size to increase by some bytes
*/
SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream,
FILE *file) {
SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream, FILE *file)
{
stream->flag = SECUREC_FILE_STREAM_FLAG;
stream->count = 0;
stream->cur = NULL;
@@ -119,15 +120,11 @@ SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream,
extern "C" {
#endif
extern int SecInputS(SecFileStream *stream, const char *cFormat,
va_list argList);
extern void SecClearDestBuf(const char *buffer, const char *format,
va_list argList);
extern int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList);
extern void SecClearDestBuf(const char *buffer, const char *format, va_list argList);
#if SECUREC_IN_KERNEL == 0
extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat,
va_list argList);
extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format,
va_list argList);
extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList);
extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList);
#endif
/* 20150105 For software and hardware decoupling,such as UMG */
#if defined(SECUREC_SYSAPI4VXWORKS)
@@ -139,12 +136,10 @@ extern int feof(FILE *stream);
#if defined(SECUREC_SYSAPI4VXWORKS) || defined(SECUREC_CTYPE_MACRO_ADAPT)
#ifndef isspace
#define isspace(c) \
(((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
#define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
#endif
#ifndef iswspace
#define iswspace(c) \
(((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n'))
#define iswspace(c) (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n'))
#endif
#ifndef isascii
#define isascii(c) (((unsigned char)(c)) <= 0x7f)
@@ -181,3 +176,5 @@ extern int feof(FILE *stream);
#define SECUREC_LOCK_STDIN(i, s)
#define SECUREC_UNLOCK_STDIN(i, s)
#endif
+291 -329
View File
@@ -1,11 +1,12 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: The user of this secure c library should include this header
* file in you source code. This header file declare all supported API prototype
* of the library, such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s,
* sprintf_s, scanf_s, and so on. Author: lishunda Create: 2014-02-25 Notes: Do
* not modify this file by yourself. History: 2018-09-27 zhaozhijian Code base
* quality improvement
* Description: The user of this secure c library should include this header file in you source code.
* This header file declare all supported API prototype of the library,
* such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on.
* Author: lishunda
* Create: 2014-02-25
* Notes: Do not modify this file by yourself.
* History: 2018-09-27 zhaozhijian Code base quality improvement
*/
#ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
@@ -61,8 +62,7 @@ typedef int errno_t;
#endif
#ifndef ERANGE
/* The destination buffer is not long enough and destination buffer can not be
* reset */
/* The destination buffer is not long enough and destination buffer can not be reset */
#define ERANGE 34
#endif
@@ -76,8 +76,7 @@ typedef int errno_t;
#define EOVERLAP_AND_RESET (54 | 128)
#endif
/* If you need export the function of this library in Win32 dll, use
* __declspec(dllexport) */
/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */
#ifndef SECUREC_API
#if defined(SECUREC_DLL_EXPORT)
#define SECUREC_API __declspec(dllexport)
@@ -85,10 +84,10 @@ typedef int errno_t;
#define SECUREC_API __declspec(dllimport)
#else
/*
* Standardized function declaration. If a security function is declared in the
* your code, it may cause a compilation alarm,Please delete the security
* function you declared. Adding extern under windows will cause the system to
* have inline functions to expand, so do not add the extern in default
* Standardized function declaration. If a security function is declared in the your code,
* it may cause a compilation alarm,Please delete the security function you declared.
* Adding extern under windows will cause the system to have inline functions to expand,
* so do not add the extern in default
*/
#if defined(_MSC_VER)
#define SECUREC_API
@@ -102,18 +101,19 @@ typedef int errno_t;
extern "C" {
#endif
/*
* Description: The GetHwSecureCVersion function get SecureC Version string and
* version number. Parameter: verNumber - to store version number Return:
* version string
* Description: The GetHwSecureCVersion function get SecureC Version string and version number.
* Parameter: verNumber - to store version number
* Return: version string
*/
SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
#if SECUREC_ENABLE_MEMSET
/*
* Description: The memset_s function copies the value of c (converted to an
* unsigned char) into each of the first count characters of the object pointed
* to by dest. Parameter: dest - destination address Parameter: destMax - The
* maximum length of destination buffer Parameter: c - the value to be copied
* Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
* the first count characters of the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: c - the value to be copied
* Parameter: count - copies count bytes of value to dest
* Return: EOK if there was no runtime-constraint violation
*/
@@ -128,91 +128,91 @@ SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
#if SECUREC_ENABLE_MEMMOVE
/*
* Description: The memmove_s function copies n characters from the object
* pointed to by src into the object pointed to by dest. Parameter: dest -
* destination address Parameter: destMax - The maximum length of destination
* buffer Parameter: src - source address Parameter: count - copies count bytes
* from the src Return: EOK if there was no runtime-constraint violation
* Description: The memmove_s function copies n characters from the object pointed to by src
* into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count bytes from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src,
size_t count);
SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
#endif
#if SECUREC_ENABLE_MEMCPY
/*
* Description: The memcpy_s function copies n characters from the object
* pointed to by src into the object pointed to by dest. Parameter: dest -
* destination address Parameter: destMax - The maximum length of destination
* buffer Parameter: src - source address Parameter: count - copies count bytes
* from the src Return: EOK if there was no runtime-constraint violation
* Description: The memcpy_s function copies n characters from the object pointed to
* by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count bytes from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src,
size_t count);
SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
#endif
#if SECUREC_ENABLE_STRCPY
/*
* Description: The strcpy_s function copies the string pointed to by strSrc
* (including the terminating null character) into the array pointed to by
* strDest Parameter: strDest - destination address Parameter: destMax - The
* maximum length of destination buffer(including the terminating null
* character) Parameter: strSrc - source address Return: EOK if there was no
* runtime-constraint violation
* Description: The strcpy_s function copies the string pointed to by strSrc (including
* the terminating null character) into the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
#endif
#if SECUREC_ENABLE_STRNCPY
/*
* Description: The strncpy_s function copies not more than n successive
* characters (not including the terminating null character) from the array
* pointed to by strSrc to the array pointed to by strDest. Parameter: strDest -
* destination address Parameter: destMax - The maximum length of destination
* buffer(including the terminating null character) Parameter: strSrc - source
* address Parameter: count - copies count characters from the src Return: EOK
* if there was no runtime-constraint violation
* Description: The strncpy_s function copies not more than n successive characters (not including
* the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Parameter: count - copies count characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc,
size_t count);
SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRCAT
/*
* Description: The strcat_s function appends a copy of the string pointed to by
* strSrc (including the terminating null character) to the end of the string
* pointed to by strDest. Parameter: strDest - destination address Parameter:
* destMax - The maximum length of destination buffer(including the terminating
* null wide character) Parameter: strSrc - source address Return: EOK if
* there was no runtime-constraint violation
* Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
* the terminating null character) to the end of the string pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
#endif
#if SECUREC_ENABLE_STRNCAT
/*
* Description: The strncat_s function appends not more than n successive
* characters (not including the terminating null character) from the array
* pointed to by strSrc to the end of the string pointed to by strDest.
* Description: The strncat_s function appends not more than n successive characters (not including
* the terminating null character)
* from the array pointed to by strSrc to the end of the string pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the
* terminating null character) Parameter: strSrc - source address Parameter:
* count - copies count characters from the src Return: EOK if there was no
* runtime-constraint violation
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Parameter: count - copies count characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc,
size_t count);
SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_VSPRINTF
/*
* Description: The vsprintf_s function is equivalent to the vsprintf function
* except for the parameter destMax and the explicit runtime-constraints
* violation Parameter: strDest - produce output according to a format ,write
* to the character string strDest. Parameter: destMax - The maximum length of
* destination buffer(including the terminating null wide characte) Parameter:
* format - fromat string Parameter: argList - instead of a variable number of
* arguments Return: the number of characters printed(not including the
* terminating null byte '\0'), If an error occurred Return: -1.
* Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax
* and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.
*/
SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
va_list argList) SECUREC_ATTRIBUTE(3, 0);
@@ -220,440 +220,401 @@ SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
#if SECUREC_ENABLE_SPRINTF
/*
* Description: The sprintf_s function is equivalent to the sprintf function
* except for the parameter destMax and the explicit runtime-constraints
* violation Parameter: strDest - produce output according to a format ,write
* to the character string strDest. Parameter: destMax - The maximum length of
* destination buffer(including the terminating null byte '\0') Parameter:
* format - fromat string Return: the number of characters printed(not
* including the terminating null byte '\0'), If an error occurred Return: -1.
* Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax
* and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.
*/
SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format,
...) SECUREC_ATTRIBUTE(3, 4);
SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
#endif
#if SECUREC_ENABLE_VSNPRINTF
/*
* Description: The vsnprintf_s function is equivalent to the vsnprintf
* function except for the parameter destMax/count and the explicit
* runtime-constraints violation Parameter: strDest - produce output according
* to a format ,write to the character string strDest. Parameter: destMax - The
* maximum length of destination buffer(including the terminating null byte
* '\0') Parameter: count - do not write more than count bytes to strDest(not
* including the terminating null byte '\0') Parameter: format - fromat string
* Description: The vsnprintf_s function is equivalent to the vsnprintf function except for
* the parameter destMax/count and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating
* null byte '\0'), If an error occurred Return: -1.Pay special attention to
* returning -1 when truncation occurs
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
*/
SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count,
const char *format, va_list argList)
SECUREC_ATTRIBUTE(4, 0);
SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
va_list argList) SECUREC_ATTRIBUTE(4, 0);
#endif
#if SECUREC_ENABLE_SNPRINTF
/*
* Description: The snprintf_s function is equivalent to the snprintf function
* except for the parameter destMax/count and the explicit runtime-constraints
* violation Parameter: strDest - produce output according to a format ,write to
* the character string strDest. Parameter: destMax - The maximum length of
* destination buffer(including the terminating null byte '\0') Parameter:
* count - do not write more than count bytes to strDest(not including the
* terminating null byte '\0') Parameter: format - fromat string Return: the
* number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning -1 when
* truncation occurs
* Description: The snprintf_s function is equivalent to the snprintf function except for
* the parameter destMax/count and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
*/
SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count,
const char *format, ...) SECUREC_ATTRIBUTE(4, 5);
SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
...) SECUREC_ATTRIBUTE(4, 5);
#endif
#if SECUREC_SNPRINTF_TRUNCATED
/*
* Description: The vsnprintf_truncated_s function is equivalent to the
* vsnprintf_s function except no count parameter and return value Parameter:
* strDest - produce output according to a format ,write to the character
* string strDest Parameter: destMax - The maximum length of destination
* buffer(including the terminating null byte '\0') Parameter: format - fromat
* string Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating
* null byte '\0'), If an error occurred Return: -1.Pay special attention to
* returning destMax - 1 when truncation occurs
* Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
* no count parameter and return value
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
*/
SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax,
const char *format, va_list argList)
SECUREC_ATTRIBUTE(3, 0);
SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
va_list argList) SECUREC_ATTRIBUTE(3, 0);
/*
* Description: The snprintf_truncated_s function is equivalent to the
* snprintf_2 function except no count parameter and return value Parameter:
* strDest - produce output according to a format ,write to the character
* string strDest. Parameter: destMax - The maximum length of destination
* buffer(including the terminating null byte '\0') Parameter: format - fromat
* string Return: the number of characters printed(not including the
* terminating null byte '\0'), If an error occurred Return: -1.Pay special
* attention to returning destMax - 1 when truncation occurs
* Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
* no count parameter and return value
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
*/
SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
const char *format, ...)
SECUREC_ATTRIBUTE(3, 4);
const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
#endif
#if SECUREC_ENABLE_SCANF
/*
* Description: The scanf_s function is equivalent to fscanf_s with the
* argument stdin interposed before the arguments to scanf_s Parameter: format -
* fromat string Return: the number of input items assigned, If an error
* occurred Return: -1.
* Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
* interposed before the arguments to scanf_s
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int scanf_s(const char *format, ...);
#endif
#if SECUREC_ENABLE_VSCANF
/*
* Description: The vscanf_s function is equivalent to scanf_s, with the
* variable argument list replaced by argList Parameter: format - fromat string
* Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return:
* -1.
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vscanf_s(const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_SSCANF
/*
* Description: The sscanf_s function is equivalent to fscanf_s, except that
* input is obtained from a string (specified by the argument buffer) rather
* than from a stream Parameter: buffer - read character from buffer
* Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
* string (specified by the argument buffer) rather than from a stream
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return:
* -1.
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
#endif
#if SECUREC_ENABLE_VSSCANF
/*
* Description: The vsscanf_s function is equivalent to sscanf_s, with the
* variable argument list replaced by argList Parameter: buffer - read
* character from buffer Parameter: format - fromat string Parameter: argList -
* instead of a variable number of arguments Return: the number of input
* items assigned, If an error occurred Return: -1.
* Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
* replaced by argList
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vsscanf_s(const char *buffer, const char *format,
va_list argList);
SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_FSCANF
/*
* Description: The fscanf_s function is equivalent to fscanf except that the
* c, s, and [ conversion specifiers apply to a pair of arguments (unless
* assignment suppression is indicated by a*) Parameter: stream - stdio file
* stream Parameter: format - fromat string Return: the number of input items
* assigned, If an error occurred Return: -1.
* Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
* apply to a pair of arguments (unless assignment suppression is indicated by a*)
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
#endif
#if SECUREC_ENABLE_VFSCANF
/*
* Description: The vfscanf_s function is equivalent to fscanf_s, with the
* variable argument list replaced by argList Parameter: stream - stdio file
* stream Parameter: format - fromat string Parameter: argList - instead of a
* variable number of arguments Return: the number of input items assigned,
* If an error occurred Return: -1.
* Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
* replaced by argList
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_STRTOK
/*
* Description: The strtok_s function parses a string into a sequence of
* strToken, replace all characters in strToken string that match to strDelimit
* set with 0. On the first call to strtok_s the string to be parsed should be
* specified in strToken. In each subsequent call that should parse the same
* string, strToken should be NULL Parameter: strToken - the string to be
* delimited Parameter: strDelimit - specifies a set of characters that delimit
* the tokens in the parsed string Parameter: context - is a pointer to a char *
* variable that is used internally by strtok_s function Return: On the first
* call returns the address of the first non \0 character, otherwise NULL is
* returned. In subsequent calls, the strtoken is set to NULL, and the context
* set is the same as the previous call, return NULL if the *context string
* length is equal 0, otherwise return *context.
* Description: The strtok_s function parses a string into a sequence of strToken,
* replace all characters in strToken string that match to strDelimit set with 0.
* On the first call to strtok_s the string to be parsed should be specified in strToken.
* In each subsequent call that should parse the same string, strToken should be NULL
* Parameter: strToken - the string to be delimited
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
* Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
* return NULL if the *context string length is equal 0, otherwise return *context.
*/
SECUREC_API char *strtok_s(char *strToken, const char *strDelimit,
char **context);
SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
#endif
#if SECUREC_ENABLE_GETS && SECUREC_IN_KERNEL == 0
/*
* Description: The gets_s function reads at most one less than the number of
* characters specified by destMax from the stream pointed to by stdin, into the
* array pointed to by buffer Parameter: buffer - destination address
* Parameter: destMax - The maximum length of destination buffer(including the
* terminating null character) Return: buffer if there was no
* runtime-constraint violation,If an error occurred Return: NULL.
* Description: The gets_s function reads at most one less than the number of characters specified
* by destMax from the stream pointed to by stdin, into the array pointed to by buffer
* Parameter: buffer - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
*/
SECUREC_API char *gets_s(char *buffer, size_t destMax);
#endif
#if SECUREC_ENABLE_WCHAR_FUNC
#if SECUREC_ENABLE_MEMCPY
/*
* Description: The wmemcpy_s function copies n successive wide characters from
* the object pointed to by src into the object pointed to by dest. Parameter:
* dest - destination address Parameter: destMax - The maximum length of
* destination buffer Parameter: src - source address Parameter: count - copies
* count wide characters from the src Return: EOK if there was no
* runtime-constraint violation
* Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
* by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src,
size_t count);
SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
#endif
#if SECUREC_ENABLE_MEMMOVE
/*
* Description: The wmemmove_s function copies n successive wide characters from
* the object pointed to by src into the object pointed to by dest. Parameter:
* dest - destination address Parameter: destMax - The maximum length of
* destination buffer Parameter: src - source address Parameter: count - copies
* count wide characters from the src Return: EOK if there was no
* runtime-constraint violation
* Description: The wmemmove_s function copies n successive wide characters from the object
* pointed to by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax,
const wchar_t *src, size_t count);
SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
#endif
#if SECUREC_ENABLE_STRCPY
/*
* Description: The wcscpy_s function copies the wide string pointed to by
* strSrc (including theterminating null wide character) into the array pointed
* to by strDest Parameter: strDest - destination address Parameter: destMax -
* The maximum length of destination buffer Parameter: strSrc - source address
* Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
* null wide character) into the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc);
SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
#endif
#if SECUREC_ENABLE_STRNCPY
/*
* Description: The wcsncpy_s function copies not more than n successive wide
* characters (not including the terminating null wide character) from the array
* pointed to by strSrc to the array pointed to by strDest Parameter: strDest -
* destination address Parameter: destMax - The maximum length of destination
* buffer(including the terminating wide character) Parameter: strSrc - source
* address Parameter: count - copies count wide characters from the src Return:
* EOK if there was no runtime-constraint violation
* Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
* terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc, size_t count);
SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRCAT
/*
* Description: The wcscat_s function appends a copy of the wide string pointed
* to by strSrc (including the terminating null wide character) to the end of
* the wide string pointed to by strDest Parameter: strDest - destination
* address Parameter: destMax - The maximum length of destination
* buffer(including the terminating wide character) Parameter: strSrc - source
* address Return: EOK if there was no runtime-constraint violation
* Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
* terminating null wide character) to the end of the wide string pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc);
SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
#endif
#if SECUREC_ENABLE_STRNCAT
/*
* Description: The wcsncat_s function appends not more than n successive wide
* characters (not including the terminating null wide character) from the array
* pointed to by strSrc to the end of the wide string pointed to by strDest.
* Description: The wcsncat_s function appends not more than n successive wide characters (not including the
* terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
* by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the
* terminating wide character) Parameter: strSrc - source address Parameter:
* count - copies count wide characters from the src Return: EOK if there
* was no runtime-constraint violation
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc, size_t count);
SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRTOK
/*
* Description: The wcstok_s function is the wide-character equivalent of
* the strtok_s function Parameter: strToken - the string to be delimited
* Parameter: strDelimit - specifies a set of characters that delimit the tokens
* in the parsed string Parameter: context - is a pointer to a char * variable
* that is used internally by strtok_s function Return: a pointer to the
* first character of a token, or a null pointer if there is no token or there
* is a runtime-constraint violation.
* Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
* Parameter: strToken - the string to be delimited
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
* Return: a pointer to the first character of a token, or a null pointer if there is no token
* or there is a runtime-constraint violation.
*/
SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit,
wchar_t **context);
SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
#endif
#if SECUREC_ENABLE_VSPRINTF
/*
* Description: The vswprintf_s function is the wide-character equivalent
* of the vsprintf_s function Parameter: strDest - produce output according to
* a format ,write to the character string strDest Parameter: destMax - The
* maximum length of destination buffer(including the terminating null )
* Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating
* null wide characte), If an error occurred Return: -1.
* Return: the number of characters printed(not including the terminating null wide characte),
* If an error occurred Return: -1.
*/
SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax,
const wchar_t *format, va_list argList);
SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SPRINTF
/*
* Description: The swprintf_s function is the wide-character equivalent
* of the sprintf_s function Parameter: strDest - produce output according to a
* format ,write to the character string strDest Parameter: destMax - The
* maximum length of destination buffer(including the terminating null )
* Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating
* null wide characte), If an error occurred Return: -1.
* Return: the number of characters printed(not including the terminating null wide characte),
* If an error occurred Return: -1.
*/
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax,
const wchar_t *format, ...);
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_FSCANF
/*
* Description: The fwscanf_s function is the wide-character equivalent
* of the fscanf_s function Parameter: stream - stdio file stream Parameter:
* format - fromat string Return: the number of input items assigned, If an
* error occurred Return: -1.
* Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VFSCANF
/*
* Description: The vfwscanf_s function is the wide-character equivalent
* of the vfscanf_s function Parameter: stream - stdio file stream Parameter:
* format - fromat string Parameter: argList - instead of a variable number of
* arguments Return: the number of input items assigned, If an error occurred
* Return: -1.
* Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format,
va_list argList);
SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SCANF
/*
* Description: The wscanf_s function is the wide-character equivalent of
* the scanf_s function Parameter: format - fromat string Return: the number
* of input items assigned, If an error occurred Return: -1.
* Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int wscanf_s(const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VSCANF
/*
* Description: The vwscanf_s function is the wide-character equivalent
* of the vscanf_s function Parameter: format - fromat string Parameter: argList
* - instead of a variable number of arguments Return: the number of input
* items assigned, If an error occurred Return: -1.
* Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SSCANF
/*
* Description: The swscanf_s function is the wide-character equivalent
* of the sscanf_s function Parameter: buffer - read character from buffer
* Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return:
* -1.
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VSSCANF
/*
* Description: The vswscanf_s function is the wide-character equivalent
* of the vsscanf_s function Parameter: buffer - read character from buffer
* Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return:
* -1.
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format,
va_list argList);
SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
#endif
#endif /* SECUREC_ENABLE_WCHAR_FUNC */
#endif
/* Those functions are used by macro ,must declare hare , also for without
* function declaration warning */
extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc,
size_t count);
/* Those functions are used by macro ,must declare hare , also for without function declaration warning */
extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
#if SECUREC_WITH_PERFORMANCE_ADDONS
/* Those functions are used by macro */
extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src,
size_t count);
extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src,
size_t count);
extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
/* The strcpy_sp is a macro, not a function in performance optimization mode. */
#define strcpy_sp(dest, destMax, src) \
((__builtin_constant_p((destMax)) && __builtin_constant_p((src))) \
? SECUREC_STRCPY_SM((dest), (destMax), (src)) \
: strcpy_s((dest), (destMax), (src)))
#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
strcpy_s((dest), (destMax), (src)))
/* The strncpy_sp is a macro, not a function in performance optimization mode.
*/
#define strncpy_sp(dest, destMax, src, count) \
((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) \
? SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) \
: strncpy_s((dest), (destMax), (src), (count)))
/* The strncpy_sp is a macro, not a function in performance optimization mode. */
#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
strncpy_s((dest), (destMax), (src), (count)))
/* The strcat_sp is a macro, not a function in performance optimization mode. */
#define strcat_sp(dest, destMax, src) \
((__builtin_constant_p((destMax)) && __builtin_constant_p((src))) \
? SECUREC_STRCAT_SM((dest), (destMax), (src)) \
: strcat_s((dest), (destMax), (src)))
#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
strcat_s((dest), (destMax), (src)))
/* The strncat_sp is a macro, not a function in performance optimization mode.
*/
#define strncat_sp(dest, destMax, src, count) \
((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) \
? SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) \
: strncat_s((dest), (destMax), (src), (count)))
/* The strncat_sp is a macro, not a function in performance optimization mode. */
#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
strncat_s((dest), (destMax), (src), (count)))
/* The memcpy_sp is a macro, not a function in performance optimization mode. */
#define memcpy_sp(dest, destMax, src, count) \
(__builtin_constant_p((count)) \
? (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) \
: (__builtin_constant_p((destMax)) \
? (((size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & \
(unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) \
? memcpy_sOptTc((dest), (destMax), (src), (count)) \
: ERANGE) \
: memcpy_sOptAsm((dest), (destMax), (src), (count))))
#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
(SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
(__builtin_constant_p((destMax)) ? \
(((size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
memcpy_sOptAsm((dest), (destMax), (src), (count))))
/* The memset_sp is a macro, not a function in performance optimization mode. */
#define memset_sp(dest, destMax, c, count) \
(__builtin_constant_p((count)) \
? (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) \
: (__builtin_constant_p((destMax)) \
? (((((unsigned long long)(destMax) & \
(unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) \
? memset_sOptTc((dest), (destMax), (c), (count)) \
: ERANGE) \
: memset_sOptAsm((dest), (destMax), (c), (count))))
#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
(SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
(__builtin_constant_p((destMax)) ? \
(((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
memset_sOptAsm((dest), (destMax), (c), (count))))
#else
#define strcpy_sp strcpy_s
#define strncpy_sp strncpy_s
@@ -667,3 +628,4 @@ extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src,
}
#endif /* __cplusplus */
#endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */
@@ -1,14 +1,13 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: Define internal used macro and data type. The marco of
* SECUREC_ON_64BITS will be determined in this header file, which is a switch
* for part of code. Some macro are used to supress warning by MS compiler.
* Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS
* will be determined in this header file, which is a switch for part
* of code. Some macro are used to supress warning by MS compiler.
* Author: lishunda
* Create: 2014-02-25
* Notes: User can change the value of SECUREC_STRING_MAX_LEN and
* SECUREC_MEM_MAX_LEN macro to meet their special need, but The maximum value
* should not exceed 2G. History: 2018-09-27 zhaozhijian Code base quality
* improvement
* Notes: User can change the value of SECUREC_STRING_MAX_LEN and SECUREC_MEM_MAX_LEN
* macro to meet their special need, but The maximum value should not exceed 2G.
* History: 2018-09-27 zhaozhijian Code base quality improvement
*/
/*
* [Standardize-exceptions]: Performance-sensitive
@@ -21,8 +20,7 @@
#ifndef SECUREC_USING_STD_SECURE_LIB
#if defined(_MSC_VER) && _MSC_VER >= 1400
#if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__ == 0
/* Security functions have been provided since vs2005, default use of system
* library functions */
/* Security functions have been provided since vs2005, default use of system library functions */
#define SECUREC_USING_STD_SECURE_LIB 0
#else
#define SECUREC_USING_STD_SECURE_LIB 1
@@ -32,8 +30,8 @@
#endif
#endif
/* Compatibility with older Secure C versions, shielding VC symbol redefinition
* warning */
/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
#if defined(_MSC_VER) && _MSC_VER >= 1400 && SECUREC_USING_STD_SECURE_LIB == 0
#ifndef SECUREC_DISABLE_CRT_FUNC
#define SECUREC_DISABLE_CRT_FUNC 1
@@ -89,8 +87,8 @@
#endif
#endif
/* Default secure function declaration, default declarations for non-standard
* functions */
/* Default secure function declaration, default declarations for non-standard functions */
#ifndef SECUREC_SNPRINTF_TRUNCATED
#define SECUREC_SNPRINTF_TRUNCATED 1
#endif
@@ -106,8 +104,7 @@
#define SECUREC_ENABLE_VSNPRINTF 0
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security
* function */
/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
#define snprintf_s _snprintf_s
#define SECUREC_ENABLE_SNPRINTF 0
#endif
@@ -310,9 +307,8 @@
#endif
/*
* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS
* macro, default is enable. The macro is automatically closed on the windows
* platform and linux kernel
* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable.
* The macro is automatically closed on the windows platform and linux kernel
*/
#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
#if SECUREC_IN_KERNEL
@@ -322,18 +318,15 @@
#endif
#endif
/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible
* to Windows. */
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && \
!defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
#ifndef SECUREC_COMPATIBLE_WIN_FORMAT
#define SECUREC_COMPATIBLE_WIN_FORMAT
#endif
#endif
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
/* On windows platform, can't use optimized function for there is no
* __builtin_constant_p like function */
/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */
/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
#undef SECUREC_WITH_PERFORMANCE_ADDONS
@@ -341,17 +334,15 @@
#endif
#endif
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || \
defined(_VXWORKS_PLATFORM_) || defined(SECUREC_VXWORKS_VERSION_5_4)
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
defined(SECUREC_VXWORKS_VERSION_5_4)
#ifndef SECUREC_VXWORKS_PLATFORM
#define SECUREC_VXWORKS_PLATFORM
#endif
#endif
/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be
* compatible to Linux. */
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && \
!defined(SECUREC_VXWORKS_PLATFORM)
/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM)
#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT
#define SECUREC_COMPATIBLE_LINUX_FORMAT
#endif
@@ -368,10 +359,9 @@
#endif
/*
* Add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort
* -Wformat. Default does not check the format is that the same data type in the
* actual code. In the product is different in the original data type definition
* of VxWorks and Linux.
* Add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort -Wformat.
* Default does not check the format is that the same data type in the actual code.
* In the product is different in the original data type definition of VxWorks and Linux.
*/
#ifndef SECUREC_SUPPORT_FORMAT_WARNING
#define SECUREC_SUPPORT_FORMAT_WARNING 0
@@ -389,9 +379,8 @@
((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) && \
!defined(SECUREC_PCLINT)
/*
* This is a built-in function that can be used without a declaration, if you
* encounter an undeclared compilation alarm, you can add
* -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
* This is a built-in function that can be used without a declaration, if you encounter an undeclared compilation alarm,
* you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
*/
#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE
long __builtin_expect(long exp, long c);
@@ -429,8 +418,7 @@ long __builtin_expect(long exp, long c);
#define SECUREC_ON_64BITS
#endif
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && \
defined(__SIZEOF_POINTER__))
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
#if __SIZEOF_POINTER__ == 8
#define SECUREC_ON_64BITS
#endif
@@ -445,19 +433,19 @@ long __builtin_expect(long exp, long c);
#endif
/*
* Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow
* system on default, and strtold. The function strtold is referenced first at
* ISO9899:1999(C99), and some old compilers can not support these functions.
* Here provides a macro to open these functions: SECUREC_SUPPORT_STRTOLD -- If
* defined, strtold will be used
* Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default,
* and strtold.
* The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can
* not support these functions. Here provides a macro to open these functions:
* SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used
*/
#ifndef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 0
#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
#if defined(__USE_ISOC99) || (defined(_AIX) && defined(_ISOC99_SOURCE)) || \
#if defined(__USE_ISOC99) || \
(defined(_AIX) && defined(_ISOC99_SOURCE)) || \
(defined(__hpux) && defined(__ia64)) || \
(defined(SECUREC_ON_SOLARIS) && \
(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
(defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
defined(_STDC_C99) || defined(__EXTENSIONS__))
#undef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 1
@@ -469,6 +457,7 @@ long __builtin_expect(long exp, long c);
#endif
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS
#ifndef SECUREC_TWO_MIN
@@ -477,35 +466,24 @@ long __builtin_expect(long exp, long c);
/* For strncpy_s performance optimization */
#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
(((void *)(dest) != NULL && (void *)(src) != NULL && \
(size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < \
SECUREC_STRING_MAX_LEN) && \
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) \
? (((size_t)(count) < strlen(src)) \
? (memcpy((dest), (src), (count)), \
*((char *)(dest) + (count)) = '\0', EOK) \
: (memcpy((dest), (src), strlen(src) + 1), EOK)) \
: (strncpy_error((dest), (destMax), (src), (count))))
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
(((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
(memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
#define SECUREC_STRCPY_SM(dest, destMax, src) \
(((void *)(dest) != NULL && (void *)(src) != NULL && \
(size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < \
SECUREC_STRING_MAX_LEN) && \
(strlen(src) + 1) <= (size_t)(destMax)) \
? (memcpy((dest), (src), strlen(src) + 1), EOK) \
: (strcpy_error((dest), (destMax), (src))))
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
(strcpy_error((dest), (destMax), (src))))
/* For strcat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRCAT_SM(dest, destMax, src) \
({ \
#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
int catRet = EOK; \
if ((void *)(dest) != NULL && (void *)(src) != NULL && \
(size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < \
SECUREC_STRING_MAX_LEN)) { \
if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
char *catTmpDst = (char *)(dest); \
size_t catRestSize = (destMax); \
while (catRestSize > 0 && *catTmpDst != '\0') { \
@@ -534,15 +512,11 @@ long __builtin_expect(long exp, long c);
/* For strncat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) \
({ \
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
int ncatRet = EOK; \
if ((void *)(dest) != NULL && (void *)(src) != NULL && \
(size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < \
SECUREC_STRING_MAX_LEN) && \
(((unsigned long long)(count) & (unsigned long long)(-2)) < \
SECUREC_STRING_MAX_LEN)) { \
if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
char *ncatTmpDest = (char *)(dest); \
size_t ncatRestSize = (size_t)(destMax); \
while (ncatRestSize > 0 && *ncatTmpDest != '\0') { \
@@ -551,8 +525,7 @@ long __builtin_expect(long exp, long c);
} \
if (ncatRestSize == 0) { \
ncatRet = EINVAL; \
} else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= \
ncatRestSize) { \
} else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize) { \
if ((size_t)(count) < strlen(src)) { \
memcpy(ncatTmpDest, (src), (count)); \
*(ncatTmpDest + (count)) = '\0'; \
@@ -571,26 +544,23 @@ long __builtin_expect(long exp, long c);
ncatRet; \
})
#else
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) \
strncat_s((dest), (destMax), (src), (count))
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
#endif
/* This macro do not check buffer overlap by default */
#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
(!(((size_t)(destMax) == 0) || \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > \
SECUREC_MEM_MAX_LEN) || \
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || \
((void *)(src) == NULL)) \
? (memcpy((dest), (src), (count)), EOK) \
: (memcpy_s((dest), (destMax), (src), (count))))
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \
(memcpy((dest), (src), (count)), EOK) : \
(memcpy_s((dest), (destMax), (src), (count))))
#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
(!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > \
SECUREC_MEM_MAX_LEN) || \
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) \
? (memset((dest), (c), (count)), EOK) \
: (memset_s((dest), (destMax), (c), (count))))
(!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
(memset((dest), (c), (count)), EOK) : \
(memset_s((dest), (destMax), (c), (count))))
#endif
#endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */
@@ -16,14 +16,18 @@
/*
* Convert wide characters to narrow multi-bytes
*/
int wctomb(char *s, wchar_t wc) { return wcrtomb(s, wc, NULL); }
int wctomb(char *s, wchar_t wc)
{
return wcrtomb(s, wc, NULL);
}
#endif
#if SECUREC_HAVE_MBTOWC
/*
* Converting narrow multi-byte characters to wide characters
*/
int mbtowc(wchar_t *pwc, const char *s, size_t n) {
int mbtowc(wchar_t *pwc, const char *s, size_t n)
{
return mbrtowc(pwc, s, n, NULL);
}
#endif
@@ -51,7 +55,8 @@ int mbtowc(wchar_t *pwc, const char *s, size_t n) {
* 0X602<->CP0002
* ...
*/
const char *GetHwSecureCVersion(unsigned short *verNumber) {
const char *GetHwSecureCVersion(unsigned short *verNumber)
{
if (verNumber != NULL) {
*verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION);
}
@@ -60,3 +65,4 @@ const char *GetHwSecureCVersion(unsigned short *verNumber) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(GetHwSecureCVersion);
#endif
@@ -1,8 +1,9 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: Define macro, data struct, and declare internal used function
* prototype, which is used by secure functions. Author: lishunda Create:
* 2014-02-25
* Description: Define macro, data struct, and declare internal used function prototype,
* which is used by secure functions.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
@@ -10,28 +11,23 @@
#include "securec.h"
#if (defined(_MSC_VER)) && (_MSC_VER >= 1400)
/* Shield compilation alerts using discarded functions and Constant expression
* to maximize code compatibility */
#define SECUREC_MASK_MSVC_CRT_WARNING \
__pragma(warning(push)) __pragma(warning(disable : 4996 4127))
/* Shield compilation alerts using discarded functions and Constant expression to maximize code compatibility */
#define SECUREC_MASK_MSVC_CRT_WARNING __pragma(warning(push)) \
__pragma(warning(disable : 4996 4127))
#define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop))
#else
#define SECUREC_MASK_MSVC_CRT_WARNING
#define SECUREC_END_MASK_MSVC_CRT_WARNING
#endif
#define SECUREC_WHILE_ZERO \
SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING
#define SECUREC_WHILE_ZERO SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING
/* Automatically identify the platform that supports strnlen function, and use
* this function to improve performance */
/* Automatically identify the platform that supports strnlen function, and use this function to improve performance */
#ifndef SECUREC_HAVE_STRNLEN
#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || \
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L)
#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L)
#if SECUREC_IN_KERNEL
#define SECUREC_HAVE_STRNLEN 0
#else
#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && \
__GLIBC_MINOR__ >= 10
#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ >= 10
#define SECUREC_HAVE_STRNLEN 1
#else
#define SECUREC_HAVE_STRNLEN 0
@@ -117,12 +113,10 @@
#define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836
#define SECUREC_MAX_WIDTH_LEN SECUREC_MUL_TEN(SECUREC_MAX_WIDTH_LEN_DIV_TEN)
/* Is the x multiplied by 10 greater than */
#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) \
(((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN))
#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN))
#define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */
#define SECUREC_FLOAT_BUFSIZE_LB \
(4932 + 40) /* Max length of long double value */
#define SECUREC_FLOAT_BUFSIZE_LB (4932 + 40) /* Max length of long double value */
#define SECUREC_FLOAT_DEFAULT_PRECISION 6
/* This macro does not handle pointer equality or integer overflow */
@@ -135,40 +129,35 @@
((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src)))
/*
* Check whether the strings overlap, len is the length of the string not
* include terminator Length is related to data type char or wchar , do not
* force conversion of types
* Check whether the strings overlap, len is the length of the string not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_STRING_NO_OVERLAP(dest, src, len) \
(((src) < (dest) && ((src) + (len)) < (dest)) || \
((dest) < (src) && ((dest) + (len)) < (src)))
/*
* Check whether the strings overlap for strcpy wcscpy function, dest len and
* src Len are not include terminator Length is related to data type char or
* wchar , do not force conversion of types
* Check whether the strings overlap for strcpy wcscpy function, dest len and src Len are not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_STRING_IS_OVERLAP(dest, src, len) \
(((src) < (dest) && ((src) + (len)) >= (dest)) || \
((dest) < (src) && ((dest) + (len)) >= (src)))
/*
* Check whether the strings overlap for strcat wcscat function, dest len and
* src Len are not include terminator Length is related to data type char or
* wchar , do not force conversion of types
* Check whether the strings overlap for strcat wcscat function, dest len and src Len are not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \
(((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \
((src) < (dest) && ((src) + (srcLen)) >= (dest)))
#if SECUREC_HAVE_STRNLEN
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) \
do { \
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
*(outLen) = strnlen((str), (maxLen)); \
} \
SECUREC_WHILE_ZERO
#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) \
do { \
} SECUREC_WHILE_ZERO
#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) do { \
if ((maxLen) > 8) { \
/* Optimization or len less then 8 */ \
if (*((str) + 0) == '\0') { \
@@ -191,18 +180,15 @@
/* Optimization with a length of 8 */ \
*(outLen) = 8; \
} else { \
/* The offset is 8 because the performance of 8 byte alignment is high \
*/ \
/* The offset is 8 because the performance of 8 byte alignment is high */ \
*(outLen) = 8 + strnlen((str) + 8, (maxLen) - 8); \
} \
} else { \
SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#else
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) \
do { \
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
const char *strEnd = (const char *)(str); \
size_t availableSize = (size_t)(maxLen); \
while (availableSize > 0 && *strEnd != '\0') { \
@@ -210,13 +196,11 @@
++strEnd; \
} \
*(outLen) = (size_t)(strEnd - (str)); \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN
#endif
#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) \
do { \
#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \
const wchar_t *strEnd = (const wchar_t *)(str); \
size_t len = 0; \
while (len < (maxLen) && *strEnd != L'\0') { \
@@ -224,20 +208,15 @@
++strEnd; \
} \
*(outLen) = len; \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
/* Performance optimization, product may disable inline function */
#ifdef SECUREC_USE_ASM
#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) \
(void)memcpy_opt((dest), (src), (count))
#define SECUREC_MEMSET_WARP_OPT(dest, c, count) \
(void)memset_opt((dest), (c), (count))
#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy_opt((dest), (src), (count))
#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset_opt((dest), (c), (count))
#else
#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) \
(void)memcpy((dest), (src), (count))
#define SECUREC_MEMSET_WARP_OPT(dest, c, count) \
(void)memset((dest), (c), (count))
#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy((dest), (src), (count))
#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset((dest), (c), (count))
#endif
#ifdef SECUREC_FORMAT_OUTPUT_INPUT
@@ -278,12 +257,11 @@ typedef unsigned int SecUnsignedInt;
* Determine whether the address is 8-byte aligned
* Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507
*/
#define SECUREC_ADDR_ALIGNED_8(addr) \
((((size_t)(addr)) & 7) == 0) /* Use 7 to check aligned 8 */
#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7) == 0) /* Use 7 to check aligned 8 */
/*
* If you define the memory allocation function, you need to define the function
* prototype. You can define this macro as a header file.
* If you define the memory allocation function, you need to define the function prototype.
* You can define this macro as a header file.
*/
#if defined(SECUREC_MALLOC_PROTOTYPE)
SECUREC_MALLOC_PROTOTYPE
@@ -299,260 +277,196 @@ SECUREC_MALLOC_PROTOTYPE
/* Struct for performance */
typedef struct {
unsigned char buf[1]; /* Performance optimization code structure assignment
length 1 bytes */
unsigned char buf[1]; /* Performance optimization code structure assignment length 1 bytes */
} SecStrBuf1;
typedef struct {
unsigned char buf[2]; /* Performance optimization code structure assignment
length 2 bytes */
unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */
} SecStrBuf2;
typedef struct {
unsigned char buf[3]; /* Performance optimization code structure assignment
length 3 bytes */
unsigned char buf[3]; /* Performance optimization code structure assignment length 3 bytes */
} SecStrBuf3;
typedef struct {
unsigned char buf[4]; /* Performance optimization code structure assignment
length 4 bytes */
unsigned char buf[4]; /* Performance optimization code structure assignment length 4 bytes */
} SecStrBuf4;
typedef struct {
unsigned char buf[5]; /* Performance optimization code structure assignment
length 5 bytes */
unsigned char buf[5]; /* Performance optimization code structure assignment length 5 bytes */
} SecStrBuf5;
typedef struct {
unsigned char buf[6]; /* Performance optimization code structure assignment
length 6 bytes */
unsigned char buf[6]; /* Performance optimization code structure assignment length 6 bytes */
} SecStrBuf6;
typedef struct {
unsigned char buf[7]; /* Performance optimization code structure assignment
length 7 bytes */
unsigned char buf[7]; /* Performance optimization code structure assignment length 7 bytes */
} SecStrBuf7;
typedef struct {
unsigned char buf[8]; /* Performance optimization code structure assignment
length 8 bytes */
unsigned char buf[8]; /* Performance optimization code structure assignment length 8 bytes */
} SecStrBuf8;
typedef struct {
unsigned char buf[9]; /* Performance optimization code structure assignment
length 9 bytes */
unsigned char buf[9]; /* Performance optimization code structure assignment length 9 bytes */
} SecStrBuf9;
typedef struct {
unsigned char buf[10]; /* Performance optimization code structure assignment
length 10 bytes */
unsigned char buf[10]; /* Performance optimization code structure assignment length 10 bytes */
} SecStrBuf10;
typedef struct {
unsigned char buf[11]; /* Performance optimization code structure assignment
length 11 bytes */
unsigned char buf[11]; /* Performance optimization code structure assignment length 11 bytes */
} SecStrBuf11;
typedef struct {
unsigned char buf[12]; /* Performance optimization code structure assignment
length 12 bytes */
unsigned char buf[12]; /* Performance optimization code structure assignment length 12 bytes */
} SecStrBuf12;
typedef struct {
unsigned char buf[13]; /* Performance optimization code structure assignment
length 13 bytes */
unsigned char buf[13]; /* Performance optimization code structure assignment length 13 bytes */
} SecStrBuf13;
typedef struct {
unsigned char buf[14]; /* Performance optimization code structure assignment
length 14 bytes */
unsigned char buf[14]; /* Performance optimization code structure assignment length 14 bytes */
} SecStrBuf14;
typedef struct {
unsigned char buf[15]; /* Performance optimization code structure assignment
length 15 bytes */
unsigned char buf[15]; /* Performance optimization code structure assignment length 15 bytes */
} SecStrBuf15;
typedef struct {
unsigned char buf[16]; /* Performance optimization code structure assignment
length 16 bytes */
unsigned char buf[16]; /* Performance optimization code structure assignment length 16 bytes */
} SecStrBuf16;
typedef struct {
unsigned char buf[17]; /* Performance optimization code structure assignment
length 17 bytes */
unsigned char buf[17]; /* Performance optimization code structure assignment length 17 bytes */
} SecStrBuf17;
typedef struct {
unsigned char buf[18]; /* Performance optimization code structure assignment
length 18 bytes */
unsigned char buf[18]; /* Performance optimization code structure assignment length 18 bytes */
} SecStrBuf18;
typedef struct {
unsigned char buf[19]; /* Performance optimization code structure assignment
length 19 bytes */
unsigned char buf[19]; /* Performance optimization code structure assignment length 19 bytes */
} SecStrBuf19;
typedef struct {
unsigned char buf[20]; /* Performance optimization code structure assignment
length 20 bytes */
unsigned char buf[20]; /* Performance optimization code structure assignment length 20 bytes */
} SecStrBuf20;
typedef struct {
unsigned char buf[21]; /* Performance optimization code structure assignment
length 21 bytes */
unsigned char buf[21]; /* Performance optimization code structure assignment length 21 bytes */
} SecStrBuf21;
typedef struct {
unsigned char buf[22]; /* Performance optimization code structure assignment
length 22 bytes */
unsigned char buf[22]; /* Performance optimization code structure assignment length 22 bytes */
} SecStrBuf22;
typedef struct {
unsigned char buf[23]; /* Performance optimization code structure assignment
length 23 bytes */
unsigned char buf[23]; /* Performance optimization code structure assignment length 23 bytes */
} SecStrBuf23;
typedef struct {
unsigned char buf[24]; /* Performance optimization code structure assignment
length 24 bytes */
unsigned char buf[24]; /* Performance optimization code structure assignment length 24 bytes */
} SecStrBuf24;
typedef struct {
unsigned char buf[25]; /* Performance optimization code structure assignment
length 25 bytes */
unsigned char buf[25]; /* Performance optimization code structure assignment length 25 bytes */
} SecStrBuf25;
typedef struct {
unsigned char buf[26]; /* Performance optimization code structure assignment
length 26 bytes */
unsigned char buf[26]; /* Performance optimization code structure assignment length 26 bytes */
} SecStrBuf26;
typedef struct {
unsigned char buf[27]; /* Performance optimization code structure assignment
length 27 bytes */
unsigned char buf[27]; /* Performance optimization code structure assignment length 27 bytes */
} SecStrBuf27;
typedef struct {
unsigned char buf[28]; /* Performance optimization code structure assignment
length 28 bytes */
unsigned char buf[28]; /* Performance optimization code structure assignment length 28 bytes */
} SecStrBuf28;
typedef struct {
unsigned char buf[29]; /* Performance optimization code structure assignment
length 29 bytes */
unsigned char buf[29]; /* Performance optimization code structure assignment length 29 bytes */
} SecStrBuf29;
typedef struct {
unsigned char buf[30]; /* Performance optimization code structure assignment
length 30 bytes */
unsigned char buf[30]; /* Performance optimization code structure assignment length 30 bytes */
} SecStrBuf30;
typedef struct {
unsigned char buf[31]; /* Performance optimization code structure assignment
length 31 bytes */
unsigned char buf[31]; /* Performance optimization code structure assignment length 31 bytes */
} SecStrBuf31;
typedef struct {
unsigned char buf[32]; /* Performance optimization code structure assignment
length 32 bytes */
unsigned char buf[32]; /* Performance optimization code structure assignment length 32 bytes */
} SecStrBuf32;
typedef struct {
unsigned char buf[33]; /* Performance optimization code structure assignment
length 33 bytes */
unsigned char buf[33]; /* Performance optimization code structure assignment length 33 bytes */
} SecStrBuf33;
typedef struct {
unsigned char buf[34]; /* Performance optimization code structure assignment
length 34 bytes */
unsigned char buf[34]; /* Performance optimization code structure assignment length 34 bytes */
} SecStrBuf34;
typedef struct {
unsigned char buf[35]; /* Performance optimization code structure assignment
length 35 bytes */
unsigned char buf[35]; /* Performance optimization code structure assignment length 35 bytes */
} SecStrBuf35;
typedef struct {
unsigned char buf[36]; /* Performance optimization code structure assignment
length 36 bytes */
unsigned char buf[36]; /* Performance optimization code structure assignment length 36 bytes */
} SecStrBuf36;
typedef struct {
unsigned char buf[37]; /* Performance optimization code structure assignment
length 37 bytes */
unsigned char buf[37]; /* Performance optimization code structure assignment length 37 bytes */
} SecStrBuf37;
typedef struct {
unsigned char buf[38]; /* Performance optimization code structure assignment
length 38 bytes */
unsigned char buf[38]; /* Performance optimization code structure assignment length 38 bytes */
} SecStrBuf38;
typedef struct {
unsigned char buf[39]; /* Performance optimization code structure assignment
length 39 bytes */
unsigned char buf[39]; /* Performance optimization code structure assignment length 39 bytes */
} SecStrBuf39;
typedef struct {
unsigned char buf[40]; /* Performance optimization code structure assignment
length 40 bytes */
unsigned char buf[40]; /* Performance optimization code structure assignment length 40 bytes */
} SecStrBuf40;
typedef struct {
unsigned char buf[41]; /* Performance optimization code structure assignment
length 41 bytes */
unsigned char buf[41]; /* Performance optimization code structure assignment length 41 bytes */
} SecStrBuf41;
typedef struct {
unsigned char buf[42]; /* Performance optimization code structure assignment
length 42 bytes */
unsigned char buf[42]; /* Performance optimization code structure assignment length 42 bytes */
} SecStrBuf42;
typedef struct {
unsigned char buf[43]; /* Performance optimization code structure assignment
length 43 bytes */
unsigned char buf[43]; /* Performance optimization code structure assignment length 43 bytes */
} SecStrBuf43;
typedef struct {
unsigned char buf[44]; /* Performance optimization code structure assignment
length 44 bytes */
unsigned char buf[44]; /* Performance optimization code structure assignment length 44 bytes */
} SecStrBuf44;
typedef struct {
unsigned char buf[45]; /* Performance optimization code structure assignment
length 45 bytes */
unsigned char buf[45]; /* Performance optimization code structure assignment length 45 bytes */
} SecStrBuf45;
typedef struct {
unsigned char buf[46]; /* Performance optimization code structure assignment
length 46 bytes */
unsigned char buf[46]; /* Performance optimization code structure assignment length 46 bytes */
} SecStrBuf46;
typedef struct {
unsigned char buf[47]; /* Performance optimization code structure assignment
length 47 bytes */
unsigned char buf[47]; /* Performance optimization code structure assignment length 47 bytes */
} SecStrBuf47;
typedef struct {
unsigned char buf[48]; /* Performance optimization code structure assignment
length 48 bytes */
unsigned char buf[48]; /* Performance optimization code structure assignment length 48 bytes */
} SecStrBuf48;
typedef struct {
unsigned char buf[49]; /* Performance optimization code structure assignment
length 49 bytes */
unsigned char buf[49]; /* Performance optimization code structure assignment length 49 bytes */
} SecStrBuf49;
typedef struct {
unsigned char buf[50]; /* Performance optimization code structure assignment
length 50 bytes */
unsigned char buf[50]; /* Performance optimization code structure assignment length 50 bytes */
} SecStrBuf50;
typedef struct {
unsigned char buf[51]; /* Performance optimization code structure assignment
length 51 bytes */
unsigned char buf[51]; /* Performance optimization code structure assignment length 51 bytes */
} SecStrBuf51;
typedef struct {
unsigned char buf[52]; /* Performance optimization code structure assignment
length 52 bytes */
unsigned char buf[52]; /* Performance optimization code structure assignment length 52 bytes */
} SecStrBuf52;
typedef struct {
unsigned char buf[53]; /* Performance optimization code structure assignment
length 53 bytes */
unsigned char buf[53]; /* Performance optimization code structure assignment length 53 bytes */
} SecStrBuf53;
typedef struct {
unsigned char buf[54]; /* Performance optimization code structure assignment
length 54 bytes */
unsigned char buf[54]; /* Performance optimization code structure assignment length 54 bytes */
} SecStrBuf54;
typedef struct {
unsigned char buf[55]; /* Performance optimization code structure assignment
length 55 bytes */
unsigned char buf[55]; /* Performance optimization code structure assignment length 55 bytes */
} SecStrBuf55;
typedef struct {
unsigned char buf[56]; /* Performance optimization code structure assignment
length 56 bytes */
unsigned char buf[56]; /* Performance optimization code structure assignment length 56 bytes */
} SecStrBuf56;
typedef struct {
unsigned char buf[57]; /* Performance optimization code structure assignment
length 57 bytes */
unsigned char buf[57]; /* Performance optimization code structure assignment length 57 bytes */
} SecStrBuf57;
typedef struct {
unsigned char buf[58]; /* Performance optimization code structure assignment
length 58 bytes */
unsigned char buf[58]; /* Performance optimization code structure assignment length 58 bytes */
} SecStrBuf58;
typedef struct {
unsigned char buf[59]; /* Performance optimization code structure assignment
length 59 bytes */
unsigned char buf[59]; /* Performance optimization code structure assignment length 59 bytes */
} SecStrBuf59;
typedef struct {
unsigned char buf[60]; /* Performance optimization code structure assignment
length 60 bytes */
unsigned char buf[60]; /* Performance optimization code structure assignment length 60 bytes */
} SecStrBuf60;
typedef struct {
unsigned char buf[61]; /* Performance optimization code structure assignment
length 61 bytes */
unsigned char buf[61]; /* Performance optimization code structure assignment length 61 bytes */
} SecStrBuf61;
typedef struct {
unsigned char buf[62]; /* Performance optimization code structure assignment
length 62 bytes */
unsigned char buf[62]; /* Performance optimization code structure assignment length 62 bytes */
} SecStrBuf62;
typedef struct {
unsigned char buf[63]; /* Performance optimization code structure assignment
length 63 bytes */
unsigned char buf[63]; /* Performance optimization code structure assignment length 63 bytes */
} SecStrBuf63;
typedef struct {
unsigned char buf[64]; /* Performance optimization code structure assignment
length 64 bytes */
unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */
} SecStrBuf64;
/*
@@ -561,29 +475,23 @@ typedef struct {
*/
#if defined(_DEBUG) || defined(DEBUG)
#if defined(SECUREC_ERROR_HANDLER_BY_ASSERT)
#define SECUREC_ERROR_INVALID_PARAMTER(msg) \
assert(msg "invalid argument" == NULL)
#define SECUREC_ERROR_INVALID_RANGE(msg) \
assert(msg "invalid dest buffer size" == NULL)
#define SECUREC_ERROR_INVALID_PARAMTER(msg) assert(msg "invalid argument" == NULL)
#define SECUREC_ERROR_INVALID_RANGE(msg) assert(msg "invalid dest buffer size" == NULL)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL)
#elif defined(SECUREC_ERROR_HANDLER_BY_PRINTF)
#if SECUREC_IN_KERNEL
#define SECUREC_ERROR_INVALID_PARAMTER(msg) printk("%s invalid argument\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) \
printk("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) printk("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg)
#else
#define SECUREC_ERROR_INVALID_PARAMTER(msg) printf("%s invalid argument\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) \
printf("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) printf("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg)
#endif
#elif defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
#define SECUREC_ERROR_INVALID_PARAMTER(msg) \
LogSecureCRuntimeError(msg " EINVAL\n")
#define SECUREC_ERROR_INVALID_PARAMTER(msg) LogSecureCRuntimeError(msg " EINVAL\n")
#define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n")
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) \
LogSecureCRuntimeError(msg " EOVERLAP\n")
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) LogSecureCRuntimeError(msg " EOVERLAP\n")
#endif
#endif
@@ -616,3 +524,4 @@ extern void LogSecureCRuntimeError(const char *errDetail);
}
#endif /* __cplusplus */
#endif
@@ -1,8 +1,9 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: By defining data type for ANSI string and including "input.inl",
* this file generates real underlying function used by scanf
* family API. Author: lishunda Create: 2014-02-25
* this file generates real underlying function used by scanf family API.
* Author: lishunda
* Create: 2014-02-25
*/
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifdef SECUREC_FOR_WCHAR
@@ -13,13 +14,17 @@
#include "input.inl"
SECUREC_INLINE int SecIsDigit(SecInt ch) {
SECUREC_INLINE int SecIsDigit(SecInt ch)
{
/* SecInt to unsigned char clear 571 */
return isdigit((unsigned char)(ch) & 0x00ff);
}
SECUREC_INLINE int SecIsXdigit(SecInt ch) {
SECUREC_INLINE int SecIsXdigit(SecInt ch)
{
return isxdigit((unsigned char)(ch) & 0x00ff);
}
SECUREC_INLINE int SecIsSpace(SecInt ch) {
SECUREC_INLINE int SecIsSpace(SecInt ch)
{
return isspace((unsigned char)(ch) & 0x00ff);
}
@@ -1,8 +1,9 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: By defining data type for UNICODE string and including
* "input.inl", this file generates real underlying function used by scanf
* family API. Author: lishunda Create: 2014-02-25
* Description: By defining data type for UNICODE string and including "input.inl",
* this file generates real underlying function used by scanf family API.
* Author: lishunda
* Create: 2014-02-25
*/
/* If some platforms don't have wchar.h, dont't include it */
@@ -32,13 +33,19 @@
#include "input.inl"
SECUREC_INLINE int SecIsDigit(SecInt ch) {
SECUREC_INLINE int SecIsDigit(SecInt ch)
{
/* Convert int to unsigned int clear 571 */
return (!((unsigned int)(int)(ch)&0xff00) &&
isdigit(((unsigned int)(int)(ch)&0x00ff)));
return (!((unsigned int)(int)(ch) & 0xff00) && isdigit(((unsigned int)(int)(ch) & 0x00ff)));
}
SECUREC_INLINE int SecIsXdigit(SecInt ch) {
return (!((unsigned int)(int)(ch)&0xff00) &&
isxdigit(((unsigned int)(int)(ch)&0x00ff)));
SECUREC_INLINE int SecIsXdigit(SecInt ch)
{
return (!((unsigned int)(int)(ch) & 0xff00) && isxdigit(((unsigned int)(int)(ch) & 0x00ff)));
}
SECUREC_INLINE int SecIsSpace(SecInt ch) { return iswspace((wint_t)(int)(ch)); }
SECUREC_INLINE int SecIsSpace(SecInt ch)
{
return iswspace((wint_t)(int)(ch));
}
@@ -1,7 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: Define macro, enum, data struct, and declare internal used
* function prototype, which is used by output.inl, secureprintoutput_w.c and
* Description: Define macro, enum, data struct, and declare internal used function
* prototype, which is used by output.inl, secureprintoutput_w.c and
* secureprintoutput_a.c.
* Author: lishunda
* Create: 2014-02-25
@@ -13,8 +13,7 @@
/*
* Flag definitions.
* Using macros instead of enumerations is because some of the enumerated types
* under the compiler are 16bit.
* Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit.
*/
#define SECUREC_FLAG_SIGN 0x00001U
#define SECUREC_FLAG_SIGN_SPACE 0x00002U
@@ -57,6 +56,7 @@ typedef struct {
char *cur;
} SecPrintfStream;
#ifndef SECUREC_BUFFER_SIZE
#if SECUREC_IN_KERNEL
#define SECUREC_BUFFER_SIZE 32
@@ -73,55 +73,48 @@ typedef struct {
#if SECUREC_BUFFER_SIZE < 23
#error SECUREC_BUFFER_SIZE Can not be less than 23
#endif
/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as
* possible */
/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as possible */
#define SECUREC_WCHAR_BUFFER_SIZE 4
#define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE
/* Max. # bytes in multibyte char ,see MB_LEN_MAX */
#define SECUREC_MB_LEN 16
/* The return value of the internal function, which is returned when truncated
*/
/* The return value of the internal function, which is returned when truncated */
#define SECUREC_PRINTF_TRUNCATE (-2)
#define SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, maxLimit) \
((format) == NULL || (strDest) == NULL || (destMax) == 0 || \
(destMax) > (maxLimit))
((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit))
#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) \
do { \
#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) do { \
if ((strDest) != NULL && (destMax) > 0 && (destMax) <= (maxLimit)) { \
*(strDest) = '\0'; \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, \
maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || \
(destMax) > (maxLimit)) || \
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
((count) > (SECUREC_STRING_MAX_LEN - 1) && (count) != (size_t)(-1)))
#else
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, \
maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || \
(destMax) > (maxLimit)) || \
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
((count) > (SECUREC_STRING_MAX_LEN - 1)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int SecVsnprintfImpl(char *string, size_t count, const char *format,
va_list argList);
extern int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList);
#if SECUREC_IN_KERNEL == 0
extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar,
const wchar_t *format, va_list argList);
extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList);
#endif
#ifdef __cplusplus
}
#endif
#endif
@@ -1,8 +1,9 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: By defining corresponding macro for ANSI string and including
* "output.inl", this file generates real underlying function used by printf
* family API. Author: lishunda Create: 2014-02-25
* Description: By defining corresponding macro for ANSI string and including "output.inl",
* this file generates real underlying function used by printf family API.
* Author: lishunda
* Create: 2014-02-25
*/
#define SECUREC_FORMAT_OUTPUT_INPUT 1
@@ -18,24 +19,22 @@ static const unsigned char g_flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = {
/*
* Known flag is "0123456789 +-#hlLwZzjqt*I"
*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
};
SECUREC_INLINE const char *SecSkipKnownFlags(const char *format) {
SECUREC_INLINE const char *SecSkipKnownFlags(const char *format)
{
const char *fmt = format;
while (*fmt != '\0') {
char fmtChar = *fmt;
if ((unsigned char)fmtChar >
0x7f) { /* 0x7f is upper limit of format char value */
if ((unsigned char)fmtChar > 0x7f) { /* 0x7f is upper limit of format char value */
break;
}
if (g_flagTable[(unsigned char)fmtChar] == 0) {
@@ -46,7 +45,8 @@ SECUREC_INLINE const char *SecSkipKnownFlags(const char *format) {
return fmt;
}
SECUREC_INLINE int SecFormatContainN(const char *format) {
SECUREC_INLINE int SecFormatContainN(const char *format)
{
const char *fmt = format;
while (*fmt != '\0') {
++fmt;
@@ -68,19 +68,17 @@ SECUREC_INLINE int SecFormatContainN(const char *format) {
return 0;
}
/*
* Multi character formatted output implementation, the count include \0
* character, must be greater than zero
* Multi character formatted output implementation, the count include \0 character, must be greater than zero
*/
int SecVsnprintfImpl(char *string, size_t count, const char *format,
va_list argList) {
int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
{
int retVal;
if (SecFormatContainN(format)) {
string[0] = '\0';
return -1;
}
retVal = vsnprintf(string, count, format, argList);
if (retVal >= (int)count) { /* The size_t to int is ok, count max is
SECUREC_STRING_MAX_LEN */
if (retVal >= (int)count) { /* The size_t to int is ok, count max is SECUREC_STRING_MAX_LEN */
/* The buffer was too small; we return truncation */
string[count - 1] = '\0';
return SECUREC_PRINTF_TRUNCATE;
@@ -103,23 +101,20 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format,
#define EOF (-1)
#endif
SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f,
int *pnumwritten);
SECUREC_INLINE void SecWriteString(const char *string, int len,
SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten);
#include "output.inl"
/*
* Multi character formatted output implementation
*/
int SecVsnprintfImpl(char *string, size_t count, const char *format,
va_list argList) {
int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
{
SecPrintfStream str;
int retVal;
str.count = (int)
count; /* The count include \0 character, must be greater than zero */
str.count = (int)count; /* The count include \0 character, must be greater than zero */
str.cur = string;
retVal = SecOutputS(&str, format, argList);
@@ -137,8 +132,8 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format,
/*
* Write a wide character
*/
SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f,
int *pnumwritten) {
SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten)
{
int count = num;
while (count-- > 0 && --(f->count) >= 0) {
*(f->cur) = ch;
@@ -151,11 +146,10 @@ SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f,
}
/*
* Write string function, where this function is called, make sure that len is
* greater than 0
* Write string function, where this function is called, make sure that len is greater than 0
*/
SECUREC_INLINE void SecWriteString(const char *string, int len,
SecPrintfStream *f, int *pnumwritten) {
SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten)
{
const char *str = string;
int count = len;
while (count-- > 0 && --(f->count) >= 0) {
@@ -169,3 +163,4 @@ SECUREC_INLINE void SecWriteString(const char *string, int len,
}
}
#endif
@@ -1,8 +1,9 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved.
* Description: By defining corresponding macro for UNICODE string and including
* "output.inl", this file generates real underlying function used by printf
* family API. Author: lishunda Create: 2014-02-25
* Description: By defining corresponding macro for UNICODE string and including "output.inl",
* this file generates real underlying function used by printf family API.
* Author: lishunda
* Create: 2014-02-25
*/
/* If some platforms don't have wchar.h, dont't include it */
@@ -38,22 +39,18 @@
#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiCharW
#define SECUREC_WRITE_STRING SecWriteStringW
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f,
int *pnumwritten);
SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f,
int *pnumwritten);
SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len,
SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str,
int zeroCount);
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount);
#include "output.inl"
/*
* Wide character formatted output implementation
*/
int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format,
va_list argList) {
int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList)
{
SecPrintfStream str;
int retVal; /* If initialization causes e838 */
@@ -62,8 +59,7 @@ int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format,
str.count = (int)(sizeInWchar * sizeof(wchar_t));
retVal = SecOutputSW(&str, format, argList);
if (retVal >= 0 &&
SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) {
if (retVal >= 0 && SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) {
return (retVal);
} else if (str.count < 0) {
/* The buffer was too small; we return truncation */
@@ -77,8 +73,8 @@ int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format,
/*
* Output a wide character zero end into the SecPrintfStream structure
*/
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str,
int zeroCount) {
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount)
{
int i = 0;
while (i < zeroCount && SecPutZeroChar(str) == 0) {
++i;
@@ -92,7 +88,8 @@ SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str,
/*
* Output a wide character into the SecPrintfStream structure
*/
SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f) {
SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f)
{
if (((f)->count -= (int)sizeof(wchar_t)) >= 0) {
*(wchar_t *)(void *)(f->cur) = ch;
f->cur += sizeof(wchar_t);
@@ -102,11 +99,10 @@ SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f) {
}
/*
* Output a wide character into the SecPrintfStream structure, returns the
* number of characters written
* Output a wide character into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f,
int *pnumwritten) {
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten)
{
if (SecPutCharW(ch, f) == 0) {
*pnumwritten = *pnumwritten + 1;
} else {
@@ -115,11 +111,10 @@ SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f,
}
/*
* Output multiple wide character into the SecPrintfStream structure, returns
* the number of characters written
* Output multiple wide character into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f,
int *pnumwritten) {
SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten)
{
int count = num;
while (count-- > 0) {
SecWriteCharW(ch, f, pnumwritten);
@@ -130,11 +125,10 @@ SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f,
}
/*
* Output a wide string into the SecPrintfStream structure, returns the number
* of characters written
* Output a wide string into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len,
SecPrintfStream *f, int *pnumwritten) {
SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten)
{
const wchar_t *str = string;
int count = len;
while (count-- > 0) {
@@ -145,3 +139,4 @@ SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len,
}
}
}
@@ -11,19 +11,18 @@
/*
* <FUNCTION DESCRIPTION>
* The snprintf_s function is equivalent to the snprintf function
* except for the parameter destMax/count and the explicit
* runtime-constraints violation The snprintf_s function formats and stores
* count or fewer characters in strDest and appends a terminating null. Each
* argument (if any) is converted and output according to the corresponding
* format specification in format. The formatting is consistent with the printf
* family of functions; If copying occurs between strings that overlap, the
* behavior is undefined.
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The snprintf_s function formats and stores count or fewer characters in
* strDest and appends a terminating null. Each argument (if any) is converted
* and output according to the corresponding format specification in format.
* The formatting is consistent with the printf family of functions; If copying
* occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the storage location for output. Size
* in bytes for snprintf_s or size in words for
* snwprintf_s. count Maximum number of character to store.
* in bytes for snprintf_s or size in words for snwprintf_s.
* count Maximum number of character to store.
* format Format-control string.
* ... Optional arguments.
*
@@ -31,24 +30,22 @@
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating
* null return -1 if an error occurs. return -1 if count < destMax and the
* output string has been truncated
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return -1 if count < destMax and the output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*
*/
int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
...) {
int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsnprintf_s(strDest, destMax, count, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -61,43 +58,40 @@ EXPORT_SYMBOL(snprintf_s);
/*
* <FUNCTION DESCRIPTION>
* The snprintf_truncated_s function is equivalent to the snprintf function
* except for the parameter destMax/count and the explicit
* runtime-constraints violation The snprintf_truncated_s function formats and
* stores count or fewer characters in strDest and appends a terminating null.
* Each argument (if any) is converted and output according to the corresponding
* format specification in format. The formatting is consistent with the printf
* family of functions; If copying occurs between strings that overlap, the
* behavior is undefined.
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The snprintf_truncated_s function formats and stores count or fewer characters in
* strDest and appends a terminating null. Each argument (if any) is converted
* and output according to the corresponding format specification in format.
* The formatting is consistent with the printf family of functions; If copying
* occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the storage location for output. Size
* in bytes for snprintf_truncated_s or size in
* words for snwprintf_s. format Format-control string.
* in bytes for snprintf_truncated_s or size in words for snwprintf_s.
* format Format-control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating
* null return -1 if an error occurs. return destMax-1 if output string has
* been truncated
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return destMax-1 if output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*
*/
int snprintf_truncated_s(char *strDest, size_t destMax, const char *format,
...) {
int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsnprintf_truncated_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -106,3 +100,5 @@ EXPORT_SYMBOL(snprintf_truncated_s);
#endif
#endif
@@ -10,14 +10,13 @@
/*
* <FUNCTION DESCRIPTION>
* The sprintf_s function is equivalent to the sprintf function
* except for the parameter destMax and the explicit runtime-constraints
* violation The sprintf_s function formats and stores a series of characters
* and values in strDest. Each argument (if any) is converted and output
* according to the corresponding format specification in format. The format
* consists of ordinary characters and has the same form and function as the
* format argument for printf. A null character is appended after the last
* character written. If copying occurs between strings that overlap, the
* behavior is undefined.
* except for the parameter destMax and the explicit runtime-constraints violation
* The sprintf_s function formats and stores a series of characters and values
* in strDest. Each argument (if any) is converted and output according to
* the corresponding format specification in format. The format consists of
* ordinary characters and has the same form and function as the format argument
* for printf. A null character is appended after the last character written.
* If copying occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for output.
@@ -29,24 +28,25 @@
* strDest is updated
*
* <RETURN VALUE>
* return the number of bytes stored in strDest, not counting the terminating
* null character. return -1 if an error occurred.
* return the number of bytes stored in strDest, not counting the terminating null character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int sprintf_s(char *strDest, size_t destMax, const char *format, ...) {
int sprintf_s(char *strDest, size_t destMax, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsprintf_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(sprintf_s);
#endif
@@ -10,13 +10,13 @@
/*
* <FUNCTION DESCRIPTION>
* The sscanf_s function is equivalent to fscanf_s,
* except that input is obtained from a string (specified by the argument
* buffer) rather than from a stream The sscanf function reads data from buffer
* into the location given by each argument. Every argument must be a pointer to
* a variable with a type that corresponds to a type specifier in format. The
* format argument controls the interpretation of the input fields and has the
* same form and function as the format argument for the scanf function. If
* copying takes place between strings that overlap, the behavior is undefined.
* except that input is obtained from a string (specified by the argument buffer) rather than from a stream
* The sscanf function reads data from buffer into the location given by each
* argument. Every argument must be a pointer to a variable with a type that
* corresponds to a type specifier in format. The format argument controls the
* interpretation of the input fields and has the same form and function as
* the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data.
@@ -27,23 +27,26 @@
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int sscanf_s(const char *buffer, const char *format, ...) {
int sscanf_s(const char *buffer, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsscanf_s(buffer, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(sscanf_s);
#endif
@@ -10,8 +10,8 @@
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax,
const char *strSrc) {
SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSrc)
{
size_t destLen;
size_t srcLen;
size_t maxSrcLen;
@@ -38,18 +38,16 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax,
SECUREC_ERROR_INVALID_RANGE("strcat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc,
srcLen + 1); /* Single character length include \0 */
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen + 1); /* Single character length include \0 */
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The strcat_s function appends a copy of the string pointed to by strSrc
* (including the terminating null character) to the end of the string pointed
* to by strDest. The initial character of strSrc overwrites the terminating
* null character of strDest. strcat_s will return EOVERLAP_AND_RESET if the
* source and destination strings overlap.
* The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character)
* to the end of the string pointed to by strDest.
* The initial character of strSrc overwrites the terminating null character of strDest.
* strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap.
*
* Note that the second parameter is the total size of the buffer, not the
* remaining size.
@@ -64,19 +62,17 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
* SECUREC_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and all
* other parameters are valid)or (strDest != NULL and strSrc is NULL and destMax
* != 0 and destMax <= SECUREC_STRING_MAX_LEN) ERANGE destMax is 0
* and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest have not
* enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all
* parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or
* (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc) {
errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strcat_s");
return ERANGE;
@@ -95,3 +91,4 @@ errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strcat_s);
#endif
@@ -21,139 +21,107 @@
#define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL
#endif
/* The purpose of converting to void is to clean up the alarm */
#define SECUREC_SMALL_STR_COPY(strDest, strSrc, srcStrLen) \
do { \
#define SECUREC_SMALL_STR_COPY(strDest, strSrc, srcStrLen) do { \
if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \
/* Use struct assignment */ \
switch (srcStrLen) { \
case 1: \
*(SecStrBuf1 *)(void *)(strDest) = \
*(const SecStrBuf1 *)(const void *)(strSrc); \
*(SecStrBuf1 *)(void *)(strDest) = *(const SecStrBuf1 *)(const void *)(strSrc); \
break; \
case 2: \
*(SecStrBuf2 *)(void *)(strDest) = \
*(const SecStrBuf2 *)(const void *)(strSrc); \
*(SecStrBuf2 *)(void *)(strDest) = *(const SecStrBuf2 *)(const void *)(strSrc); \
break; \
case 3: \
*(SecStrBuf3 *)(void *)(strDest) = \
*(const SecStrBuf3 *)(const void *)(strSrc); \
*(SecStrBuf3 *)(void *)(strDest) = *(const SecStrBuf3 *)(const void *)(strSrc); \
break; \
case 4: \
*(SecStrBuf4 *)(void *)(strDest) = \
*(const SecStrBuf4 *)(const void *)(strSrc); \
*(SecStrBuf4 *)(void *)(strDest) = *(const SecStrBuf4 *)(const void *)(strSrc); \
break; \
case 5: \
*(SecStrBuf5 *)(void *)(strDest) = \
*(const SecStrBuf5 *)(const void *)(strSrc); \
*(SecStrBuf5 *)(void *)(strDest) = *(const SecStrBuf5 *)(const void *)(strSrc); \
break; \
case 6: \
*(SecStrBuf6 *)(void *)(strDest) = \
*(const SecStrBuf6 *)(const void *)(strSrc); \
*(SecStrBuf6 *)(void *)(strDest) = *(const SecStrBuf6 *)(const void *)(strSrc); \
break; \
case 7: \
*(SecStrBuf7 *)(void *)(strDest) = \
*(const SecStrBuf7 *)(const void *)(strSrc); \
*(SecStrBuf7 *)(void *)(strDest) = *(const SecStrBuf7 *)(const void *)(strSrc); \
break; \
case 8: \
*(SecStrBuf8 *)(void *)(strDest) = \
*(const SecStrBuf8 *)(const void *)(strSrc); \
*(SecStrBuf8 *)(void *)(strDest) = *(const SecStrBuf8 *)(const void *)(strSrc); \
break; \
case 9: \
*(SecStrBuf9 *)(void *)(strDest) = \
*(const SecStrBuf9 *)(const void *)(strSrc); \
*(SecStrBuf9 *)(void *)(strDest) = *(const SecStrBuf9 *)(const void *)(strSrc); \
break; \
case 10: \
*(SecStrBuf10 *)(void *)(strDest) = \
*(const SecStrBuf10 *)(const void *)(strSrc); \
*(SecStrBuf10 *)(void *)(strDest) = *(const SecStrBuf10 *)(const void *)(strSrc); \
break; \
case 11: \
*(SecStrBuf11 *)(void *)(strDest) = \
*(const SecStrBuf11 *)(const void *)(strSrc); \
*(SecStrBuf11 *)(void *)(strDest) = *(const SecStrBuf11 *)(const void *)(strSrc); \
break; \
case 12: \
*(SecStrBuf12 *)(void *)(strDest) = \
*(const SecStrBuf12 *)(const void *)(strSrc); \
*(SecStrBuf12 *)(void *)(strDest) = *(const SecStrBuf12 *)(const void *)(strSrc); \
break; \
case 13: \
*(SecStrBuf13 *)(void *)(strDest) = \
*(const SecStrBuf13 *)(const void *)(strSrc); \
*(SecStrBuf13 *)(void *)(strDest) = *(const SecStrBuf13 *)(const void *)(strSrc); \
break; \
case 14: \
*(SecStrBuf14 *)(void *)(strDest) = \
*(const SecStrBuf14 *)(const void *)(strSrc); \
*(SecStrBuf14 *)(void *)(strDest) = *(const SecStrBuf14 *)(const void *)(strSrc); \
break; \
case 15: \
*(SecStrBuf15 *)(void *)(strDest) = \
*(const SecStrBuf15 *)(const void *)(strSrc); \
*(SecStrBuf15 *)(void *)(strDest) = *(const SecStrBuf15 *)(const void *)(strSrc); \
break; \
case 16: \
*(SecStrBuf16 *)(void *)(strDest) = \
*(const SecStrBuf16 *)(const void *)(strSrc); \
*(SecStrBuf16 *)(void *)(strDest) = *(const SecStrBuf16 *)(const void *)(strSrc); \
break; \
case 17: \
*(SecStrBuf17 *)(void *)(strDest) = \
*(const SecStrBuf17 *)(const void *)(strSrc); \
*(SecStrBuf17 *)(void *)(strDest) = *(const SecStrBuf17 *)(const void *)(strSrc); \
break; \
case 18: \
*(SecStrBuf18 *)(void *)(strDest) = \
*(const SecStrBuf18 *)(const void *)(strSrc); \
*(SecStrBuf18 *)(void *)(strDest) = *(const SecStrBuf18 *)(const void *)(strSrc); \
break; \
case 19: \
*(SecStrBuf19 *)(void *)(strDest) = \
*(const SecStrBuf19 *)(const void *)(strSrc); \
*(SecStrBuf19 *)(void *)(strDest) = *(const SecStrBuf19 *)(const void *)(strSrc); \
break; \
case 20: \
*(SecStrBuf20 *)(void *)(strDest) = \
*(const SecStrBuf20 *)(const void *)(strSrc); \
*(SecStrBuf20 *)(void *)(strDest) = *(const SecStrBuf20 *)(const void *)(strSrc); \
break; \
case 21: \
*(SecStrBuf21 *)(void *)(strDest) = \
*(const SecStrBuf21 *)(const void *)(strSrc); \
*(SecStrBuf21 *)(void *)(strDest) = *(const SecStrBuf21 *)(const void *)(strSrc); \
break; \
case 22: \
*(SecStrBuf22 *)(void *)(strDest) = \
*(const SecStrBuf22 *)(const void *)(strSrc); \
*(SecStrBuf22 *)(void *)(strDest) = *(const SecStrBuf22 *)(const void *)(strSrc); \
break; \
case 23: \
*(SecStrBuf23 *)(void *)(strDest) = \
*(const SecStrBuf23 *)(const void *)(strSrc); \
*(SecStrBuf23 *)(void *)(strDest) = *(const SecStrBuf23 *)(const void *)(strSrc); \
break; \
case 24: \
*(SecStrBuf24 *)(void *)(strDest) = \
*(const SecStrBuf24 *)(const void *)(strSrc); \
*(SecStrBuf24 *)(void *)(strDest) = *(const SecStrBuf24 *)(const void *)(strSrc); \
break; \
case 25: \
*(SecStrBuf25 *)(void *)(strDest) = \
*(const SecStrBuf25 *)(const void *)(strSrc); \
*(SecStrBuf25 *)(void *)(strDest) = *(const SecStrBuf25 *)(const void *)(strSrc); \
break; \
case 26: \
*(SecStrBuf26 *)(void *)(strDest) = \
*(const SecStrBuf26 *)(const void *)(strSrc); \
*(SecStrBuf26 *)(void *)(strDest) = *(const SecStrBuf26 *)(const void *)(strSrc); \
break; \
case 27: \
*(SecStrBuf27 *)(void *)(strDest) = \
*(const SecStrBuf27 *)(const void *)(strSrc); \
*(SecStrBuf27 *)(void *)(strDest) = *(const SecStrBuf27 *)(const void *)(strSrc); \
break; \
case 28: \
*(SecStrBuf28 *)(void *)(strDest) = \
*(const SecStrBuf28 *)(const void *)(strSrc); \
*(SecStrBuf28 *)(void *)(strDest) = *(const SecStrBuf28 *)(const void *)(strSrc); \
break; \
case 29: \
*(SecStrBuf29 *)(void *)(strDest) = \
*(const SecStrBuf29 *)(const void *)(strSrc); \
*(SecStrBuf29 *)(void *)(strDest) = *(const SecStrBuf29 *)(const void *)(strSrc); \
break; \
case 30: \
*(SecStrBuf30 *)(void *)(strDest) = \
*(const SecStrBuf30 *)(const void *)(strSrc); \
*(SecStrBuf30 *)(void *)(strDest) = *(const SecStrBuf30 *)(const void *)(strSrc); \
break; \
case 31: \
*(SecStrBuf31 *)(void *)(strDest) = \
*(const SecStrBuf31 *)(const void *)(strSrc); \
*(SecStrBuf31 *)(void *)(strDest) = *(const SecStrBuf31 *)(const void *)(strSrc); \
break; \
case 32: \
*(SecStrBuf32 *)(void *)(strDest) = \
*(const SecStrBuf32 *)(const void *)(strSrc); \
*(SecStrBuf32 *)(void *)(strDest) = *(const SecStrBuf32 *)(const void *)(strSrc); \
break; \
default: \
break; \
@@ -262,33 +230,29 @@
break; \
} \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#endif
#if SECUREC_IN_KERNEL || (SECUREC_STRCPY_WITH_PERFORMANCE == 0)
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) \
SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm))
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm))
#else
/*
* Performance optimization. lenWithTerm include '\0'
*/
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) \
do { \
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) do { \
if ((lenWithTerm) > SECUREC_STRCOPY_THRESHOLD_SIZE) { \
SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)); \
} else { \
SECUREC_SMALL_STR_COPY((dest), (src), (lenWithTerm)); \
} \
} \
SECUREC_WHILE_ZERO
} SECUREC_WHILE_ZERO
#endif
/*
* Check Src Range
*/
SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax,
const char *strSrc) {
SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, const char *strSrc)
{
size_t tmpDestMax = destMax;
const char *tmpSrc = strSrc;
/* Use destMax as boundary checker and destMax must be greater than zero */
@@ -307,7 +271,8 @@ SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax,
/*
* Handling errors
*/
errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) {
errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strcpy_s");
return ERANGE;
@@ -325,10 +290,10 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) {
/*
* <FUNCTION DESCRIPTION>
* The strcpy_s function copies the string pointed to strSrc
* (including the terminating null character) into the array pointed to
* by strDest The destination string must be large enough to hold the source
* string, including the terminating null character. strcpy_s will return
* EOVERLAP_AND_RESET if the source and destination strings overlap.
* (including the terminating null character) into the array pointed to by strDest
* The destination string must be large enough to hold the source string,
* including the terminating null character. strcpy_s will return EOVERLAP_AND_RESET
* if the source and destination strings overlap.
*
* <INPUT PARAMETERS>
* strDest Location of destination string buffer
@@ -340,20 +305,17 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) {
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and
* destMax <= SECUREC_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and
* strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN ERANGE
* destMax is 0 and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest
* have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all
* parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) {
if ((destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN && strDest != NULL &&
strSrc != NULL && strDest != strSrc)) {
errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc)
{
if ((destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN && strDest != NULL && strSrc != NULL && strDest != strSrc)) {
size_t srcStrLen;
SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen);
++srcStrLen; /* The length include '\0' */
@@ -377,3 +339,4 @@ errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strcpy_s);
#endif
@@ -10,8 +10,8 @@
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax,
const char *strSrc, size_t count) {
SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
size_t destLen;
size_t srcLen;
SECUREC_CALC_STR_LEN(strDest, destMax, &destLen);
@@ -39,8 +39,7 @@ SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax,
SECUREC_ERROR_INVALID_RANGE("strncat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc,
srcLen); /* No terminator */
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen); /* No terminator */
*(strDest + destLen + srcLen) = '\0';
return EOK;
}
@@ -49,14 +48,14 @@ SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax,
* <FUNCTION DESCRIPTION>
* The strncat_s function appends not more than n successive characters
* (not including the terminating null character)
* from the array pointed to by strSrc to the end of the string pointed to
* by strDest The strncat_s function try to append the first D characters of
* strSrc to the end of strDest, where D is the lesser of count and the length
* of strSrc. If appending those D characters will fit within strDest (whose
* size is given as destMax) and still leave room for a null terminator, then
* those characters are appended, starting at the original terminating null of
* strDest, and a new terminating null is appended; otherwise, strDest[0] is set
* to the null character.
* from the array pointed to by strSrc to the end of the string pointed to by strDest
* The strncat_s function try to append the first D characters of strSrc to
* the end of strDest, where D is the lesser of count and the length of strSrc.
* If appending those D characters will fit within strDest (whose size is given
* as destMax) and still leave room for a null terminator, then those characters
* are appended, starting at the original terminating null of strDest, and a
* new terminating null is appended; otherwise, strDest[0] is set to the null
* character.
*
* <INPUT PARAMETERS>
* strDest Null-terminated destination string.
@@ -69,20 +68,17 @@ SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
* SECUREC_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and all
* other parameters are valid)or (strDest != NULL and strSrc is NULL and
* destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) ERANGE destMax is 0 and
* destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest have not
* enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all
* parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or
* (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc,
size_t count) {
errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strncat_s");
return ERANGE;
@@ -113,3 +109,4 @@ errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc,
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strncat_s);
#endif
@@ -14,28 +14,24 @@
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && \
(strDest) != NULL && (strSrc) != NULL && \
((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && \
(count) > 0))
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && (count) > 0))
#else
#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && \
(strDest) != NULL && (strSrc) != NULL && \
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
(count) <= SECUREC_STRING_MAX_LEN && (count) > 0))
#endif
/*
* Check Src Count Range
*/
SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax,
const char *strSrc, size_t count) {
SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
size_t tmpDestMax = destMax;
size_t tmpCount = count;
const char *endPos = strSrc;
/* Use destMax and count as boundary checker and destMax must be greater than
* zero */
/* Use destMax and count as boundary checker and destMax must be greater than zero */
while (*(endPos) != '\0' && tmpDestMax > 0 && tmpCount > 0) {
++endPos;
--tmpCount;
@@ -52,8 +48,8 @@ SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax,
/*
* Handling errors, when dest euqal src return EOK
*/
errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc,
size_t count) {
errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE;
@@ -78,34 +74,30 @@ errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc,
/*
* <FUNCTION DESCRIPTION>
* The strncpy_s function copies not more than n successive characters (not
* including the terminating null character) from the array pointed to by strSrc
* to the array pointed to by strDest.
* The strncpy_s function copies not more than n successive characters (not including the terminating null character)
* from the array pointed to by strSrc to the array pointed to by strDest.
*
* <INPUT PARAMETERS>
* strDest Destination string.
* destMax The size of the destination string, in
* characters. strSrc Source string. count Number of
* characters to be copied.
* destMax The size of the destination string, in characters.
* strSrc Source string.
* count Number of characters to be copied.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and
* destMax <= SECUREC_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and
* strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN ERANGE
* destMax is 0 and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest
* have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all
* parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc,
size_t count) {
errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count)) {
size_t minCpLen; /* Use it to store the maxi length limit */
if (count < destMax) {
@@ -117,19 +109,16 @@ errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc,
tmpCount = destMax - 1;
}
#endif
SECUREC_CALC_STR_LEN(strSrc, tmpCount,
&minCpLen); /* No ending terminator */
SECUREC_CALC_STR_LEN(strSrc, tmpCount, &minCpLen); /* No ending terminator */
if (minCpLen == destMax) {
strDest[0] = '\0';
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE_AND_RESET;
}
}
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) ||
strDest == strSrc) {
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) || strDest == strSrc) {
/* Not overlap */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc,
minCpLen); /* Copy string without terminator */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, minCpLen); /* Copy string without terminator */
strDest[minCpLen] = '\0';
return EOK;
} else {
@@ -144,3 +133,4 @@ errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc,
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strncpy_s);
#endif
@@ -7,7 +7,9 @@
#include "securecutil.h"
SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit) {
SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit)
{
const char *ctl = strDelimit;
while (*ctl != '\0' && *ctl != ch) {
++ctl;
@@ -17,10 +19,10 @@ SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit) {
/*
* Find beginning of token (skip over leading delimiters).
* Note that there is no token if this loop sets string to point to the terminal
* null.
* Note that there is no token if this loop sets string to point to the terminal null.
*/
SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit) {
SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit)
{
char *token = strToken;
while (*token != '\0') {
if (SecIsInDelimit(*token, strDelimit)) {
@@ -36,9 +38,9 @@ SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit) {
/*
* Find rest of token
*/
SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) {
/* Find the rest of the token. If it is not the end of the string, put a null
* there */
SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit)
{
/* Find the rest of the token. If it is not the end of the string, put a null there */
char *token = strToken;
while (*token != '\0') {
if (SecIsInDelimit(*token, strDelimit)) {
@@ -55,8 +57,8 @@ SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) {
/*
* Find the final position pointer
*/
SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit,
char **context) {
SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char **context)
{
/* Point to updated position */
char *token = SecFindRest(strToken, strDelimit);
/* Record string position for next search in the context */
@@ -71,22 +73,23 @@ SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit,
/*
* <FUNCTION DESCRIPTION>
* The strtok_s function parses a string into a sequence of strToken,
* replace all characters in strToken string that match to strDelimit set
* with 0. On the first call to strtok_s the string to be parsed should be
* specified in strToken. In each subsequent call that should parse the same
* string, strToken should be NULL <INPUT PARAMETERS> strToken String
* containing token or tokens. strDelimit Set of delimiter characters.
* replace all characters in strToken string that match to strDelimit set with 0.
* On the first call to strtok_s the string to be parsed should be specified in strToken.
* In each subsequent call that should parse the same string, strToken should be NULL
* <INPUT PARAMETERS>
* strToken String containing token or tokens.
* strDelimit Set of delimiter characters.
* context Used to store position information between calls
* to strtok_s
* <OUTPUT PARAMETERS>
* context is updated
* <RETURN VALUE>
* On the first call returns the address of the first non \0 character,
* otherwise NULL is returned. In subsequent calls, the strtoken is set to NULL,
* and the context set is the same as the previous call, return NULL if the
* *context string length is equal 0, otherwise return *context.
* On the first call returns the address of the first non \0 character, otherwise NULL is returned.
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
* return NULL if the *context string length is equal 0, otherwise return *context.
*/
char *strtok_s(char *strToken, const char *strDelimit, char **context) {
char *strtok_s(char *strToken, const char *strDelimit, char **context)
{
char *orgToken = strToken;
/* Validate delimiter and string context */
if (context == NULL || strDelimit == NULL) {
@@ -96,8 +99,7 @@ char *strtok_s(char *strToken, const char *strDelimit, char **context) {
if (orgToken == NULL && *context == NULL) {
return NULL;
}
/* If string is null, continue searching from previous string position stored
* in context */
/* If string is null, continue searching from previous string position stored in context */
if (orgToken == NULL) {
orgToken = *context;
}
@@ -107,3 +109,4 @@ char *strtok_s(char *strToken, const char *strDelimit, char **context) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strtok_s);
#endif
@@ -9,8 +9,7 @@
/*
* <FUNCTION DESCRIPTION>
* The swprintf_s function is the wide-character equivalent of the
* sprintf_s function
* The swprintf_s function is the wide-character equivalent of the sprintf_s function
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
@@ -22,21 +21,22 @@
* strDest is updated
*
* <RETURN VALUE>
* return the number of wide characters stored in strDest, not counting the
* terminating null wide character. return -1 if an error occurred.
* return the number of wide characters stored in strDest, not counting the terminating null wide character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...) {
int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vswprintf_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -9,13 +9,13 @@
/*
* <FUNCTION DESCRIPTION>
* The swscanf_s function is the wide-character equivalent of the
* sscanf_s function The swscanf_s function reads data from buffer into the
* location given by each argument. Every argument must be a pointer to a
* variable with a type that corresponds to a type specifier in format. The
* format argument controls the interpretation of the input fields and has the
* same form and function as the format argument for the scanf function. If
* copying takes place between strings that overlap, the behavior is undefined.
* The swscanf_s function is the wide-character equivalent of the sscanf_s function
* The swscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format. The format argument controls
* the interpretation of the input fields and has the same form and function
* as the format argument for the scanf function. If copying takes place between
* strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data.
@@ -26,20 +26,23 @@
* ... the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; The return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; The return value does not include fields that were read but not
* assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...) {
int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vswscanf_s(buffer, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
@@ -10,12 +10,12 @@
/*
* <FUNCTION DESCRIPTION>
* The vfscanf_s function is equivalent to fscanf_s, with the variable
* argument list replaced by argList The vfscanf_s function reads data from the
* current position of stream into the locations given by argument (if any).
* Each argument must be a pointer to a variable of a type that corresponds to a
* type specifier in format. format controls the interpretation of the input
* fields and has the same form and function as the format argument for scanf.
* The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by argList
* The vfscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
@@ -26,12 +26,13 @@
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vfscanf_s(FILE *stream, const char *format, va_list argList) {
int vfscanf_s(FILE *stream, const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
@@ -54,3 +55,5 @@ int vfscanf_s(FILE *stream, const char *format, va_list argList) {
return retVal;
}
@@ -10,12 +10,12 @@
/*
* <FUNCTION DESCRIPTION>
* The vfwscanf_s function is the wide-character equivalent of the
* vfscanf_s function The vfwscanf_s function reads data from the current
* position of stream into the locations given by argument (if any). Each
* argument must be a pointer to a variable of a type that corresponds to a type
* specifier in format. format controls the interpretation of the input fields
* and has the same form and function as the format argument for scanf.
* The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
* The vfwscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same form
* and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
@@ -26,12 +26,13 @@
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) {
int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
@@ -53,3 +54,5 @@ int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) {
}
return retVal;
}
@@ -10,12 +10,12 @@
/*
* <FUNCTION DESCRIPTION>
* The vscanf_s function is equivalent to scanf_s, with the variable
* argument list replaced by argList, The vscanf_s function reads data from the
* standard input stream stdin and writes the data into the location that's
* given by argument. Each argument must be a pointer to a variable of a type
* that corresponds to a type specifier in format. If copying occurs between
* strings that overlap, the behavior is undefined.
* The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList,
* The vscanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
@@ -30,15 +30,15 @@
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vscanf_s(const char *format, va_list argList) {
int vscanf_s(const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
SecInitFileStreamFromStdin(&fStr);
/*
* The "va_list" has different definition on different platform, so we can't
* use argList == NULL To determine it's invalid. If you has fixed platform,
* you can check some fields to validate it, such as "argList == NULL" or
* argList.xxx != NULL or *(size_t *)&argList != 0.
* The "va_list" has different definition on different platform, so we can't use argList == NULL
* To determine it's invalid. If you has fixed platform, you can check some fields to validate it,
* such as "argList == NULL" or argList.xxx != NULL or *(size_t *)&argList != 0.
*/
if (format == NULL || fStr.pf == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vscanf_s");
@@ -56,3 +56,5 @@ int vscanf_s(const char *format, va_list argList) {
}
return retVal;
}
@@ -11,35 +11,34 @@
/*
* <FUNCTION DESCRIPTION>
* The vsnprintf_s function is equivalent to the vsnprintf function
* except for the parameter destMax/count and the explicit
* runtime-constraints violation The vsnprintf_s function takes a pointer to an
* argument list, then formats and writes up to count characters of the given
* data to the memory pointed to by strDest and appends a terminating null.
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The vsnprintf_s function takes a pointer to an argument list, then formats
* and writes up to count characters of the given data to the memory pointed
* to by strDest and appends a terminating null.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the strDest for output.
* count Maximum number of character to write(not
* including the terminating NULL) format Format-control
* string. argList pointer to list of arguments.
* count Maximum number of character to write(not including
* the terminating NULL)
* format Format-control string.
* argList pointer to list of arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating
* null return -1 if an error occurs. return -1 if count < destMax and the
* output string has been truncated
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return -1 if count < destMax and the output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
va_list argList) {
int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, va_list argList)
{
int retVal;
if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count,
SECUREC_STRING_MAX_LEN)) {
if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
return -1;
@@ -47,8 +46,7 @@ int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
if (destMax > count) {
retVal = SecVsnprintfImpl(strDest, count + 1, format, argList);
if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not
destroyed 2014.2.18 */
if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not destroyed 2014.2.18 */
/* The string has been truncated, return -1 */
return -1; /* To skip error handler, return strlen(strDest) or -1 */
}
@@ -84,11 +82,10 @@ EXPORT_SYMBOL(vsnprintf_s);
/*
* <FUNCTION DESCRIPTION>
* The vsnprintf_truncated_s function is equivalent to the vsnprintf function
* except for the parameter destMax/count and the explicit
* runtime-constraints violation The vsnprintf_truncated_s function takes a
* pointer to an argument list, then formats and writes up to count characters
* of the given data to the memory pointed to by strDest and appends a
* terminating null.
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The vsnprintf_truncated_s function takes a pointer to an argument list, then formats
* and writes up to count characters of the given data to the memory pointed
* to by strDest and appends a terminating null.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
@@ -101,19 +98,17 @@ EXPORT_SYMBOL(vsnprintf_s);
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating
* null return -1 if an error occurs. return destMax-1 if output string has
* been truncated
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return destMax-1 if output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
va_list argList) {
int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_list argList)
{
int retVal;
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax,
SECUREC_STRING_MAX_LEN)) {
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
return -1;
@@ -122,8 +117,7 @@ int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
if (retVal < 0) {
if (retVal == SECUREC_PRINTF_TRUNCATE) {
return (int)(destMax -
1); /* To skip error handler, return strlen(strDest) */
return (int)(destMax - 1); /* To skip error handler, return strlen(strDest) */
}
strDest[0] = '\0'; /* Empty the dest strDest */
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
@@ -136,3 +130,5 @@ int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
EXPORT_SYMBOL(vsnprintf_truncated_s);
#endif
#endif
@@ -10,9 +10,9 @@
/*
* <FUNCTION DESCRIPTION>
* The vsprintf_s function is equivalent to the vsprintf function
* except for the parameter destMax and the explicit runtime-constraints
* violation The vsprintf_s function takes a pointer to an argument list, and
* then formats and writes the given data to the memory pointed to by strDest.
* except for the parameter destMax and the explicit runtime-constraints violation
* The vsprintf_s function takes a pointer to an argument list, and then formats
* and writes the given data to the memory pointed to by strDest.
* The function differ from the non-secure versions only in that the secure
* versions support positional parameters.
*
@@ -26,18 +26,16 @@
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating
* null character, return -1 if an error occurs.
* return the number of characters written, not including the terminating null character,
* return -1 if an error occurs.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsprintf_s(char *strDest, size_t destMax, const char *format,
va_list argList) {
int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax,
SECUREC_STRING_MAX_LEN)) {
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s");
return -1;
@@ -59,3 +57,5 @@ int vsprintf_s(char *strDest, size_t destMax, const char *format,
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsprintf_s);
#endif
@@ -18,14 +18,13 @@
*
*
* <FUNCTION DESCRIPTION>
* The vsscanf_s function is equivalent to sscanf_s, with the variable
* argument list replaced by argList The vsscanf_s function reads data from
* buffer into the location given by each argument. Every argument must be a
* pointer to a variable with a type that corresponds to a type specifier in
* format. The format argument controls the interpretation of the input fields
* and has the same form and function as the format argument for the scanf
* function. If copying takes place between strings that overlap, the behavior
* is undefined.
* The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
* The vsscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format. The format argument controls
* the interpretation of the input fields and has the same form and function
* as the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data
@@ -36,12 +35,13 @@
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vsscanf_s(const char *buffer, const char *format, va_list argList) {
int vsscanf_s(const char *buffer, const char *format, va_list argList)
{
size_t count; /* If initialization causes e838 */
int retVal;
SecFileStream fStr;
@@ -59,10 +59,9 @@ int vsscanf_s(const char *buffer, const char *format, va_list argList) {
}
#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL
/*
* On vxworks platform when buffer is white string, will set first %s argument
* tu zero.like following useage: " \v\f\t\r\n", "%s", str, strSize Do not
* check all character, just first and last character then consider it is
* white string
* On vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage:
* " \v\f\t\r\n", "%s", str, strSize
* Do not check all character, just first and last character then consider it is white string
*/
if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) {
SecClearDestBuf(buffer, format, argList);
@@ -79,3 +78,4 @@ int vsscanf_s(const char *buffer, const char *format, va_list argList) {
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsscanf_s);
#endif
@@ -7,10 +7,10 @@
#include "secureprintoutput.h"
/*
* <FUNCTION DESCRIPTION>
* The vswprintf_s function is the wide-character equivalent of the
* vsprintf_s function
* The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
@@ -22,17 +22,15 @@
* strDest is updated
*
* <RETURN VALUE>
* return the number of wide characters stored in strDest, not counting the
* terminating null wide character. return -1 if an error occurred.
* return the number of wide characters stored in strDest, not counting the terminating null wide character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format,
va_list argList) {
int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax,
SECUREC_WCHAR_STRING_MAX_LEN)) {
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
return -1;
@@ -51,3 +49,5 @@ int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format,
return retVal;
}
@@ -8,7 +8,8 @@
#define SECUREC_INLINE_INIT_FILE_STREAM_STR 1
#include "secinput.h"
SECUREC_INLINE size_t SecWcslen(const wchar_t *s) {
SECUREC_INLINE size_t SecWcslen(const wchar_t *s)
{
const wchar_t *end = s;
while (*end != L'\0') {
++end;
@@ -18,13 +19,13 @@ SECUREC_INLINE size_t SecWcslen(const wchar_t *s) {
/*
* <FUNCTION DESCRIPTION>
* The vswscanf_s function is the wide-character equivalent of the
* vsscanf_s function The vsscanf_s function reads data from buffer into the
* location given by each argument. Every argument must be a pointer to a
* variable with a type that corresponds to a type specifier in format. The
* format argument controls the interpretation of the input fields and has the
* same form and function as the format argument for the scanf function. If
* copying takes place between strings that overlap, the behavior is undefined.
* The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
* The vsscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format.
* The format argument controls the interpretation of the input fields and
* has the same form and function as the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data
@@ -35,12 +36,13 @@ SECUREC_INLINE size_t SecWcslen(const wchar_t *s) {
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully
* converted and assigned; the return value does not include fields that were
* read but not assigned. A return value of 0 indicates that no fields were
* assigned. return -1 if an error occurs.
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) {
int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList)
{
size_t count; /* If initialization causes e838 */
SecFileStream fStr;
int retVal;
@@ -56,8 +58,7 @@ int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) {
SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
return SECUREC_SCANF_EINVAL;
}
SecInitFileStreamFromString(&fStr, (const char *)buffer,
(int)count * ((int)sizeof(wchar_t)));
SecInitFileStreamFromString(&fStr, (const char *)buffer, (int)count * ((int)sizeof(wchar_t)));
retVal = SecInputSW(&fStr, format, argList);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
@@ -65,3 +66,5 @@ int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) {
}
return retVal;
}
@@ -10,13 +10,13 @@
/*
* <FUNCTION DESCRIPTION>
* The vwscanf_s function is the wide-character equivalent of the
* vscanf_s function The vwscanf_s function is the wide-character version of
* vscanf_s. The function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type
* specifier in format. If copying occurs between strings that overlap, the
* behavior is undefined.
* The vwscanf_s function is the wide-character equivalent of the vscanf_s function
* The vwscanf_s function is the wide-character version of vscanf_s. The
* function reads data from the standard input stream stdin and writes the
* data into the location that's given by argument. Each argument must be a
* pointer to a variable of a type that corresponds to a type specifier in
* format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
@@ -31,7 +31,8 @@
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vwscanf_s(const wchar_t *format, va_list argList) {
int vwscanf_s(const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
@@ -54,3 +55,5 @@ int vwscanf_s(const wchar_t *format, va_list argList) {
return retVal;
}
@@ -10,14 +10,13 @@
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc) {
SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
size_t destLen;
size_t srcLen;
size_t maxCount; /* Store the maximum available count */
/* To calculate the length of a wide character, the parameter must be a wide
* character */
/* To calculate the length of a wide character, the parameter must be a wide character */
SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
maxCount = destMax - destLen;
SECUREC_CALC_WSTR_LEN(strSrc, maxCount, &srcLen);
@@ -41,22 +40,21 @@ SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax,
return ERANGE_AND_RESET;
}
/* Copy single character length include \0 */
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc,
(srcLen + 1) * sizeof(wchar_t));
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, (srcLen + 1) * sizeof(wchar_t));
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The wcscat_s function appends a copy of the wide string pointed to by
* strSrc (including the terminating null wide character) to the end of the wide
* string pointed to by strDest. The arguments and return value of wcscat_s are
* wide-character strings.
* The wcscat_s function appends a copy of the wide string pointed to by strSrc
* (including the terminating null wide character)
* to the end of the wide string pointed to by strDest.
* The arguments and return value of wcscat_s are wide-character strings.
*
* The wcscat_s function appends strSrc to strDest and terminates the
* resulting string with a null character. The initial character of strSrc
* overwrites the terminating null character of strDest. wcscat_s will return
* EOVERLAP_AND_RESET if the source and destination strings overlap.
* The wcscat_s function appends strSrc to strDest and terminates the resulting
* string with a null character. The initial character of strSrc overwrites the
* terminating null character of strDest. wcscat_s will return EOVERLAP_AND_RESET if the
* source and destination strings overlap.
*
* Note that the second parameter is the total size of the buffer, not the
* remaining size.
@@ -71,19 +69,18 @@ SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
* SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and
* all other parameters are valid) or (strDest != NULL and strSrc is NULLL and
* destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) ERANGE destMax >
* SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET strDest
* have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* all parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
* (strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) {
errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcscat_s");
return ERANGE;
@@ -100,3 +97,5 @@ errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) {
return SecDoCatW(strDest, destMax, strSrc);
}
@@ -7,8 +7,8 @@
#include "securecutil.h"
SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc) {
SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
size_t srcStrLen;
SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen);
@@ -22,8 +22,7 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax,
}
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
/* Performance optimization, srcStrLen is single character length include
* '\0' */
/* Performance optimization, srcStrLen is single character length include '\0' */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, (srcStrLen + 1) * sizeof(wchar_t));
return EOK;
} else {
@@ -36,8 +35,7 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax,
/*
* <FUNCTION DESCRIPTION>
* The wcscpy_s function copies the wide string pointed to by strSrc
* (including theterminating null wide character) into the array pointed to by
strDest
* (including theterminating null wide character) into the array pointed to by strDest
* <INPUT PARAMETERS>
* strDest Destination string buffer
@@ -49,27 +47,21 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is
0
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET destMax <= length of strSrc and strDest != strSrc
* and strDest != NULL and strSrc != NULL and destMax
!= 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not
overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
destMax != 0
* and strDest != NULL and strSrc != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* and strDest != NULL and strSrc !=NULL and strDest !=
strSrc
* and strDest != NULL and strSrc !=NULL and strDest != strSrc
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
'\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) {
errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcscpy_s");
return ERANGE;
@@ -84,3 +76,5 @@ errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) {
}
return SecDoCpyW(strDest, destMax, strSrc);
}
@@ -10,10 +10,9 @@
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc, size_t count) {
/* To calculate the length of a wide character, the parameter must be a wide
* character */
SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
/* To calculate the length of a wide character, the parameter must be a wide character */
size_t destLen;
size_t srcLen;
SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
@@ -37,8 +36,7 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax,
SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc,
srcLen * sizeof(wchar_t)); /* no terminator */
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen * sizeof(wchar_t)); /* no terminator */
*(strDest + destLen + srcLen) = L'\0';
return EOK;
}
@@ -47,13 +45,12 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax,
* <FUNCTION DESCRIPTION>
* The wcsncat_s function appends not more than n successive wide characters
* (not including the terminating null wide character)
* from the array pointed to by strSrc to the end of the wide string pointed
* to by strDest.
* from the array pointed to by strSrc to the end of the wide string pointed to by strDest.
*
* The wcsncat_s function try to append the first D characters of strSrc to
* the end of strDest, where D is the lesser of count and the length of
* strSrc. If appending those D characters will fit within strDest (whose size
* is given as destMax) and still leave room for a null terminator, then those
* the end of strDest, where D is the lesser of count and the length of strSrc.
* If appending those D characters will fit within strDest (whose size is
* given as destMax) and still leave room for a null terminator, then those
* characters are appended, starting at the original terminating null of
* strDest, and a new terminating null is appended; otherwise, strDest[0] is
* set to the null character.
@@ -69,20 +66,17 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
* SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and
* all other parameters are valid) or (strDest != NULL and strSrc is NULLL and
* destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) ERANGE destMax >
* SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET strDest
* have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* all parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
* (strDest != NULL and strSrc is NULLL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc,
size_t count) {
errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
return ERANGE;
@@ -108,3 +102,5 @@ errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc,
}
return SecDoCatLimitW(strDest, destMax, strSrc, count);
}
@@ -7,8 +7,8 @@
#include "securecutil.h"
SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax,
const wchar_t *strSrc, size_t count) {
SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
size_t srcStrLen;
if (count < destMax) {
SECUREC_CALC_WSTR_LEN(strSrc, count, &srcStrLen);
@@ -52,22 +52,21 @@ SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax,
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <=
* SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and strSrc
* is NULLL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN ERANGE
* destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET count
* > SECUREC_WCHAR_STRING_MAX_LEN or (destMax <= length of strSrc and destMax <=
* count and strDest != strSrc and strDest != NULL and strSrc != NULL and
* destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap)
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* all parameters are valid
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > SECUREC_WCHAR_STRING_MAX_LEN or
* (destMax <= length of strSrc and destMax <= count and strDest != strSrc
* and strDest != NULL and strSrc != NULL and destMax != 0 and
* destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap)
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
*
* If there is a runtime-constraint violation, strDest[0] will be set to the
* '\0' when strDest and destMax valid
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc,
size_t count) {
errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
return ERANGE;
@@ -98,3 +97,4 @@ errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc,
return SecDoCpyLimitW(strDest, destMax, strSrc, count);
}
@@ -7,7 +7,9 @@
#include "securecutil.h"
SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit) {
SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit)
{
const wchar_t *ctl = strDelimit;
while (*ctl != L'\0' && *ctl != ch) {
++ctl;
@@ -17,11 +19,10 @@ SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit) {
/*
* Find beginning of token (skip over leading delimiters).
* Note that there is no token if this loop sets string to point to the terminal
* null.
* Note that there is no token if this loop sets string to point to the terminal null.
*/
SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken,
const wchar_t *strDelimit) {
SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, const wchar_t *strDelimit)
{
wchar_t *token = strToken;
while (*token != L'\0') {
if (SecIsInDelimitW(*token, strDelimit)) {
@@ -35,11 +36,10 @@ SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken,
}
/*
* Find the end of the token. If it is not the end of the string, put a null
* there.
* Find the end of the token. If it is not the end of the string, put a null there.
*/
SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken,
const wchar_t *strDelimit) {
SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimit)
{
wchar_t *token = strToken;
while (*token != L'\0') {
if (SecIsInDelimitW(*token, strDelimit)) {
@@ -56,9 +56,8 @@ SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken,
/*
* Update Token wide character function
*/
SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken,
const wchar_t *strDelimit,
wchar_t **context) {
SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
{
/* Point to updated position */
wchar_t *token = SecFindRestW(strToken, strDelimit);
/* Update the context */
@@ -76,8 +75,7 @@ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken,
*
*
* <FUNCTION DESCRIPTION>
* The wcstok_s function is the wide-character equivalent of the
* strtok_s function
* The wcstok_s function is the wide-character equivalent of the strtok_s function
*
* <INPUT PARAMETERS>
* strToken String containing token or tokens.
@@ -88,11 +86,10 @@ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken,
* <OUTPUT PARAMETERS>
* context is updated
* <RETURN VALUE>
* The wcstok_s function is the wide-character equivalent of the
* strtok_s function
* The wcstok_s function is the wide-character equivalent of the strtok_s function
*/
wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit,
wchar_t **context) {
wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
{
wchar_t *orgToken = strToken;
/* Validation section */
if (context == NULL || strDelimit == NULL) {
@@ -108,3 +105,4 @@ wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit,
orgToken = SecFindBeginW(orgToken, strDelimit);
return SecUpdateTokenW(orgToken, strDelimit, context);
}
@@ -6,9 +6,8 @@
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain
* platform compatibility. And sufficient input validation is performed before
* calling
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
@@ -29,24 +28,25 @@
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and count <=
* destMax and destMax <= SECUREC_WCHAR_MEM_MAX_LEN EINVAL_AND_RESET dest
* != NULL and src is NULLL and destMax != 0 and destMax <=
* SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax ERANGE destMax
* > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or (count > destMax and dest is
* NULL and destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* EINVAL dest is NULL and destMax != 0 and count <= destMax
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
* ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
* (count > destMax and dest is NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* count <= destMax destMax != 0 and destMax <=
* SECUREC_WCHAR_MEM_MAX_LEN and dest != NULL and src != NULL and dest != src
* count <= destMax destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* and dest != NULL and src != NULL and dest != src
*
* if an error occured, dest will be filled with 0 when dest and destMax
* valid . If the source and destination overlap, the behavior of wmemcpy_s is
* undefined. Use wmemmove_s to handle overlapping regions.
* if an error occured, dest will be filled with 0 when dest and destMax valid .
* If the source and destination overlap, the behavior of wmemcpy_s is undefined.
* Use wmemmove_s to handle overlapping regions.
*/
errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src,
size_t count) {
errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s");
return ERANGE;
@@ -59,6 +59,6 @@ errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src,
}
return ERANGE;
}
return memcpy_s(dest, destMax * sizeof(wchar_t), src,
count * sizeof(wchar_t));
return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
}
@@ -6,17 +6,16 @@
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain
* platform compatibility. And sufficient input validation is performed before
* calling
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
/*
* <FUNCTION DESCRIPTION>
* The wmemmove_s function copies n successive wide characters from the object
* pointed to by src into the object pointed to by dest.
* The wmemmove_s function copies n successive wide characters from the object pointed
* to by src into the object pointed to by dest.
*
* <INPUT PARAMETERS>
* dest Destination buffer.
@@ -29,23 +28,24 @@
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and count <=
* destMax and destMax <= SECUREC_WCHAR_MEM_MAX_LEN EINVAL_AND_RESET dest !=
* NULL and src is NULLL and destMax != 0 and destMax <=
* SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax ERANGE destMax >
* SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or (count > destMax and dest is
* NULL and destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* ERANGE_AND_RESET count > destMax and dest != NULL and destMax !=
* 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EINVAL dest is NULL and destMax != 0 and count <= destMax
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
* ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
* (count > destMax and dest is NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
*
*
* If an error occured, dest will be filled with 0 when dest and destMax
* valid. If some regions of the source area and the destination overlap,
* wmemmove_s ensures that the original source bytes in the overlapping region
* are copied before being overwritten
* If an error occured, dest will be filled with 0 when dest and destMax valid.
* If some regions of the source area and the destination overlap, wmemmove_s
* ensures that the original source bytes in the overlapping region are copied
* before being overwritten
*/
errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src,
size_t count) {
errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s");
return ERANGE;
@@ -58,6 +58,6 @@ errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src,
}
return ERANGE;
}
return memmove_s(dest, destMax * sizeof(wchar_t), src,
count * sizeof(wchar_t));
return memmove_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
}
@@ -10,20 +10,19 @@
/*
* <NAME>
* <FUNCTION DESCRIPTION>
* The wscanf_s function is the wide-character equivalent of the
* scanf_s function The wscanf_s function reads data from the standard input
* stream stdin and writes the data into the location that's given by argument.
* Each argument must be a pointer to a variable of a type that corresponds to a
* type specifier in format. If copying occurs between strings that overlap, the
* behavior is undefined.
* The wscanf_s function is the wide-character equivalent of the scanf_s function
* The wscanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... the converted value stored in user assigned
* address
* ... the converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
@@ -31,15 +30,16 @@
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int wscanf_s(const wchar_t *format, ...) {
int wscanf_s(const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vwscanf_s(format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler
will optimize this code */
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -15,19 +15,25 @@ void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd);
int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface);
void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interface);
#else /* CONFIG_NO_CTRL_IFACE */
static inline int hostapd_ctrl_iface_init(struct hostapd_data *hapd) {
static inline int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
{
return 0;
}
static inline void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd) {}
static inline void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
{
}
static inline int
hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface) {
hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
{
return 0;
}
static inline void
hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interface) {}
hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interface)
{
}
#endif /* CONFIG_NO_CTRL_IFACE */
#endif /* CTRL_IFACE_H */
@@ -9,8 +9,9 @@
#include "includes.h"
#include "common.h"
#include "eap_register.h"
#include "eap_server/eap_methods.h"
#include "eap_register.h"
/**
* eap_server_register_methods - Register statically linked EAP server methods
@@ -19,7 +20,8 @@
* This function is called at program initialization to register all EAP
* methods that were linked in statically.
*/
int eap_server_register_methods(void) {
int eap_server_register_methods(void)
{
int ret = 0;
#ifdef EAP_SERVER_IDENTITY
@@ -11,7 +11,8 @@
#include "utils/common.h"
#include "utils/module_tests.h"
int hapd_module_tests(void) {
int hapd_module_tests(void)
{
wpa_printf(MSG_INFO, "hostapd module tests");
return 0;
}
@@ -102,20 +102,26 @@ static struct milenage_parameters *milenage_db = NULL;
#define EAP_AKA_IK_LEN 16
#define EAP_AKA_CK_LEN 16
#ifdef CONFIG_SQLITE
static sqlite3 *sqlite_db = NULL;
static struct milenage_parameters db_tmp_milenage;
static int db_table_exists(sqlite3 *db, const char *name) {
static int db_table_exists(sqlite3 *db, const char *name)
{
char cmd[128];
os_snprintf(cmd, sizeof(cmd), "SELECT 1 FROM %s;", name);
return sqlite3_exec(db, cmd, NULL, NULL, NULL) == SQLITE_OK;
}
static int db_table_create_milenage(sqlite3 *db) {
static int db_table_create_milenage(sqlite3 *db)
{
char *err = NULL;
const char *sql = "CREATE TABLE milenage("
const char *sql =
"CREATE TABLE milenage("
" imsi INTEGER PRIMARY KEY NOT NULL,"
" ki CHAR(32) NOT NULL,"
" opc CHAR(32) NOT NULL,"
@@ -134,16 +140,20 @@ static int db_table_create_milenage(sqlite3 *db) {
return 0;
}
static sqlite3 *db_open(const char *db_file) {
static sqlite3 * db_open(const char *db_file)
{
sqlite3 *db;
if (sqlite3_open(db_file, &db)) {
printf("Failed to open database %s: %s\n", db_file, sqlite3_errmsg(db));
printf("Failed to open database %s: %s\n",
db_file, sqlite3_errmsg(db));
sqlite3_close(db);
return NULL;
}
if (!db_table_exists(db, "milenage") && db_table_create_milenage(db) < 0) {
if (!db_table_exists(db, "milenage") &&
db_table_create_milenage(db) < 0) {
sqlite3_close(db);
return NULL;
}
@@ -151,7 +161,9 @@ static sqlite3 *db_open(const char *db_file) {
return db;
}
static int get_milenage_cb(void *ctx, int argc, char *argv[], char *col[]) {
static int get_milenage_cb(void *ctx, int argc, char *argv[], char *col[])
{
struct milenage_parameters *m = ctx;
int i;
@@ -190,17 +202,20 @@ static int get_milenage_cb(void *ctx, int argc, char *argv[], char *col[]) {
return 0;
}
static struct milenage_parameters *db_get_milenage(const char *imsi_txt) {
static struct milenage_parameters * db_get_milenage(const char *imsi_txt)
{
char cmd[128];
unsigned long long imsi;
os_memset(&db_tmp_milenage, 0, sizeof(db_tmp_milenage));
imsi = atoll(imsi_txt);
os_snprintf(db_tmp_milenage.imsi, sizeof(db_tmp_milenage.imsi), "%llu", imsi);
os_snprintf(cmd, sizeof(cmd), "SELECT * FROM milenage WHERE imsi=%llu;",
imsi);
if (sqlite3_exec(sqlite_db, cmd, get_milenage_cb, &db_tmp_milenage, NULL) !=
SQLITE_OK)
os_snprintf(db_tmp_milenage.imsi, sizeof(db_tmp_milenage.imsi),
"%llu", imsi);
os_snprintf(cmd, sizeof(cmd),
"SELECT * FROM milenage WHERE imsi=%llu;", imsi);
if (sqlite3_exec(sqlite_db, cmd, get_milenage_cb, &db_tmp_milenage,
NULL) != SQLITE_OK)
return NULL;
if (!db_tmp_milenage.set)
@@ -208,7 +223,9 @@ static struct milenage_parameters *db_get_milenage(const char *imsi_txt) {
return &db_tmp_milenage;
}
static int db_update_milenage_sqn(struct milenage_parameters *m) {
static int db_update_milenage_sqn(struct milenage_parameters *m)
{
char cmd[128], val[13], *pos;
if (sqlite_db == NULL)
@@ -217,10 +234,12 @@ static int db_update_milenage_sqn(struct milenage_parameters *m) {
pos = val;
pos += wpa_snprintf_hex(pos, sizeof(val), m->sqn, 6);
*pos = '\0';
os_snprintf(cmd, sizeof(cmd), "UPDATE milenage SET sqn='%s' WHERE imsi=%s;",
os_snprintf(cmd, sizeof(cmd),
"UPDATE milenage SET sqn='%s' WHERE imsi=%s;",
val, m->imsi);
if (sqlite3_exec(sqlite_db, cmd, NULL, NULL, NULL) != SQLITE_OK) {
printf("Failed to update SQN in database for IMSI %s\n", m->imsi);
printf("Failed to update SQN in database for IMSI %s\n",
m->imsi);
return -1;
}
return 0;
@@ -228,7 +247,9 @@ static int db_update_milenage_sqn(struct milenage_parameters *m) {
#endif /* CONFIG_SQLITE */
static int open_socket(const char *path) {
static int open_socket(const char *path)
{
struct sockaddr_un addr;
int s;
@@ -250,7 +271,9 @@ static int open_socket(const char *path) {
return s;
}
static int read_gsm_triplets(const char *fname) {
static int read_gsm_triplets(const char *fname)
{
FILE *f;
char buf[200], *pos, *pos2;
struct gsm_triplet *g = NULL;
@@ -308,7 +331,8 @@ static int read_gsm_triplets(const char *fname) {
/* SRES */
pos = str_token(buf, ":", &pos2);
if (!pos || os_strlen(pos) != 8 || hexstr2bin(pos, g->sres, 4)) {
if (!pos || os_strlen(pos) != 8 ||
hexstr2bin(pos, g->sres, 4)) {
printf("%s:%d - Invalid SRES\n", fname, line);
ret = -1;
break;
@@ -316,7 +340,8 @@ static int read_gsm_triplets(const char *fname) {
/* RAND */
pos = str_token(buf, ":", &pos2);
if (!pos || os_strlen(pos) != 32 || hexstr2bin(pos, g->_rand, 16)) {
if (!pos || os_strlen(pos) != 32 ||
hexstr2bin(pos, g->_rand, 16)) {
printf("%s:%d - Invalid RAND\n", fname, line);
ret = -1;
break;
@@ -333,7 +358,9 @@ static int read_gsm_triplets(const char *fname) {
return ret;
}
static struct gsm_triplet *get_gsm_triplet(const char *imsi) {
static struct gsm_triplet * get_gsm_triplet(const char *imsi)
{
struct gsm_triplet *g = gsm_db_pos;
while (g) {
@@ -356,7 +383,9 @@ static struct gsm_triplet *get_gsm_triplet(const char *imsi) {
return NULL;
}
static int read_milenage(const char *fname) {
static int read_milenage(const char *fname)
{
FILE *f;
char buf[200], *pos, *pos2;
struct milenage_parameters *m = NULL;
@@ -406,7 +435,8 @@ static int read_milenage(const char *fname) {
/* Ki */
pos = str_token(buf, " ", &pos2);
if (!pos || os_strlen(pos) != 32 || hexstr2bin(pos, m->ki, 16)) {
if (!pos || os_strlen(pos) != 32 ||
hexstr2bin(pos, m->ki, 16)) {
printf("%s:%d - Invalid Ki\n", fname, line);
ret = -1;
break;
@@ -414,7 +444,8 @@ static int read_milenage(const char *fname) {
/* OPc */
pos = str_token(buf, " ", &pos2);
if (!pos || os_strlen(pos) != 32 || hexstr2bin(pos, m->opc, 16)) {
if (!pos || os_strlen(pos) != 32 ||
hexstr2bin(pos, m->opc, 16)) {
printf("%s:%d - Invalid OPc\n", fname, line);
ret = -1;
break;
@@ -430,7 +461,8 @@ static int read_milenage(const char *fname) {
/* SQN */
pos = str_token(buf, " ", &pos2);
if (!pos || os_strlen(pos) != 12 || hexstr2bin(pos, m->sqn, 6)) {
if (!pos || os_strlen(pos) != 12 ||
hexstr2bin(pos, m->sqn, 6)) {
printf("%s:%d - Invalid SEQ\n", fname, line);
ret = -1;
break;
@@ -439,9 +471,11 @@ static int read_milenage(const char *fname) {
pos = str_token(buf, " ", &pos2);
if (pos) {
m->res_len = atoi(pos);
if (m->res_len && (m->res_len < EAP_AKA_RES_MIN_LEN ||
if (m->res_len &&
(m->res_len < EAP_AKA_RES_MIN_LEN ||
m->res_len > EAP_AKA_RES_MAX_LEN)) {
printf("%s:%d - Invalid RES_len\n", fname, line);
printf("%s:%d - Invalid RES_len\n",
fname, line);
ret = -1;
break;
}
@@ -458,7 +492,9 @@ static int read_milenage(const char *fname) {
return ret;
}
static void update_milenage_file(const char *fname) {
static void update_milenage_file(const char *fname)
{
FILE *f, *f2;
char name[500], buf[500], *pos;
char *end = buf + sizeof(buf);
@@ -490,7 +526,8 @@ static void update_milenage_file(const char *fname) {
imsi_len = pos - buf;
for (m = milenage_db; m; m = m->next) {
if (strncmp(buf, m->imsi, imsi_len) == 0 && m->imsi[imsi_len] == '\0')
if (strncmp(buf, m->imsi, imsi_len) == 0 &&
m->imsi[imsi_len] == '\0')
break;
}
@@ -526,9 +563,12 @@ static void update_milenage_file(const char *fname) {
perror("rename");
return;
}
}
static struct milenage_parameters *get_milenage(const char *imsi) {
static struct milenage_parameters * get_milenage(const char *imsi)
{
struct milenage_parameters *m = milenage_db;
while (m) {
@@ -545,7 +585,9 @@ static struct milenage_parameters *get_milenage(const char *imsi) {
return m;
}
static int sim_req_auth(char *imsi, char *resp, size_t resp_len) {
static int sim_req_auth(char *imsi, char *resp, size_t resp_len)
{
int count, max_chal, ret;
char *pos;
char *rpos, *rend;
@@ -616,7 +658,9 @@ static int sim_req_auth(char *imsi, char *resp, size_t resp_len) {
return 0;
}
static int gsm_auth_req(char *imsi, char *resp, size_t resp_len) {
static int gsm_auth_req(char *imsi, char *resp, size_t resp_len)
{
int count, ret;
char *pos, *rpos, *rend;
struct milenage_parameters *m;
@@ -664,7 +708,9 @@ static int gsm_auth_req(char *imsi, char *resp, size_t resp_len) {
return 0;
}
static void inc_sqn(u8 *sqn) {
static void inc_sqn(u8 *sqn)
{
u64 val, seq, ind;
/*
@@ -684,7 +730,9 @@ static void inc_sqn(u8 *sqn) {
WPA_PUT_BE16(sqn + 4, val & 0xffff);
}
static int aka_req_auth(char *imsi, char *resp, size_t resp_len) {
static int aka_req_auth(char *imsi, char *resp, size_t resp_len)
{
/* AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES> */
char *pos, *end;
u8 _rand[EAP_AKA_RAND_LEN];
@@ -708,13 +756,15 @@ static int aka_req_auth(char *imsi, char *resp, size_t resp_len) {
#endif /* CONFIG_SQLITE */
sqn_changes = 1;
if (stdout_debug) {
printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n", m->sqn[0],
m->sqn[1], m->sqn[2], m->sqn[3], m->sqn[4], m->sqn[5]);
printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n",
m->sqn[0], m->sqn[1], m->sqn[2],
m->sqn[3], m->sqn[4], m->sqn[5]);
}
milenage_generate(m->opc, m->amf, m->ki, m->sqn, _rand, autn, ik, ck, res,
&res_len);
milenage_generate(m->opc, m->amf, m->ki, m->sqn, _rand,
autn, ik, ck, res, &res_len);
if (m->res_len >= EAP_AKA_RES_MIN_LEN &&
m->res_len <= EAP_AKA_RES_MAX_LEN && m->res_len < res_len)
m->res_len <= EAP_AKA_RES_MAX_LEN &&
m->res_len < res_len)
res_len = m->res_len;
} else {
printf("Unknown IMSI: %s\n", imsi);
@@ -757,7 +807,9 @@ static int aka_req_auth(char *imsi, char *resp, size_t resp_len) {
return 0;
}
static int aka_auts(char *imsi, char *resp, size_t resp_len) {
static int aka_auts(char *imsi, char *resp, size_t resp_len)
{
char *auts, *__rand;
u8 _auts[EAP_AKA_AUTS_LEN], _rand[EAP_AKA_RAND_LEN], sqn[6];
struct milenage_parameters *m;
@@ -777,7 +829,8 @@ static int aka_auts(char *imsi, char *resp, size_t resp_len) {
*__rand++ = '\0';
if (stdout_debug) {
printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n", imsi, auts, __rand);
printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n",
imsi, auts, __rand);
}
if (hexstr2bin(auts, _auts, EAP_AKA_AUTS_LEN) ||
hexstr2bin(__rand, _rand, EAP_AKA_RAND_LEN)) {
@@ -809,7 +862,9 @@ static int aka_auts(char *imsi, char *resp, size_t resp_len) {
return 0;
}
static int process_cmd(char *cmd, char *resp, size_t resp_len) {
static int process_cmd(char *cmd, char *resp, size_t resp_len)
{
if (os_strncmp(cmd, "SIM-REQ-AUTH ", 13) == 0)
return sim_req_auth(cmd + 13, resp, resp_len);
@@ -826,14 +881,17 @@ static int process_cmd(char *cmd, char *resp, size_t resp_len) {
return -1;
}
static int process(int s) {
static int process(int s)
{
char buf[1000], resp[1000];
struct sockaddr_un from;
socklen_t fromlen;
ssize_t res;
fromlen = sizeof(from);
res = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen);
res = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &from,
&fromlen);
if (res < 0) {
perror("recvfrom");
return -1;
@@ -860,14 +918,16 @@ static int process(int s) {
printf("Send: %s\n", resp);
if (sendto(s, resp, os_strlen(resp), 0, (struct sockaddr *)&from, fromlen) <
0)
if (sendto(s, resp, os_strlen(resp), 0, (struct sockaddr *) &from,
fromlen) < 0)
perror("send");
return 0;
}
static void cleanup(void) {
static void cleanup(void)
{
struct gsm_triplet *g, *gprev;
struct milenage_parameters *m, *prev;
@@ -901,12 +961,16 @@ static void cleanup(void) {
#endif /* CONFIG_SQLITE */
}
static void handle_term(int sig) {
static void handle_term(int sig)
{
printf("Signal %d - terminate\n", sig);
exit(0);
}
static void usage(void) {
static void usage(void)
{
printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA "
"database/authenticator\n"
"Copyright (c) 2005-2016, Jouni Malinen <j@w1.fi>\n"
@@ -936,7 +1000,9 @@ static void usage(void) {
default_socket_path);
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
int c;
char *gsm_triplet_file = NULL;
char *sqlite_db_file = NULL;
File diff suppressed because it is too large Load Diff
+126 -67
View File
@@ -8,26 +8,27 @@
#include "utils/includes.h"
#ifndef CONFIG_NATIVE_WINDOWS
#include <grp.h>
#include <syslog.h>
#include <grp.h>
#endif /* CONFIG_NATIVE_WINDOWS */
#include "ap/ap_config.h"
#include "ap/ap_drv_ops.h"
#include "ap/hostapd.h"
#include "common/version.h"
#include "config_file.h"
#include "crypto/random.h"
#include "crypto/tls.h"
#include "ctrl_iface.h"
#include "drivers/driver.h"
#include "eap_register.h"
#include "eap_server/eap.h"
#include "eap_server/tncs.h"
#include "fst/fst.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "utils/uuid.h"
#include "crypto/random.h"
#include "crypto/tls.h"
#include "common/version.h"
#include "drivers/driver.h"
#include "eap_server/eap.h"
#include "eap_server/tncs.h"
#include "ap/hostapd.h"
#include "ap/ap_config.h"
#include "ap/ap_drv_ops.h"
#include "fst/fst.h"
#include "config_file.h"
#include "eap_register.h"
#include "ctrl_iface.h"
struct hapd_global {
void **drv_priv;
@@ -36,9 +37,11 @@ struct hapd_global {
static struct hapd_global global;
#ifndef CONFIG_NO_HOSTAPD_LOGGER
static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
int level, const char *txt, size_t len) {
int level, const char *txt, size_t len)
{
struct hostapd_data *hapd = ctx;
char *format, *module_str;
int maxlen;
@@ -88,17 +91,21 @@ static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
}
if (hapd && hapd->conf && addr)
os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s", hapd->conf->iface,
os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s",
hapd->conf->iface, MAC2STR(addr),
module_str ? " " : "", module_str ? module_str : "",
txt);
else if (hapd && hapd->conf)
os_snprintf(format, maxlen, "%s:%s%s %s",
hapd->conf->iface, module_str ? " " : "",
module_str ? module_str : "", txt);
else if (addr)
os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s",
MAC2STR(addr), module_str ? " " : "",
module_str ? module_str : "", txt);
else if (hapd && hapd->conf)
os_snprintf(format, maxlen, "%s:%s%s %s", hapd->conf->iface,
module_str ? " " : "", module_str ? module_str : "", txt);
else if (addr)
os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s", MAC2STR(addr),
module_str ? " " : "", module_str ? module_str : "", txt);
else
os_snprintf(format, maxlen, "%s%s%s", module_str ? module_str : "",
os_snprintf(format, maxlen, "%s%s%s",
module_str ? module_str : "",
module_str ? ": " : "", txt);
if ((conf_stdout & module) && level >= conf_stdout_level) {
@@ -135,10 +142,12 @@ static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
}
#endif /* CONFIG_NO_HOSTAPD_LOGGER */
/**
* hostapd_driver_init - Preparate driver interface
*/
static int hostapd_driver_init(struct hostapd_iface *iface) {
static int hostapd_driver_init(struct hostapd_iface *iface)
{
struct wpa_init_params params;
size_t i;
struct hostapd_data *hapd = iface->bss[0];
@@ -160,11 +169,12 @@ static int hostapd_driver_init(struct hostapd_iface *iface) {
if (wpa_drivers[i] != hapd->driver)
continue;
if (global.drv_priv[i] == NULL && wpa_drivers[i]->global_init) {
global.drv_priv[i] = wpa_drivers[i]->global_init(iface->interfaces);
if (global.drv_priv[i] == NULL &&
wpa_drivers[i]->global_init) {
global.drv_priv[i] =
wpa_drivers[i]->global_init(iface->interfaces);
if (global.drv_priv[i] == NULL) {
wpa_printf(MSG_ERROR,
"Failed to initialize "
wpa_printf(MSG_ERROR, "Failed to initialize "
"driver '%s'",
wpa_drivers[i]->name);
return -1;
@@ -232,6 +242,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface) {
return 0;
}
/**
* hostapd_interface_init - Read configuration file and init BSS data
*
@@ -241,7 +252,8 @@ static int hostapd_driver_init(struct hostapd_iface *iface) {
*/
static struct hostapd_iface *
hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name,
const char *config_fname, int debug) {
const char *config_fname, int debug)
{
struct hostapd_iface *iface;
int k;
@@ -274,17 +286,21 @@ hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name,
return iface;
}
/**
* handle_term - SIGINT and SIGTERM handler to terminate hostapd process
*/
static void handle_term(int sig, void *signal_ctx) {
static void handle_term(int sig, void *signal_ctx)
{
wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig);
eloop_terminate();
}
#ifndef CONFIG_NATIVE_WINDOWS
static int handle_reload_iface(struct hostapd_iface *iface, void *ctx) {
static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
{
if (hostapd_reload_config(iface) < 0) {
wpa_printf(MSG_WARNING, "Failed to read new configuration "
"file - continuing with old.");
@@ -292,22 +308,29 @@ static int handle_reload_iface(struct hostapd_iface *iface, void *ctx) {
return 0;
}
/**
* handle_reload - SIGHUP handler to reload configuration
*/
static void handle_reload(int sig, void *signal_ctx) {
static void handle_reload(int sig, void *signal_ctx)
{
struct hapd_interfaces *interfaces = signal_ctx;
wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", sig);
wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration",
sig);
hostapd_for_each_interface(interfaces, handle_reload_iface, NULL);
}
static void handle_dump_state(int sig, void *signal_ctx) {
static void handle_dump_state(int sig, void *signal_ctx)
{
/* Not used anymore - ignore signal */
}
#endif /* CONFIG_NATIVE_WINDOWS */
static int hostapd_global_init(struct hapd_interfaces *interfaces,
const char *entropy_file) {
const char *entropy_file)
{
int i;
os_memset(&global, 0, sizeof(global));
@@ -350,7 +373,9 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces,
return 0;
}
static void hostapd_global_deinit(const char *pid_file, int eloop_initialized) {
static void hostapd_global_deinit(const char *pid_file, int eloop_initialized)
{
int i;
for (i = 0; wpa_drivers[i] && global.drv_priv; i++) {
@@ -379,8 +404,10 @@ static void hostapd_global_deinit(const char *pid_file, int eloop_initialized) {
os_daemonize_terminate(pid_file);
}
static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
const char *pid_file) {
const char *pid_file)
{
#ifdef EAP_SERVER_TNC
int tnc = 0;
size_t i, k;
@@ -406,7 +433,8 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
return -1;
}
if (eloop_sock_requeue()) {
wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s", strerror(errno));
wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s",
strerror(errno));
return -1;
}
}
@@ -416,15 +444,20 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
return 0;
}
static void show_version(void) {
fprintf(stderr, "hostapd v" VERSION_STR "\n"
static void show_version(void)
{
fprintf(stderr,
"hostapd v" VERSION_STR "\n"
"User space daemon for IEEE 802.11 AP management,\n"
"IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
"Copyright (c) 2002-2016, Jouni Malinen <j@w1.fi> "
"and contributors\n");
}
static void usage(void) {
static void usage(void)
{
show_version();
fprintf(stderr,
"\n"
@@ -458,15 +491,19 @@ static void usage(void) {
exit(1);
}
static const char *hostapd_msg_ifname_cb(void *ctx) {
static const char * hostapd_msg_ifname_cb(void *ctx)
{
struct hostapd_data *hapd = ctx;
if (hapd && hapd->conf)
return hapd->conf->iface;
return NULL;
}
static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
const char *path) {
const char *path)
{
#ifndef CONFIG_CTRL_IFACE_UDP
char *pos;
#endif /* !CONFIG_CTRL_IFACE_UDP */
@@ -493,8 +530,10 @@ static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
return 0;
}
static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
const char *group) {
const char *group)
{
#ifndef CONFIG_NATIVE_WINDOWS
struct group *grp;
grp = getgrnam(group);
@@ -507,8 +546,11 @@ static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
return 0;
}
static int hostapd_get_interface_names(char ***if_names, size_t *if_names_size,
char *optarg) {
static int hostapd_get_interface_names(char ***if_names,
size_t *if_names_size,
char *optarg)
{
char *if_name, *tmp, **nnames;
size_t i;
@@ -517,7 +559,8 @@ static int hostapd_get_interface_names(char ***if_names, size_t *if_names_size,
if_name = strtok_r(optarg, ",", &tmp);
while (if_name) {
nnames = os_realloc_array(*if_names, 1 + *if_names_size, sizeof(char *));
nnames = os_realloc_array(*if_names, 1 + *if_names_size,
sizeof(char *));
if (!nnames)
goto fail;
*if_names = nnames;
@@ -540,8 +583,10 @@ fail:
return -1;
}
#ifdef CONFIG_WPS
static int gen_uuid(const char *txt_addr) {
static int gen_uuid(const char *txt_addr)
{
u8 addr[ETH_ALEN];
u8 uuid[UUID_LEN];
char buf[100];
@@ -559,25 +604,31 @@ static int gen_uuid(const char *txt_addr) {
}
#endif /* CONFIG_WPS */
#ifndef HOSTAPD_CLEANUP_INTERVAL
#define HOSTAPD_CLEANUP_INTERVAL 10
#endif /* HOSTAPD_CLEANUP_INTERVAL */
static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx) {
static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx)
{
hostapd_periodic_iface(iface);
return 0;
}
/* Periodic cleanup tasks */
static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx) {
static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx)
{
struct hapd_interfaces *interfaces = eloop_ctx;
eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, hostapd_periodic,
interfaces, NULL);
eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0,
hostapd_periodic, interfaces, NULL);
hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL);
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
struct hapd_interfaces interfaces;
int ret = 1;
size_t i, j;
@@ -659,8 +710,9 @@ int main(int argc, char *argv[]) {
return -1;
break;
case 'b':
tmp_bss =
os_realloc_array(bss_config, num_bss_configs + 1, sizeof(char *));
tmp_bss = os_realloc_array(bss_config,
num_bss_configs + 1,
sizeof(char *));
if (tmp_bss == NULL)
goto out;
bss_config = tmp_bss;
@@ -674,7 +726,8 @@ int main(int argc, char *argv[]) {
return gen_uuid(optarg);
#endif /* CONFIG_WPS */
case 'i':
if (hostapd_get_interface_names(&if_names, &if_names_size, optarg))
if (hostapd_get_interface_names(&if_names,
&if_names_size, optarg))
goto out;
break;
default:
@@ -718,11 +771,12 @@ int main(int argc, char *argv[]) {
return -1;
}
eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, hostapd_periodic,
&interfaces, NULL);
eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0,
hostapd_periodic, &interfaces, NULL);
if (fst_global_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize global FST context");
wpa_printf(MSG_ERROR,
"Failed to initialize global FST context");
goto out;
}
@@ -738,8 +792,10 @@ int main(int argc, char *argv[]) {
if (i < if_names_size)
if_name = if_names[i];
interfaces.iface[i] =
hostapd_interface_init(&interfaces, if_name, argv[optind + i], debug);
interfaces.iface[i] = hostapd_interface_init(&interfaces,
if_name,
argv[optind + i],
debug);
if (!interfaces.iface[i]) {
wpa_printf(MSG_ERROR, "Failed to initialize interface");
goto out;
@@ -756,13 +812,14 @@ int main(int argc, char *argv[]) {
wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]);
fname = os_strchr(bss_config[i], ':');
if (fname == NULL) {
wpa_printf(MSG_ERROR, "Invalid BSS config identifier '%s'",
wpa_printf(MSG_ERROR,
"Invalid BSS config identifier '%s'",
bss_config[i]);
goto out;
}
*fname++ = '\0';
iface =
hostapd_interface_init_bss(&interfaces, bss_config[i], fname, debug);
iface = hostapd_interface_init_bss(&interfaces, bss_config[i],
fname, debug);
if (iface == NULL)
goto out;
for (j = 0; j < interfaces.count; j++) {
@@ -771,7 +828,8 @@ int main(int argc, char *argv[]) {
}
if (j == interfaces.count) {
struct hostapd_iface **tmp;
tmp = os_realloc_array(interfaces.iface, interfaces.count + 1,
tmp = os_realloc_array(interfaces.iface,
interfaces.count + 1,
sizeof(struct hostapd_iface *));
if (tmp == NULL) {
hostapd_interface_deinit_free(iface);
@@ -812,8 +870,9 @@ out:
for (i = 0; i < interfaces.count; i++) {
if (!interfaces.iface[i])
continue;
interfaces.iface[i]->driver_ap_teardown = !!(
interfaces.iface[i]->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
interfaces.iface[i]->driver_ap_teardown =
!!(interfaces.iface[i]->drv_flags &
WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
hostapd_interface_deinit_free(interfaces.iface[i]);
}
os_free(interfaces.iface);
@@ -11,7 +11,9 @@
#include "common.h"
#include "crypto/ms_funcs.h"
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
unsigned char password_hash[16];
size_t i;
char *password, buf[64], *pos;
@@ -8,18 +8,19 @@
#include "utils/includes.h"
#include "accounting.h"
#include "ap_config.h"
#include "ap_drv_ops.h"
#include "eapol_auth/eapol_auth_sm.h"
#include "eapol_auth/eapol_auth_sm_i.h"
#include "hostapd.h"
#include "ieee802_1x.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
#include "sta_info.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "eapol_auth/eapol_auth_sm.h"
#include "eapol_auth/eapol_auth_sm_i.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
#include "hostapd.h"
#include "ieee802_1x.h"
#include "ap_config.h"
#include "sta_info.h"
#include "ap_drv_ops.h"
#include "accounting.h"
/* Default interval in seconds for polling TX/RX octets from the driver if
* STA is not using interim accounting. This detects wrap arounds for
@@ -29,9 +30,11 @@
static void accounting_sta_interim(struct hostapd_data *hapd,
struct sta_info *sta);
static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
struct sta_info *sta,
int status_type) {
int status_type)
{
struct radius_msg *msg;
char buf[128];
u8 *val;
@@ -54,12 +57,13 @@ static struct radius_msg *accounting_msg(struct hostapd_data *hapd,
}
if (sta) {
if (!hostapd_config_get_radius_attr(hapd->conf->radius_acct_req_attr,
if (!hostapd_config_get_radius_attr(
hapd->conf->radius_acct_req_attr,
RADIUS_ATTR_ACCT_AUTHENTIC) &&
!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_AUTHENTIC,
hapd->conf->ieee802_1x
? RADIUS_ACCT_AUTHENTIC_RADIUS
: RADIUS_ACCT_AUTHENTIC_LOCAL)) {
hapd->conf->ieee802_1x ?
RADIUS_ACCT_AUTHENTIC_RADIUS :
RADIUS_ACCT_AUTHENTIC_LOCAL)) {
wpa_printf(MSG_INFO, "Could not add Acct-Authentic");
goto fail;
}
@@ -76,42 +80,49 @@ static struct radius_msg *accounting_msg(struct hostapd_data *hapd,
/* Use STA MAC if neither 802.1X nor RADIUS ACL provided
* identity */
if (!val) {
os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT, MAC2STR(sta->addr));
os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT,
MAC2STR(sta->addr));
val = (u8 *) buf;
len = os_strlen(buf);
}
if (!radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME, val, len)) {
if (!radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME, val,
len)) {
wpa_printf(MSG_INFO, "Could not add User-Name");
goto fail;
}
}
if (add_common_radius_attr(hapd, hapd->conf->radius_acct_req_attr, sta, msg) <
0)
if (add_common_radius_attr(hapd, hapd->conf->radius_acct_req_attr, sta,
msg) < 0)
goto fail;
if (sta) {
for (i = 0; ; i++) {
val = ieee802_1x_get_radius_class(sta->eapol_sm, &len, i);
val = ieee802_1x_get_radius_class(sta->eapol_sm, &len,
i);
if (val == NULL)
break;
if (!radius_msg_add_attr(msg, RADIUS_ATTR_CLASS, val, len)) {
if (!radius_msg_add_attr(msg, RADIUS_ATTR_CLASS,
val, len)) {
wpa_printf(MSG_INFO, "Could not add Class");
goto fail;
}
}
b = ieee802_1x_get_radius_cui(sta->eapol_sm);
if (b && !radius_msg_add_attr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
if (b &&
!radius_msg_add_attr(msg,
RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
wpabuf_head(b), wpabuf_len(b))) {
wpa_printf(MSG_ERROR, "Could not add CUI");
goto fail;
}
if (!b && sta->radius_cui &&
!radius_msg_add_attr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
!radius_msg_add_attr(msg,
RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
(u8 *) sta->radius_cui,
os_strlen(sta->radius_cui))) {
wpa_printf(MSG_ERROR, "Could not add CUI from ACL");
@@ -119,16 +130,19 @@ static struct radius_msg *accounting_msg(struct hostapd_data *hapd,
}
if (sta->ipaddr &&
!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_IP_ADDRESS,
!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_FRAMED_IP_ADDRESS,
be_to_host32(sta->ipaddr))) {
wpa_printf(MSG_ERROR, "Could not add Framed-IP-Address");
wpa_printf(MSG_ERROR,
"Could not add Framed-IP-Address");
goto fail;
}
}
os_get_time(&now);
if (now.sec > 1000000000 &&
!radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP, now.sec)) {
!radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP,
now.sec)) {
wpa_printf(MSG_INFO, "Could not add Event-Timestamp");
goto fail;
}
@@ -149,9 +163,11 @@ fail:
return NULL;
}
static int accounting_sta_update_stats(struct hostapd_data *hapd,
struct sta_info *sta,
struct hostap_sta_driver_data *data) {
struct hostap_sta_driver_data *data)
{
if (hostapd_drv_read_sta_data(hapd, data, sta->addr))
return -1;
@@ -166,17 +182,21 @@ static int accounting_sta_update_stats(struct hostapd_data *hapd,
sta->last_tx_bytes_lo = data->tx_bytes;
}
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, HOSTAPD_LEVEL_DEBUG,
"updated TX/RX stats: rx_bytes=%llu [%u:%u] tx_bytes=%llu "
"[%u:%u] bytes_64bit=%d",
data->rx_bytes, sta->last_rx_bytes_hi, sta->last_rx_bytes_lo,
data->tx_bytes, sta->last_tx_bytes_hi, sta->last_tx_bytes_lo,
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_DEBUG,
"updated TX/RX stats: rx_bytes=%llu [%u:%u] tx_bytes=%llu [%u:%u] bytes_64bit=%d",
data->rx_bytes, sta->last_rx_bytes_hi,
sta->last_rx_bytes_lo,
data->tx_bytes, sta->last_tx_bytes_hi,
sta->last_tx_bytes_lo,
data->bytes_64bit);
return 0;
}
static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx) {
static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx)
{
struct hostapd_data *hapd = eloop_ctx;
struct sta_info *sta = timeout_ctx;
int interval;
@@ -190,22 +210,26 @@ static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx) {
interval = ACCT_DEFAULT_UPDATE_INTERVAL;
}
eloop_register_timeout(interval, 0, accounting_interim_update, hapd, sta);
eloop_register_timeout(interval, 0, accounting_interim_update,
hapd, sta);
}
/**
* accounting_sta_start - Start STA accounting
* @hapd: hostapd BSS data
* @sta: The station
*/
void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta) {
void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
{
struct radius_msg *msg;
int interval;
if (sta->acct_session_started)
return;
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, HOSTAPD_LEVEL_INFO,
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_INFO,
"starting accounting session %016llX",
(unsigned long long) sta->acct_session_id);
@@ -223,17 +247,21 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta) {
interval = sta->acct_interim_interval;
else
interval = ACCT_DEFAULT_UPDATE_INTERVAL;
eloop_register_timeout(interval, 0, accounting_interim_update, hapd, sta);
eloop_register_timeout(interval, 0, accounting_interim_update,
hapd, sta);
msg = accounting_msg(hapd, sta, RADIUS_ACCT_STATUS_TYPE_START);
if (msg && radius_client_send(hapd->radius, msg, RADIUS_ACCT, sta->addr) < 0)
if (msg &&
radius_client_send(hapd->radius, msg, RADIUS_ACCT, sta->addr) < 0)
radius_msg_free(msg);
sta->acct_session_started = 1;
}
static void accounting_sta_report(struct hostapd_data *hapd,
struct sta_info *sta, int stop) {
struct sta_info *sta, int stop)
{
struct radius_msg *msg;
int cause = sta->acct_terminate_cause;
struct hostap_sta_driver_data data;
@@ -244,8 +272,8 @@ static void accounting_sta_report(struct hostapd_data *hapd,
return;
msg = accounting_msg(hapd, sta,
stop ? RADIUS_ACCT_STATUS_TYPE_STOP
: RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE);
stop ? RADIUS_ACCT_STATUS_TYPE_STOP :
RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE);
if (!msg) {
wpa_printf(MSG_INFO, "Could not create RADIUS Accounting message");
return;
@@ -260,12 +288,14 @@ static void accounting_sta_report(struct hostapd_data *hapd,
}
if (accounting_sta_update_stats(hapd, sta, &data) == 0) {
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_INPUT_PACKETS,
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_INPUT_PACKETS,
data.rx_packets)) {
wpa_printf(MSG_INFO, "Could not add Acct-Input-Packets");
goto fail;
}
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_OUTPUT_PACKETS,
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_OUTPUT_PACKETS,
data.tx_packets)) {
wpa_printf(MSG_INFO, "Could not add Acct-Output-Packets");
goto fail;
@@ -273,13 +303,16 @@ static void accounting_sta_report(struct hostapd_data *hapd,
if (data.bytes_64bit)
bytes = data.rx_bytes;
else
bytes = ((u64)sta->last_rx_bytes_hi << 32) | sta->last_rx_bytes_lo;
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_INPUT_OCTETS,
bytes = ((u64) sta->last_rx_bytes_hi << 32) |
sta->last_rx_bytes_lo;
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_INPUT_OCTETS,
(u32) bytes)) {
wpa_printf(MSG_INFO, "Could not add Acct-Input-Octets");
goto fail;
}
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_INPUT_GIGAWORDS,
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_INPUT_GIGAWORDS,
(u32) (bytes >> 32))) {
wpa_printf(MSG_INFO, "Could not add Acct-Input-Gigawords");
goto fail;
@@ -287,13 +320,16 @@ static void accounting_sta_report(struct hostapd_data *hapd,
if (data.bytes_64bit)
bytes = data.tx_bytes;
else
bytes = ((u64)sta->last_tx_bytes_hi << 32) | sta->last_tx_bytes_lo;
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_OUTPUT_OCTETS,
bytes = ((u64) sta->last_tx_bytes_hi << 32) |
sta->last_tx_bytes_lo;
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_OUTPUT_OCTETS,
(u32) bytes)) {
wpa_printf(MSG_INFO, "Could not add Acct-Output-Octets");
goto fail;
}
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS,
if (!radius_msg_add_attr_int32(msg,
RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS,
(u32) (bytes >> 32))) {
wpa_printf(MSG_INFO, "Could not add Acct-Output-Gigawords");
goto fail;
@@ -320,38 +356,46 @@ fail:
radius_msg_free(msg);
}
/**
* accounting_sta_interim - Send a interim STA accounting report
* @hapd: hostapd BSS data
* @sta: The station
*/
static void accounting_sta_interim(struct hostapd_data *hapd,
struct sta_info *sta) {
struct sta_info *sta)
{
if (sta->acct_session_started)
accounting_sta_report(hapd, sta, 0);
}
/**
* accounting_sta_stop - Stop STA accounting
* @hapd: hostapd BSS data
* @sta: The station
*/
void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta) {
void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
{
if (sta->acct_session_started) {
accounting_sta_report(hapd, sta, 1);
eloop_cancel_timeout(accounting_interim_update, hapd, sta);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, HOSTAPD_LEVEL_INFO,
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_INFO,
"stopped accounting session %016llX",
(unsigned long long) sta->acct_session_id);
sta->acct_session_started = 0;
}
}
int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta) {
int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
{
return radius_gen_session_id((u8 *) &sta->acct_session_id,
sizeof(sta->acct_session_id));
}
/**
* accounting_receive - Process the RADIUS frames from Accounting Server
* @msg: RADIUS response message
@@ -361,26 +405,27 @@ int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta) {
* @data: Context data (struct hostapd_data *)
* Returns: Processing status
*/
static RadiusRxResult accounting_receive(struct radius_msg *msg,
struct radius_msg *req,
const u8 *shared_secret,
size_t shared_secret_len, void *data) {
static RadiusRxResult
accounting_receive(struct radius_msg *msg, struct radius_msg *req,
const u8 *shared_secret, size_t shared_secret_len,
void *data)
{
if (radius_msg_get_hdr(msg)->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
wpa_printf(MSG_INFO, "Unknown RADIUS message code");
return RADIUS_RX_UNKNOWN;
}
if (radius_msg_verify(msg, shared_secret, shared_secret_len, req, 0)) {
wpa_printf(
MSG_INFO,
"Incoming RADIUS packet did not have correct Authenticator - dropped");
wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Authenticator - dropped");
return RADIUS_RX_INVALID_AUTHENTICATOR;
}
return RADIUS_RX_PROCESSED;
}
static void accounting_report_state(struct hostapd_data *hapd, int on) {
static void accounting_report_state(struct hostapd_data *hapd, int on)
{
struct radius_msg *msg;
if (!hapd->conf->radius->acct_server || hapd->radius == NULL)
@@ -389,8 +434,8 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) {
/* Inform RADIUS server that accounting will start/stop so that the
* server can close old accounting sessions. */
msg = accounting_msg(hapd, NULL,
on ? RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON
: RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF);
on ? RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON :
RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF);
if (!msg)
return;
@@ -399,8 +444,8 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) {
os_snprintf(buf, sizeof(buf), "%016llX",
(unsigned long long) hapd->acct_session_id);
if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID, (u8 *)buf,
os_strlen(buf)))
if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
(u8 *) buf, os_strlen(buf)))
wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
}
@@ -408,7 +453,9 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) {
radius_msg_free(msg);
}
static void accounting_interim_error_cb(const u8 *addr, void *ctx) {
static void accounting_interim_error_cb(const u8 *addr, void *ctx)
{
struct hostapd_data *hapd = ctx;
struct sta_info *sta;
unsigned int i, wait_time;
@@ -444,8 +491,8 @@ static void accounting_interim_error_cb(const u8 *addr, void *ctx) {
for (i = 1; i < sta->acct_interim_errors; i++)
wait_time *= 2;
}
res =
eloop_deplete_timeout(wait_time, 0, accounting_interim_update, hapd, sta);
res = eloop_deplete_timeout(wait_time, 0, accounting_interim_update,
hapd, sta);
if (res == 1)
wpa_printf(MSG_DEBUG,
"Interim RADIUS accounting update failed for " MACSTR
@@ -454,40 +501,44 @@ static void accounting_interim_error_cb(const u8 *addr, void *ctx) {
else if (res == 0)
wpa_printf(MSG_DEBUG,
"Interim RADIUS accounting update failed for " MACSTR
" (error count: %u)",
MAC2STR(addr), sta->acct_interim_errors);
" (error count: %u)", MAC2STR(addr),
sta->acct_interim_errors);
else
wpa_printf(MSG_DEBUG,
"Interim RADIUS accounting update failed for " MACSTR
" (error count: %u) - no timer found",
MAC2STR(addr), sta->acct_interim_errors);
" (error count: %u) - no timer found", MAC2STR(addr),
sta->acct_interim_errors);
}
/**
* accounting_init: Initialize accounting
* @hapd: hostapd BSS data
* Returns: 0 on success, -1 on failure
*/
int accounting_init(struct hostapd_data *hapd) {
int accounting_init(struct hostapd_data *hapd)
{
if (radius_gen_session_id((u8 *) &hapd->acct_session_id,
sizeof(hapd->acct_session_id)) < 0)
return -1;
if (radius_client_register(hapd->radius, RADIUS_ACCT, accounting_receive,
hapd))
if (radius_client_register(hapd->radius, RADIUS_ACCT,
accounting_receive, hapd))
return -1;
radius_client_set_interim_error_cb(hapd->radius, accounting_interim_error_cb,
hapd);
radius_client_set_interim_error_cb(hapd->radius,
accounting_interim_error_cb, hapd);
accounting_report_state(hapd, 1);
return 0;
}
/**
* accounting_deinit: Deinitialize accounting
* @hapd: hostapd BSS data
*/
void accounting_deinit(struct hostapd_data *hapd) {
void accounting_deinit(struct hostapd_data *hapd)
{
accounting_report_state(hapd, 0);
}
@@ -11,19 +11,29 @@
#ifdef CONFIG_NO_ACCOUNTING
static inline int accounting_sta_get_id(struct hostapd_data *hapd,
struct sta_info *sta) {
struct sta_info *sta)
{
return 0;
}
static inline void accounting_sta_start(struct hostapd_data *hapd,
struct sta_info *sta) {}
struct sta_info *sta)
{
}
static inline void accounting_sta_stop(struct hostapd_data *hapd,
struct sta_info *sta) {}
struct sta_info *sta)
{
}
static inline int accounting_init(struct hostapd_data *hapd) { return 0; }
static inline int accounting_init(struct hostapd_data *hapd)
{
return 0;
}
static inline void accounting_deinit(struct hostapd_data *hapd) {}
static inline void accounting_deinit(struct hostapd_data *hapd)
{
}
#else /* CONFIG_NO_ACCOUNTING */
int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta);
void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta);
+226 -169
View File
@@ -10,16 +10,16 @@
#include "utils/includes.h"
#include <math.h>
#include "acs.h"
#include "ap_config.h"
#include "ap_drv_ops.h"
#include "utils/common.h"
#include "utils/list.h"
#include "common/ieee802_11_defs.h"
#include "common/wpa_ctrl.h"
#include "drivers/driver.h"
#include "hostapd.h"
#include "ap_drv_ops.h"
#include "ap_config.h"
#include "hw_features.h"
#include "utils/common.h"
#include "utils/list.h"
#include "acs.h"
/*
* Automatic Channel Selection
@@ -131,100 +131,95 @@
*
* ACS: Trying survey-based ACS
* ACS: Survey analysis for channel 1 (2412 MHz)
* ACS: 1: min_nf=-113 interference_factor=0.0802469 nf=-113 time=162 busy=0
* rx=13 ACS: 2: min_nf=-113 interference_factor=0.0745342 nf=-113 time=161
* busy=0 rx=12 ACS: 3: min_nf=-113 interference_factor=0.0679012 nf=-113
* time=162 busy=0 rx=11 ACS: 4: min_nf=-113 interference_factor=0.0310559
* nf=-113 time=161 busy=0 rx=5 ACS: 5: min_nf=-113
* interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4 ACS: *
* interference factor average: 0.0557166 ACS: Survey analysis for channel 2
* (2417 MHz) ACS: 1: min_nf=-113 interference_factor=0.0185185 nf=-113
* time=162 busy=0 rx=3 ACS: 2: min_nf=-113 interference_factor=0.0246914
* nf=-113 time=162 busy=0 rx=4 ACS: 3: min_nf=-113
* interference_factor=0.037037 nf=-113 time=162 busy=0 rx=6 ACS: 4:
* min_nf=-113 interference_factor=0.149068 nf=-113 time=161 busy=0 rx=24 ACS:
* 5: min_nf=-113 interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4
* ACS: 1: min_nf=-113 interference_factor=0.0802469 nf=-113 time=162 busy=0 rx=13
* ACS: 2: min_nf=-113 interference_factor=0.0745342 nf=-113 time=161 busy=0 rx=12
* ACS: 3: min_nf=-113 interference_factor=0.0679012 nf=-113 time=162 busy=0 rx=11
* ACS: 4: min_nf=-113 interference_factor=0.0310559 nf=-113 time=161 busy=0 rx=5
* ACS: 5: min_nf=-113 interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4
* ACS: * interference factor average: 0.0557166
* ACS: Survey analysis for channel 2 (2417 MHz)
* ACS: 1: min_nf=-113 interference_factor=0.0185185 nf=-113 time=162 busy=0 rx=3
* ACS: 2: min_nf=-113 interference_factor=0.0246914 nf=-113 time=162 busy=0 rx=4
* ACS: 3: min_nf=-113 interference_factor=0.037037 nf=-113 time=162 busy=0 rx=6
* ACS: 4: min_nf=-113 interference_factor=0.149068 nf=-113 time=161 busy=0 rx=24
* ACS: 5: min_nf=-113 interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4
* ACS: * interference factor average: 0.050832
* ACS: Survey analysis for channel 3 (2422 MHz)
* ACS: 1: min_nf=-113 interference_factor=2.51189e-23 nf=-113 time=162 busy=0
* rx=0 ACS: 2: min_nf=-113 interference_factor=0.0185185 nf=-113 time=162
* busy=0 rx=3 ACS: 3: min_nf=-113 interference_factor=0.0186335 nf=-113
* time=161 busy=0 rx=3 ACS: 4: min_nf=-113 interference_factor=0.0186335
* nf=-113 time=161 busy=0 rx=3 ACS: 5: min_nf=-113
* interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3 ACS: *
* interference factor average: 0.0148838 ACS: Survey analysis for channel 4
* (2427 MHz) ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114
* time=162 busy=0 rx=0 ACS: 2: min_nf=-114 interference_factor=0.0555556
* nf=-114 time=162 busy=0 rx=9 ACS: 3: min_nf=-114
* interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0 ACS: 4:
* min_nf=-114 interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3 ACS:
* 5: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: 1: min_nf=-113 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0
* ACS: 2: min_nf=-113 interference_factor=0.0185185 nf=-113 time=162 busy=0 rx=3
* ACS: 3: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3
* ACS: 4: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3
* ACS: 5: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3
* ACS: * interference factor average: 0.0148838
* ACS: Survey analysis for channel 4 (2427 MHz)
* ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: 2: min_nf=-114 interference_factor=0.0555556 nf=-114 time=162 busy=0 rx=9
* ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0
* ACS: 4: min_nf=-114 interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3
* ACS: 5: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: * interference factor average: 0.0160801
* ACS: Survey analysis for channel 5 (2432 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.409938 nf=-113 time=161 busy=0
* rx=66 ACS: 2: min_nf=-114 interference_factor=0.0432099 nf=-113 time=162
* busy=0 rx=7 ACS: 3: min_nf=-114 interference_factor=0.0124224 nf=-113
* time=161 busy=0 rx=2 ACS: 4: min_nf=-114 interference_factor=0.677019
* nf=-113 time=161 busy=0 rx=109 ACS: 5: min_nf=-114
* interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3 ACS: *
* interference factor average: 0.232244 ACS: Survey analysis for channel 6
* (2437 MHz) ACS: 1: min_nf=-113 interference_factor=0.552795 nf=-113 time=161
* busy=0 rx=89 ACS: 2: min_nf=-113 interference_factor=0.0807453 nf=-112
* time=161 busy=0 rx=13 ACS: 3: min_nf=-113 interference_factor=0.0310559
* nf=-113 time=161 busy=0 rx=5 ACS: 4: min_nf=-113
* interference_factor=0.434783 nf=-112 time=161 busy=0 rx=70 ACS: 5:
* min_nf=-113 interference_factor=0.0621118 nf=-113 time=161 busy=0 rx=10 ACS:
* * interference factor average: 0.232298 ACS: Survey analysis for channel 7
* (2442 MHz) ACS: 1: min_nf=-113 interference_factor=0.440994 nf=-112 time=161
* busy=0 rx=71 ACS: 2: min_nf=-113 interference_factor=0.385093 nf=-113
* time=161 busy=0 rx=62 ACS: 3: min_nf=-113 interference_factor=0.0372671
* nf=-113 time=161 busy=0 rx=6 ACS: 4: min_nf=-113
* interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6 ACS: 5:
* min_nf=-113 interference_factor=0.0745342 nf=-113 time=161 busy=0 rx=12 ACS:
* * interference factor average: 0.195031 ACS: Survey analysis for channel 8
* (2447 MHz) ACS: 1: min_nf=-114 interference_factor=0.0496894 nf=-112
* time=161 busy=0 rx=8 ACS: 2: min_nf=-114 interference_factor=0.0496894
* nf=-114 time=161 busy=0 rx=8 ACS: 3: min_nf=-114
* interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6 ACS: 4:
* min_nf=-114 interference_factor=0.12963 nf=-113 time=162 busy=0 rx=21 ACS: 5:
* min_nf=-114 interference_factor=0.166667 nf=-114 time=162 busy=0 rx=27 ACS:
* * interference factor average: 0.0865885 ACS: Survey analysis for channel 9
* (2452 MHz) ACS: 1: min_nf=-114 interference_factor=0.0124224 nf=-114
* time=161 busy=0 rx=2 ACS: 2: min_nf=-114 interference_factor=0.0310559
* nf=-114 time=161 busy=0 rx=5 ACS: 3: min_nf=-114
* interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0 ACS: 4:
* min_nf=-114 interference_factor=0.00617284 nf=-114 time=162 busy=0 rx=1 ACS:
* 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: 1: min_nf=-114 interference_factor=0.409938 nf=-113 time=161 busy=0 rx=66
* ACS: 2: min_nf=-114 interference_factor=0.0432099 nf=-113 time=162 busy=0 rx=7
* ACS: 3: min_nf=-114 interference_factor=0.0124224 nf=-113 time=161 busy=0 rx=2
* ACS: 4: min_nf=-114 interference_factor=0.677019 nf=-113 time=161 busy=0 rx=109
* ACS: 5: min_nf=-114 interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3
* ACS: * interference factor average: 0.232244
* ACS: Survey analysis for channel 6 (2437 MHz)
* ACS: 1: min_nf=-113 interference_factor=0.552795 nf=-113 time=161 busy=0 rx=89
* ACS: 2: min_nf=-113 interference_factor=0.0807453 nf=-112 time=161 busy=0 rx=13
* ACS: 3: min_nf=-113 interference_factor=0.0310559 nf=-113 time=161 busy=0 rx=5
* ACS: 4: min_nf=-113 interference_factor=0.434783 nf=-112 time=161 busy=0 rx=70
* ACS: 5: min_nf=-113 interference_factor=0.0621118 nf=-113 time=161 busy=0 rx=10
* ACS: * interference factor average: 0.232298
* ACS: Survey analysis for channel 7 (2442 MHz)
* ACS: 1: min_nf=-113 interference_factor=0.440994 nf=-112 time=161 busy=0 rx=71
* ACS: 2: min_nf=-113 interference_factor=0.385093 nf=-113 time=161 busy=0 rx=62
* ACS: 3: min_nf=-113 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6
* ACS: 4: min_nf=-113 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6
* ACS: 5: min_nf=-113 interference_factor=0.0745342 nf=-113 time=161 busy=0 rx=12
* ACS: * interference factor average: 0.195031
* ACS: Survey analysis for channel 8 (2447 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.0496894 nf=-112 time=161 busy=0 rx=8
* ACS: 2: min_nf=-114 interference_factor=0.0496894 nf=-114 time=161 busy=0 rx=8
* ACS: 3: min_nf=-114 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6
* ACS: 4: min_nf=-114 interference_factor=0.12963 nf=-113 time=162 busy=0 rx=21
* ACS: 5: min_nf=-114 interference_factor=0.166667 nf=-114 time=162 busy=0 rx=27
* ACS: * interference factor average: 0.0865885
* ACS: Survey analysis for channel 9 (2452 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.0124224 nf=-114 time=161 busy=0 rx=2
* ACS: 2: min_nf=-114 interference_factor=0.0310559 nf=-114 time=161 busy=0 rx=5
* ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0
* ACS: 4: min_nf=-114 interference_factor=0.00617284 nf=-114 time=162 busy=0 rx=1
* ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: * interference factor average: 0.00993022
* ACS: Survey analysis for channel 10 (2457 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0
* rx=1 ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161
* busy=0 rx=1 ACS: 3: min_nf=-114 interference_factor=0.00621118 nf=-114
* time=161 busy=0 rx=1 ACS: 4: min_nf=-114 interference_factor=0.0493827
* nf=-114 time=162 busy=0 rx=8 ACS: 5: min_nf=-114
* interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 ACS: *
* interference factor average: 0.0136033 ACS: Survey analysis for channel 11
* (2462 MHz) ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114
* time=161 busy=0 rx=0 ACS: 2: min_nf=-114 interference_factor=2.51189e-23
* nf=-113 time=161 busy=0 rx=0 ACS: 3: min_nf=-114
* interference_factor=2.51189e-23 nf=-113 time=161 busy=0 rx=0 ACS: 4:
* min_nf=-114 interference_factor=0.0432099 nf=-114 time=162 busy=0 rx=7 ACS:
* 5: min_nf=-114 interference_factor=0.0925926 nf=-114 time=162 busy=0 rx=15
* ACS: 1: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: 3: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: 4: min_nf=-114 interference_factor=0.0493827 nf=-114 time=162 busy=0 rx=8
* ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: * interference factor average: 0.0136033
* ACS: Survey analysis for channel 11 (2462 MHz)
* ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0
* ACS: 2: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=161 busy=0 rx=0
* ACS: 3: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=161 busy=0 rx=0
* ACS: 4: min_nf=-114 interference_factor=0.0432099 nf=-114 time=162 busy=0 rx=7
* ACS: 5: min_nf=-114 interference_factor=0.0925926 nf=-114 time=162 busy=0 rx=15
* ACS: * interference factor average: 0.0271605
* ACS: Survey analysis for channel 12 (2467 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.0621118 nf=-113 time=161 busy=0
* rx=10 ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161
* busy=0 rx=1 ACS: 3: min_nf=-114 interference_factor=2.51189e-23 nf=-113
* time=162 busy=0 rx=0 ACS: 4: min_nf=-114 interference_factor=2.51189e-23
* nf=-113 time=162 busy=0 rx=0 ACS: 5: min_nf=-114
* interference_factor=0.00617284 nf=-113 time=162 busy=0 rx=1 ACS: *
* interference factor average: 0.0148992 ACS: Survey analysis for channel 13
* (2472 MHz) ACS: 1: min_nf=-114 interference_factor=0.0745342 nf=-114
* time=161 busy=0 rx=12 ACS: 2: min_nf=-114 interference_factor=0.0555556
* nf=-114 time=162 busy=0 rx=9 ACS: 3: min_nf=-114
* interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 ACS: 4:
* min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 ACS:
* 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: 1: min_nf=-114 interference_factor=0.0621118 nf=-113 time=161 busy=0 rx=10
* ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1
* ACS: 3: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0
* ACS: 4: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0
* ACS: 5: min_nf=-114 interference_factor=0.00617284 nf=-113 time=162 busy=0 rx=1
* ACS: * interference factor average: 0.0148992
* ACS: Survey analysis for channel 13 (2472 MHz)
* ACS: 1: min_nf=-114 interference_factor=0.0745342 nf=-114 time=161 busy=0 rx=12
* ACS: 2: min_nf=-114 interference_factor=0.0555556 nf=-114 time=162 busy=0 rx=9
* ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: 4: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0
* ACS: * interference factor average: 0.0260179
* ACS: Survey analysis for selected bandwidth 20MHz
* ACS: * channel 1: total interference = 0.121432
@@ -240,29 +235,33 @@
* ACS: * channel 11: total interference = 0.0916111
* ACS: * channel 12: total interference = 0.0816809
* ACS: * channel 13: total interference = 0.0680776
* ACS: Ideal channel is 13 (2472 MHz) with total interference factor of
* 0.0680776
* ACS: Ideal channel is 13 (2472 MHz) with total interference factor of 0.0680776
*
* [1] http://en.wikipedia.org/wiki/Near_and_far_field
*/
static int acs_request_scan(struct hostapd_iface *iface);
static int acs_survey_is_sufficient(struct freq_survey *survey);
static void acs_clean_chan_surveys(struct hostapd_channel_data *chan) {
static void acs_clean_chan_surveys(struct hostapd_channel_data *chan)
{
struct freq_survey *survey, *tmp;
if (dl_list_empty(&chan->survey_list))
return;
dl_list_for_each_safe(survey, tmp, &chan->survey_list, struct freq_survey,
list) {
dl_list_for_each_safe(survey, tmp, &chan->survey_list,
struct freq_survey, list) {
dl_list_del(&survey->list);
os_free(survey);
}
}
static void acs_cleanup(struct hostapd_iface *iface) {
static void acs_cleanup(struct hostapd_iface *iface)
{
int i;
struct hostapd_channel_data *chan;
@@ -281,14 +280,18 @@ static void acs_cleanup(struct hostapd_iface *iface) {
iface->acs_num_completed_scans = 0;
}
static void acs_fail(struct hostapd_iface *iface) {
static void acs_fail(struct hostapd_iface *iface)
{
wpa_printf(MSG_ERROR, "ACS: Failed to start");
acs_cleanup(iface);
hostapd_disable_iface(iface);
}
static long double acs_survey_interference_factor(struct freq_survey *survey,
s8 min_nf) {
static long double
acs_survey_interference_factor(struct freq_survey *survey, s8 min_nf)
{
long double factor, busy, total;
if (survey->filled & SURVEY_HAS_CHAN_TIME_BUSY)
@@ -311,15 +314,18 @@ static long double acs_survey_interference_factor(struct freq_survey *survey,
/* TODO: figure out the best multiplier for noise floor base */
factor = pow(10, survey->nf / 5.0L) +
(busy / total) * pow(2, pow(10, (long double)survey->nf / 10.0L) -
(busy / total) *
pow(2, pow(10, (long double) survey->nf / 10.0L) -
pow(10, (long double) min_nf / 10.0L));
return factor;
}
static void
acs_survey_chan_interference_factor(struct hostapd_iface *iface,
struct hostapd_channel_data *chan) {
struct hostapd_channel_data *chan)
{
struct freq_survey *survey;
unsigned int i = 0;
long double int_factor = 0;
@@ -333,7 +339,8 @@ acs_survey_chan_interference_factor(struct hostapd_iface *iface,
chan->interference_factor = 0;
dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list) {
dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list)
{
i++;
if (!acs_survey_is_sufficient(survey)) {
@@ -342,13 +349,12 @@ acs_survey_chan_interference_factor(struct hostapd_iface *iface,
}
count++;
int_factor = acs_survey_interference_factor(survey, iface->lowest_nf);
int_factor = acs_survey_interference_factor(survey,
iface->lowest_nf);
chan->interference_factor += int_factor;
wpa_printf(MSG_DEBUG,
"ACS: %d: min_nf=%d interference_factor=%Lg nf=%d time=%lu "
"busy=%lu rx=%lu",
i, chan->min_nf, int_factor, survey->nf,
(unsigned long)survey->channel_time,
wpa_printf(MSG_DEBUG, "ACS: %d: min_nf=%d interference_factor=%Lg nf=%d time=%lu busy=%lu rx=%lu",
i, chan->min_nf, int_factor,
survey->nf, (unsigned long) survey->channel_time,
(unsigned long) survey->channel_time_busy,
(unsigned long) survey->channel_time_rx);
}
@@ -358,9 +364,11 @@ acs_survey_chan_interference_factor(struct hostapd_iface *iface,
chan->interference_factor /= count;
}
static int acs_usable_ht40_chan(struct hostapd_channel_data *chan) {
const int allowed[] = {36, 44, 52, 60, 100, 108, 116,
124, 132, 149, 157, 184, 192};
static int acs_usable_ht40_chan(struct hostapd_channel_data *chan)
{
const int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149,
157, 184, 192 };
unsigned int i;
for (i = 0; i < ARRAY_SIZE(allowed); i++)
@@ -370,7 +378,9 @@ static int acs_usable_ht40_chan(struct hostapd_channel_data *chan) {
return 0;
}
static int acs_usable_vht80_chan(struct hostapd_channel_data *chan) {
static int acs_usable_vht80_chan(struct hostapd_channel_data *chan)
{
const int allowed[] = { 36, 52, 100, 116, 132, 149 };
unsigned int i;
@@ -381,7 +391,9 @@ static int acs_usable_vht80_chan(struct hostapd_channel_data *chan) {
return 0;
}
static int acs_survey_is_sufficient(struct freq_survey *survey) {
static int acs_survey_is_sufficient(struct freq_survey *survey)
{
if (!(survey->filled & SURVEY_HAS_NF)) {
wpa_printf(MSG_INFO, "ACS: Survey is missing noise floor");
return 0;
@@ -394,8 +406,7 @@ static int acs_survey_is_sufficient(struct freq_survey *survey) {
if (!(survey->filled & SURVEY_HAS_CHAN_TIME_BUSY) &&
!(survey->filled & SURVEY_HAS_CHAN_TIME_RX)) {
wpa_printf(
MSG_INFO,
wpa_printf(MSG_INFO,
"ACS: Survey is missing RX and busy time (at least one is required)");
return 0;
}
@@ -403,11 +414,14 @@ static int acs_survey_is_sufficient(struct freq_survey *survey) {
return 1;
}
static int acs_survey_list_is_sufficient(struct hostapd_channel_data *chan) {
static int acs_survey_list_is_sufficient(struct hostapd_channel_data *chan)
{
struct freq_survey *survey;
int ret = -1;
dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list) {
dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list)
{
if (acs_survey_is_sufficient(survey)) {
ret = 1;
break;
@@ -419,14 +433,17 @@ static int acs_survey_list_is_sufficient(struct hostapd_channel_data *chan) {
ret = 1; /* no survey list entries */
if (!ret) {
wpa_printf(MSG_INFO, "ACS: Channel %d has insufficient survey data",
wpa_printf(MSG_INFO,
"ACS: Channel %d has insufficient survey data",
chan->chan);
}
return ret;
}
static int acs_surveys_are_sufficient(struct hostapd_iface *iface) {
static int acs_surveys_are_sufficient(struct hostapd_iface *iface)
{
int i;
struct hostapd_channel_data *chan;
int valid = 0;
@@ -446,7 +463,9 @@ static int acs_surveys_are_sufficient(struct hostapd_iface *iface) {
return !!valid;
}
static int acs_usable_chan(struct hostapd_channel_data *chan) {
static int acs_usable_chan(struct hostapd_channel_data *chan)
{
if (dl_list_empty(&chan->survey_list))
return 0;
if (chan->flag & HOSTAPD_CHAN_DISABLED)
@@ -456,16 +475,20 @@ static int acs_usable_chan(struct hostapd_channel_data *chan) {
return 1;
}
static int is_in_chanlist(struct hostapd_iface *iface,
struct hostapd_channel_data *chan) {
struct hostapd_channel_data *chan)
{
if (!iface->conf->acs_ch_list.num)
return 1;
return freq_range_list_includes(&iface->conf->acs_ch_list, chan->chan);
}
static void
acs_survey_all_chans_intereference_factor(struct hostapd_iface *iface) {
static void acs_survey_all_chans_intereference_factor(
struct hostapd_iface *iface)
{
int i;
struct hostapd_channel_data *chan;
@@ -488,8 +511,10 @@ acs_survey_all_chans_intereference_factor(struct hostapd_iface *iface) {
}
}
static struct hostapd_channel_data *acs_find_chan(struct hostapd_iface *iface,
int freq) {
int freq)
{
struct hostapd_channel_data *chan;
int i;
@@ -506,14 +531,20 @@ static struct hostapd_channel_data *acs_find_chan(struct hostapd_iface *iface,
return NULL;
}
static int is_24ghz_mode(enum hostapd_hw_mode mode) {
return mode == HOSTAPD_MODE_IEEE80211B || mode == HOSTAPD_MODE_IEEE80211G;
static int is_24ghz_mode(enum hostapd_hw_mode mode)
{
return mode == HOSTAPD_MODE_IEEE80211B ||
mode == HOSTAPD_MODE_IEEE80211G;
}
static int is_common_24ghz_chan(int chan) {
static int is_common_24ghz_chan(int chan)
{
return chan == 1 || chan == 6 || chan == 11;
}
#ifndef ACS_ADJ_WEIGHT
#define ACS_ADJ_WEIGHT 0.85
#endif /* ACS_ADJ_WEIGHT */
@@ -538,7 +569,8 @@ static int is_common_24ghz_chan(int chan) {
* summable (i.e., must be always greater than zero).
*/
static struct hostapd_channel_data *
acs_find_ideal_chan(struct hostapd_iface *iface) {
acs_find_ideal_chan(struct hostapd_iface *iface)
{
struct hostapd_channel_data *chan, *adj_chan, *ideal_chan = NULL,
*rand_chan = NULL;
long double factor, ideal_factor = 0;
@@ -548,23 +580,26 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
/* TODO: HT40- support */
if (iface->conf->ieee80211n && iface->conf->secondary_channel == -1) {
if (iface->conf->ieee80211n &&
iface->conf->secondary_channel == -1) {
wpa_printf(MSG_ERROR, "ACS: HT40- is not supported yet. Please try HT40+");
return NULL;
}
if (iface->conf->ieee80211n && iface->conf->secondary_channel)
if (iface->conf->ieee80211n &&
iface->conf->secondary_channel)
n_chans = 2;
if (iface->conf->ieee80211ac && iface->conf->vht_oper_chwidth == 1)
if (iface->conf->ieee80211ac &&
iface->conf->vht_oper_chwidth == 1)
n_chans = 4;
/* TODO: VHT80+80, VHT160. Update acs_adjust_vht_center_freq() too. */
wpa_printf(MSG_DEBUG, "ACS: Survey analysis for selected bandwidth %d MHz",
n_chans == 1 ? 20
: n_chans == 2 ? 40
: 80);
n_chans == 1 ? 20 :
n_chans == 2 ? 40 :
80);
for (i = 0; i < iface->current_mode->num_channels; i++) {
double total_weight;
@@ -581,19 +616,19 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
/* HT40 on 5 GHz has a limited set of primary channels as per
* 11n Annex J */
if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
iface->conf->ieee80211n && iface->conf->secondary_channel &&
iface->conf->ieee80211n &&
iface->conf->secondary_channel &&
!acs_usable_ht40_chan(chan)) {
wpa_printf(MSG_DEBUG,
"ACS: Channel %d: not allowed as primary channel for HT40",
wpa_printf(MSG_DEBUG, "ACS: Channel %d: not allowed as primary channel for HT40",
chan->chan);
continue;
}
if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
iface->conf->ieee80211ac && iface->conf->vht_oper_chwidth == 1 &&
iface->conf->ieee80211ac &&
iface->conf->vht_oper_chwidth == 1 &&
!acs_usable_vht80_chan(chan)) {
wpa_printf(MSG_DEBUG,
"ACS: Channel %d: not allowed as primary channel for VHT80",
wpa_printf(MSG_DEBUG, "ACS: Channel %d: not allowed as primary channel for VHT80",
chan->chan);
continue;
}
@@ -624,27 +659,35 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
* channel interference factor. */
if (is_24ghz_mode(iface->current_mode->mode)) {
for (j = 0; j < n_chans; j++) {
adj_chan = acs_find_chan(iface, chan->freq + (j * 20) - 5);
adj_chan = acs_find_chan(iface, chan->freq +
(j * 20) - 5);
if (adj_chan && acs_usable_chan(adj_chan)) {
factor += ACS_ADJ_WEIGHT * adj_chan->interference_factor;
factor += ACS_ADJ_WEIGHT *
adj_chan->interference_factor;
total_weight += ACS_ADJ_WEIGHT;
}
adj_chan = acs_find_chan(iface, chan->freq + (j * 20) - 10);
adj_chan = acs_find_chan(iface, chan->freq +
(j * 20) - 10);
if (adj_chan && acs_usable_chan(adj_chan)) {
factor += ACS_NEXT_ADJ_WEIGHT * adj_chan->interference_factor;
factor += ACS_NEXT_ADJ_WEIGHT *
adj_chan->interference_factor;
total_weight += ACS_NEXT_ADJ_WEIGHT;
}
adj_chan = acs_find_chan(iface, chan->freq + (j * 20) + 5);
adj_chan = acs_find_chan(iface, chan->freq +
(j * 20) + 5);
if (adj_chan && acs_usable_chan(adj_chan)) {
factor += ACS_ADJ_WEIGHT * adj_chan->interference_factor;
factor += ACS_ADJ_WEIGHT *
adj_chan->interference_factor;
total_weight += ACS_ADJ_WEIGHT;
}
adj_chan = acs_find_chan(iface, chan->freq + (j * 20) + 10);
adj_chan = acs_find_chan(iface, chan->freq +
(j * 20) + 10);
if (adj_chan && acs_usable_chan(adj_chan)) {
factor += ACS_NEXT_ADJ_WEIGHT * adj_chan->interference_factor;
factor += ACS_NEXT_ADJ_WEIGHT *
adj_chan->interference_factor;
total_weight += ACS_NEXT_ADJ_WEIGHT;
}
}
@@ -673,11 +716,13 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
"ACS: * channel %d: total interference = %Lg (%f bias)",
chan->chan, factor, bias->bias);
} else {
wpa_printf(MSG_DEBUG, "ACS: * channel %d: total interference = %Lg",
wpa_printf(MSG_DEBUG,
"ACS: * channel %d: total interference = %Lg",
chan->chan, factor);
}
if (acs_usable_chan(chan) && (!ideal_chan || factor < ideal_factor)) {
if (acs_usable_chan(chan) &&
(!ideal_chan || factor < ideal_factor)) {
ideal_factor = factor;
ideal_chan = chan;
}
@@ -688,9 +733,7 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
}
if (ideal_chan) {
wpa_printf(MSG_DEBUG,
"ACS: Ideal channel is %d (%d MHz) with total interference "
"factor of %Lg",
wpa_printf(MSG_DEBUG, "ACS: Ideal channel is %d (%d MHz) with total interference factor of %Lg",
ideal_chan->chan, ideal_chan->freq, ideal_factor);
return ideal_chan;
}
@@ -698,7 +741,9 @@ acs_find_ideal_chan(struct hostapd_iface *iface) {
return rand_chan;
}
static void acs_adjust_vht_center_freq(struct hostapd_iface *iface) {
static void acs_adjust_vht_center_freq(struct hostapd_iface *iface)
{
int offset;
wpa_printf(MSG_DEBUG, "ACS: Adjusting VHT center frequency");
@@ -717,10 +762,13 @@ static void acs_adjust_vht_center_freq(struct hostapd_iface *iface) {
return;
}
iface->conf->vht_oper_centr_freq_seg0_idx = iface->conf->channel + offset;
iface->conf->vht_oper_centr_freq_seg0_idx =
iface->conf->channel + offset;
}
static int acs_study_survey_based(struct hostapd_iface *iface) {
static int acs_study_survey_based(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "ACS: Trying survey-based ACS");
if (!iface->chans_surveyed) {
@@ -737,7 +785,9 @@ static int acs_study_survey_based(struct hostapd_iface *iface) {
return 0;
}
static int acs_study_options(struct hostapd_iface *iface) {
static int acs_study_options(struct hostapd_iface *iface)
{
int err;
err = acs_study_survey_based(iface);
@@ -750,7 +800,9 @@ static int acs_study_options(struct hostapd_iface *iface) {
return -1;
}
static void acs_study(struct hostapd_iface *iface) {
static void acs_study(struct hostapd_iface *iface)
{
struct hostapd_channel_data *ideal_chan;
int err;
@@ -785,12 +837,13 @@ fail:
/* This can possibly happen if channel parameters (secondary
* channel, center frequencies) are misconfigured */
wpa_printf(MSG_ERROR, "ACS: Possibly channel configuration is invalid, "
"please report this along with your config file.");
wpa_printf(MSG_ERROR, "ACS: Possibly channel configuration is invalid, please report this along with your config file.");
acs_fail(iface);
}
static void acs_scan_complete(struct hostapd_iface *iface) {
static void acs_scan_complete(struct hostapd_iface *iface)
{
int err;
iface->scan_cb = NULL;
@@ -821,14 +874,16 @@ fail:
acs_fail(iface);
}
static int acs_request_scan(struct hostapd_iface *iface) {
static int acs_request_scan(struct hostapd_iface *iface)
{
struct wpa_driver_scan_params params;
struct hostapd_channel_data *chan;
int i, *freq;
os_memset(&params, 0, sizeof(params));
params.freqs =
os_calloc(iface->current_mode->num_channels + 1, sizeof(params.freqs[0]));
params.freqs = os_calloc(iface->current_mode->num_channels + 1,
sizeof(params.freqs[0]));
if (params.freqs == NULL)
return -1;
@@ -848,7 +903,8 @@ static int acs_request_scan(struct hostapd_iface *iface) {
iface->scan_cb = acs_scan_complete;
wpa_printf(MSG_DEBUG, "ACS: Scanning %d / %d",
iface->acs_num_completed_scans + 1, iface->conf->acs_num_scans);
iface->acs_num_completed_scans + 1,
iface->conf->acs_num_scans);
if (hostapd_driver_scan(iface->bss[0], &params) < 0) {
wpa_printf(MSG_ERROR, "ACS: Failed to request initial scan");
@@ -861,11 +917,12 @@ static int acs_request_scan(struct hostapd_iface *iface) {
return 0;
}
enum hostapd_chan_status acs_init(struct hostapd_iface *iface) {
enum hostapd_chan_status acs_init(struct hostapd_iface *iface)
{
int err;
wpa_printf(MSG_INFO,
"ACS: Automatic channel selection started, this may take a bit");
wpa_printf(MSG_INFO, "ACS: Automatic channel selection started, this may take a bit");
if (iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) {
wpa_printf(MSG_INFO, "ACS: Offloading to driver");
@@ -16,9 +16,9 @@ enum hostapd_chan_status acs_init(struct hostapd_iface *iface);
#else /* CONFIG_ACS */
static inline enum hostapd_chan_status acs_init(struct hostapd_iface *iface) {
wpa_printf(MSG_ERROR, "ACS was disabled on your build, rebuild hostapd with "
"CONFIG_ACS=y or set channel");
static inline enum hostapd_chan_status acs_init(struct hostapd_iface *iface)
{
wpa_printf(MSG_ERROR, "ACS was disabled on your build, rebuild hostapd with CONFIG_ACS=y or set channel");
return HOSTAPD_CHAN_INVALID;
}
@@ -8,18 +8,20 @@
#include "utils/includes.h"
#include "ap_config.h"
#include "common/eapol_common.h"
#include "common/ieee802_11_defs.h"
#include "utils/common.h"
#include "crypto/sha1.h"
#include "radius/radius_client.h"
#include "common/ieee802_11_defs.h"
#include "common/eapol_common.h"
#include "eap_common/eap_wsc_common.h"
#include "eap_server/eap.h"
#include "radius/radius_client.h"
#include "sta_info.h"
#include "utils/common.h"
#include "wpa_auth.h"
#include "sta_info.h"
#include "ap_config.h"
static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) {
static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
{
struct hostapd_vlan *vlan, *prev;
vlan = bss->vlan;
@@ -33,7 +35,9 @@ static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) {
bss->vlan = NULL;
}
void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) {
void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
{
dl_list_init(&bss->anqp_elem);
bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
@@ -93,28 +97,31 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) {
bss->sae_anti_clogging_threshold = 5;
}
struct hostapd_config *hostapd_config_defaults(void) {
struct hostapd_config * hostapd_config_defaults(void)
{
#define ecw2cw(ecw) ((1 << (ecw)) - 1)
struct hostapd_config *conf;
struct hostapd_bss_config *bss;
const int aCWmin = 4, aCWmax = 10;
const struct hostapd_wmm_ac_params ac_bk = {aCWmin, aCWmax, 7, 0,
0}; /* background traffic */
const struct hostapd_wmm_ac_params ac_be = {aCWmin, aCWmax, 3, 0,
0}; /* best effort traffic */
const struct hostapd_wmm_ac_params ac_bk =
{ aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
const struct hostapd_wmm_ac_params ac_be =
{ aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
{ aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
{ aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
const struct hostapd_tx_queue_params txq_bk = {7, ecw2cw(aCWmin),
ecw2cw(aCWmax), 0};
const struct hostapd_tx_queue_params txq_be = {
3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
const struct hostapd_tx_queue_params txq_vi = {
1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
const struct hostapd_tx_queue_params txq_vo = {
1, (ecw2cw(aCWmin) + 1) / 4 - 1, (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
const struct hostapd_tx_queue_params txq_bk =
{ 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
const struct hostapd_tx_queue_params txq_be =
{ 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
const struct hostapd_tx_queue_params txq_vi =
{ 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
const struct hostapd_tx_queue_params txq_vo =
{ 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
(ecw2cw(aCWmin) + 1) / 2 - 1, 15};
#undef ecw2cw
@@ -188,12 +195,16 @@ struct hostapd_config *hostapd_config_defaults(void) {
return conf;
}
int hostapd_mac_comp(const void *a, const void *b) {
int hostapd_mac_comp(const void *a, const void *b)
{
return os_memcmp(a, b, sizeof(macaddr));
}
static int hostapd_config_read_wpa_psk(const char *fname,
struct hostapd_ssid *ssid) {
struct hostapd_ssid *ssid)
{
FILE *f;
char buf[128], *pos;
int line = 0, ret = 0, len, ok;
@@ -226,10 +237,8 @@ static int hostapd_config_read_wpa_psk(const char *fname,
continue;
if (hwaddr_aton(buf, addr)) {
wpa_printf(MSG_ERROR,
"Invalid MAC address '%s' on "
"line %d in '%s'",
buf, line, fname);
wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
"line %d in '%s'", buf, line, fname);
ret = -1;
break;
}
@@ -247,7 +256,8 @@ static int hostapd_config_read_wpa_psk(const char *fname,
pos = buf + 17;
if (*pos == '\0') {
wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", line, fname);
wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
line, fname);
os_free(psk);
ret = -1;
break;
@@ -259,14 +269,13 @@ static int hostapd_config_read_wpa_psk(const char *fname,
if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
ok = 1;
else if (len >= 8 && len < 64) {
pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, 4096, psk->psk, PMK_LEN);
pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
4096, psk->psk, PMK_LEN);
ok = 1;
}
if (!ok) {
wpa_printf(MSG_ERROR,
"Invalid PSK '%s' on line %d in "
"'%s'",
pos, line, fname);
wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
"'%s'", pos, line, fname);
os_free(psk);
ret = -1;
break;
@@ -281,24 +290,30 @@ static int hostapd_config_read_wpa_psk(const char *fname,
return ret;
}
static int hostapd_derive_psk(struct hostapd_ssid *ssid) {
static int hostapd_derive_psk(struct hostapd_ssid *ssid)
{
ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
if (ssid->wpa_psk == NULL) {
wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
return -1;
}
wpa_hexdump_ascii(MSG_DEBUG, "SSID", (u8 *)ssid->ssid, ssid->ssid_len);
wpa_hexdump_ascii(MSG_DEBUG, "SSID",
(u8 *) ssid->ssid, ssid->ssid_len);
wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
(u8 *) ssid->wpa_passphrase,
os_strlen(ssid->wpa_passphrase));
pbkdf2_sha1(ssid->wpa_passphrase, ssid->ssid, ssid->ssid_len, 4096,
pbkdf2_sha1(ssid->wpa_passphrase,
ssid->ssid, ssid->ssid_len,
4096, ssid->wpa_psk->psk, PMK_LEN);
wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
ssid->wpa_psk->psk, PMK_LEN);
wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)", ssid->wpa_psk->psk,
PMK_LEN);
return 0;
}
int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) {
int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
{
struct hostapd_ssid *ssid = &conf->ssid;
if (ssid->wpa_passphrase != NULL) {
@@ -315,15 +330,18 @@ int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) {
}
if (ssid->wpa_psk_file) {
if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid))
if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
&conf->ssid))
return -1;
}
return 0;
}
static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
int num_servers) {
int num_servers)
{
int i;
for (i = 0; i < num_servers; i++) {
@@ -332,8 +350,10 @@ static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
os_free(servers);
}
struct hostapd_radius_attr *
hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) {
hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
{
for (; attr; attr = attr->next) {
if (attr->type == type)
return attr;
@@ -341,7 +361,9 @@ hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) {
return NULL;
}
static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) {
static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
{
struct hostapd_radius_attr *prev;
while (attr) {
@@ -352,14 +374,18 @@ static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) {
}
}
void hostapd_config_free_eap_user(struct hostapd_eap_user *user) {
void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
{
hostapd_config_free_radius_attr(user->accept_attr);
os_free(user->identity);
bin_clear_free(user->password, user->password_len);
os_free(user);
}
static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) {
static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
{
int i;
for (i = 0; i < NUM_WEP_KEYS; i++) {
bin_clear_free(keys->key[i], keys->len[i]);
@@ -367,7 +393,9 @@ static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) {
}
}
void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l) {
void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
{
struct hostapd_wpa_psk *psk, *tmp;
for (psk = *l; psk;) {
@@ -378,17 +406,22 @@ void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l) {
*l = NULL;
}
static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf) {
static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
{
struct anqp_element *elem;
while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element, list))) {
while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
list))) {
dl_list_del(&elem->list);
wpabuf_free(elem->payload);
os_free(elem);
}
}
void hostapd_config_free_bss(struct hostapd_bss_config *conf) {
void hostapd_config_free_bss(struct hostapd_bss_config *conf)
{
struct hostapd_eap_user *user, *prev_user;
if (conf == NULL)
@@ -552,11 +585,13 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf) {
os_free(conf);
}
/**
* hostapd_config_free - Free hostapd configuration
* @conf: Configuration data from hostapd_config_read().
*/
void hostapd_config_free(struct hostapd_config *conf) {
void hostapd_config_free(struct hostapd_config *conf)
{
size_t i;
if (conf == NULL)
@@ -578,6 +613,7 @@ void hostapd_config_free(struct hostapd_config *conf) {
os_free(conf);
}
/**
* hostapd_maclist_found - Find a MAC address from a list
* @list: MAC address list
@@ -589,7 +625,8 @@ void hostapd_config_free(struct hostapd_config *conf) {
* Perform a binary search for given MAC address from a pre-sorted list.
*/
int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
const u8 *addr, struct vlan_description *vlan_id) {
const u8 *addr, struct vlan_description *vlan_id)
{
int start, end, middle, res;
start = 0;
@@ -612,7 +649,9 @@ int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
return 0;
}
int hostapd_rate_found(int *list, int rate) {
int hostapd_rate_found(int *list, int rate)
{
int i;
if (list == NULL)
@@ -625,8 +664,10 @@ int hostapd_rate_found(int *list, int rate) {
return 0;
}
int hostapd_vlan_valid(struct hostapd_vlan *vlan,
struct vlan_description *vlan_desc) {
struct vlan_description *vlan_desc)
{
struct hostapd_vlan *v = vlan;
int i;
@@ -634,7 +675,8 @@ int hostapd_vlan_valid(struct hostapd_vlan *vlan,
vlan_desc->untagged > MAX_VLAN_ID)
return 0;
for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
if (vlan_desc->tagged[i] < 0 || vlan_desc->tagged[i] > MAX_VLAN_ID)
if (vlan_desc->tagged[i] < 0 ||
vlan_desc->tagged[i] > MAX_VLAN_ID)
return 0;
}
if (!vlan_desc->untagged && !vlan_desc->tagged[0])
@@ -649,7 +691,9 @@ int hostapd_vlan_valid(struct hostapd_vlan *vlan,
return 0;
}
const char *hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) {
const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
{
struct hostapd_vlan *v = vlan;
while (v) {
if (v->vlan_id == vlan_id)
@@ -659,27 +703,32 @@ const char *hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) {
return NULL;
}
const u8 *hostapd_get_psk(const struct hostapd_bss_config *conf, const u8 *addr,
const u8 *p2p_dev_addr, const u8 *prev_psk) {
const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
const u8 *addr, const u8 *p2p_dev_addr,
const u8 *prev_psk)
{
struct hostapd_wpa_psk *psk;
int next_ok = prev_psk == NULL;
if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
wpa_printf(MSG_DEBUG,
"Searching a PSK for " MACSTR " p2p_dev_addr=" MACSTR
" prev_psk=%p",
wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
" p2p_dev_addr=" MACSTR " prev_psk=%p",
MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
addr = NULL; /* Use P2P Device Address for matching */
} else {
wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR " prev_psk=%p",
wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
" prev_psk=%p",
MAC2STR(addr), prev_psk);
}
for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
if (next_ok &&
(psk->group || (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
(psk->group ||
(addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
(!addr && p2p_dev_addr &&
os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) == 0)))
os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
0)))
return psk->psk;
if (psk->psk == prev_psk)
@@ -689,9 +738,11 @@ const u8 *hostapd_get_psk(const struct hostapd_bss_config *conf, const u8 *addr,
return NULL;
}
static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
struct hostapd_config *conf,
int full_config) {
int full_config)
{
if (full_config && bss->ieee802_1x && !bss->eap_server &&
!bss->radius->auth_servers) {
wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
@@ -702,7 +753,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
if (bss->wpa) {
int wep, i;
wep = bss->default_wep_key_len > 0 || bss->individual_wep_key_len > 0;
wep = bss->default_wep_key_len > 0 ||
bss->individual_wep_key_len > 0;
for (i = 0; i < NUM_WEP_KEYS; i++) {
if (bss->ssid.wep.keys_set) {
wep = 1;
@@ -711,13 +763,13 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
}
if (wep) {
wpa_printf(MSG_ERROR,
"WEP configuration in a WPA network is not supported");
wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
return -1;
}
}
if (full_config && bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
if (full_config && bss->wpa &&
bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
"RADIUS checking (macaddr_acl=2) enabled.");
@@ -739,10 +791,12 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
for (i = 0; i < conf->num_bss; i++) {
if (conf->bss[i] != bss &&
(hostapd_mac_comp(conf->bss[i]->bssid, bss->bssid) == 0)) {
wpa_printf(MSG_ERROR,
"Duplicate BSSID " MACSTR " on interface '%s' and '%s'.",
MAC2STR(bss->bssid), conf->bss[i]->iface, bss->iface);
(hostapd_mac_comp(conf->bss[i]->bssid,
bss->bssid) == 0)) {
wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
" on interface '%s' and '%s'.",
MAC2STR(bss->bssid),
conf->bss[i]->iface, bss->iface);
return -1;
}
}
@@ -750,7 +804,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
#ifdef CONFIG_IEEE80211R
if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
(bss->nas_identifier == NULL || os_strlen(bss->nas_identifier) < 1 ||
(bss->nas_identifier == NULL ||
os_strlen(bss->nas_identifier) < 1 ||
os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
"nas_identifier to be configured as a 1..48 octet "
@@ -777,7 +832,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
if (full_config && conf->ieee80211n && bss->wpa &&
!(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) {
WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
{
bss->disable_11n = 1;
wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
"requires CCMP/GCMP to be enabled, disabling HT "
@@ -789,8 +845,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
if (full_config && conf->ieee80211ac &&
bss->ssid.security_policy == SECURITY_STATIC_WEP) {
bss->disable_11ac = 1;
wpa_printf(MSG_ERROR, "VHT (IEEE 802.11ac) with WEP is not allowed, "
"disabling VHT capabilities");
wpa_printf(MSG_ERROR,
"VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
}
#endif /* CONFIG_IEEE80211AC */
@@ -801,8 +857,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
bss->wps_state = 0;
}
if (full_config && bss->wps_state && bss->ssid.wep.keys_set &&
bss->wpa == 0) {
if (full_config && bss->wps_state &&
bss->ssid.wep.keys_set && bss->wpa == 0) {
wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
"disabled");
bss->wps_state = 0;
@@ -821,7 +877,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
if (full_config && bss->hs20 &&
(!(bss->wpa & 2) ||
!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))) {
WPA_CIPHER_CCMP_256 |
WPA_CIPHER_GCMP_256)))) {
wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
"configuration is required for Hotspot 2.0 "
"functionality");
@@ -841,22 +898,22 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
return 0;
}
static int hostapd_config_check_cw(struct hostapd_config *conf, int queue) {
static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
{
int tx_cwmin = conf->tx_queue[queue].cwmin;
int tx_cwmax = conf->tx_queue[queue].cwmax;
int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
if (tx_cwmin > tx_cwmax) {
wpa_printf(
MSG_ERROR,
wpa_printf(MSG_ERROR,
"Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
tx_cwmin, tx_cwmax);
return -1;
}
if (ac_cwmin > ac_cwmax) {
wpa_printf(
MSG_ERROR,
wpa_printf(MSG_ERROR,
"Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
ac_cwmin, ac_cwmax);
return -1;
@@ -864,7 +921,9 @@ static int hostapd_config_check_cw(struct hostapd_config *conf, int queue) {
return 0;
}
int hostapd_config_check(struct hostapd_config *conf, int full_config) {
int hostapd_config_check(struct hostapd_config *conf, int full_config)
{
size_t i;
if (full_config && conf->ieee80211d &&
@@ -880,16 +939,15 @@ int hostapd_config_check(struct hostapd_config *conf, int full_config) {
return -1;
}
if (full_config && conf->local_pwr_constraint != -1 && !conf->ieee80211d) {
wpa_printf(MSG_ERROR,
"Cannot add Power Constraint element without Country element");
if (full_config && conf->local_pwr_constraint != -1 &&
!conf->ieee80211d) {
wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
return -1;
}
if (full_config && conf->spectrum_mgmt_required &&
conf->local_pwr_constraint == -1) {
wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country "
"and Power Constraint elements");
wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
return -1;
}
@@ -906,8 +964,10 @@ int hostapd_config_check(struct hostapd_config *conf, int full_config) {
return 0;
}
void hostapd_set_security_params(struct hostapd_bss_config *bss,
int full_config) {
int full_config)
{
if (bss->individual_wep_key_len == 0) {
/* individual keys are not use; can use key idx0 for
* broadcast keys */
@@ -933,8 +993,8 @@ void hostapd_set_security_params(struct hostapd_bss_config *bss,
bss->ssid.security_policy = SECURITY_IEEE_802_1X;
bss->ssid.wep.default_len = bss->default_wep_key_len;
if (full_config && bss->default_wep_key_len) {
cipher =
bss->default_wep_key_len >= 13 ? WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
cipher = bss->default_wep_key_len >= 13 ?
WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
} else if (full_config && bss->ssid.wep.keys_set) {
if (bss->ssid.wep.len[0] >= 13)
cipher = WPA_CIPHER_WEP104;
@@ -10,14 +10,14 @@
#define HOSTAPD_CONFIG_H
#include "common/defs.h"
#include "common/ieee802_11_common.h"
#include "common/ieee802_11_defs.h"
#include "common/wpa_common.h"
#include "fst/fst.h"
#include "ip_addr.h"
#include "utils/list.h"
#include "vlan.h"
#include "ip_addr.h"
#include "common/wpa_common.h"
#include "common/ieee802_11_defs.h"
#include "common/ieee802_11_common.h"
#include "wps/wps.h"
#include "fst/fst.h"
#include "vlan.h"
/**
* mesh_conf - local MBSS state and settings
@@ -114,6 +114,7 @@ struct hostapd_ssid {
#endif /* CONFIG_FULL_DYNAMIC_VLAN */
};
#define VLAN_ID_WILDCARD -1
struct hostapd_vlan {
@@ -176,6 +177,7 @@ struct hostapd_radius_attr {
struct hostapd_radius_attr *next;
};
#define NUM_TX_QUEUES 4
struct hostapd_tx_queue_params {
@@ -185,6 +187,7 @@ struct hostapd_tx_queue_params {
int burst; /* maximum burst time in 0.1 ms, i.e., 10 = 1 ms */
};
#define MAX_ROAMING_CONSORTIUM_LEN 15
struct hostapd_roaming_consortium {
@@ -221,6 +224,7 @@ struct anqp_element {
struct wpabuf *payload;
};
/**
* struct hostapd_bss_config - Per-BSS configuration
*/
@@ -593,6 +597,7 @@ struct hostapd_bss_config {
int ftm_initiator;
};
/**
* struct hostapd_config - Per-radio interface configuration
*/
@@ -608,7 +613,10 @@ struct hostapd_config {
u8 acs;
struct wpa_freq_range_list acs_ch_list;
enum hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */
enum { LONG_PREAMBLE = 0, SHORT_PREAMBLE = 1 } preamble;
enum {
LONG_PREAMBLE = 0,
SHORT_PREAMBLE = 1
} preamble;
int *supported_rates;
int *basic_rates;
@@ -701,6 +709,7 @@ struct hostapd_config {
struct wpabuf *civic;
};
int hostapd_mac_comp(const void *a, const void *b);
struct hostapd_config * hostapd_config_defaults(void);
void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
@@ -711,12 +720,14 @@ void hostapd_config_free(struct hostapd_config *conf);
int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
const u8 *addr, struct vlan_description *vlan_id);
int hostapd_rate_found(int *list, int rate);
const u8 *hostapd_get_psk(const struct hostapd_bss_config *conf, const u8 *addr,
const u8 *p2p_dev_addr, const u8 *prev_psk);
const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
const u8 *addr, const u8 *p2p_dev_addr,
const u8 *prev_psk);
int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf);
int hostapd_vlan_valid(struct hostapd_vlan *vlan,
struct vlan_description *vlan_desc);
const char *hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id);
const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
int vlan_id);
struct hostapd_radius_attr *
hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type);
int hostapd_config_check(struct hostapd_config *conf, int full_config);
@@ -8,20 +8,22 @@
#include "utils/includes.h"
#include "ap_config.h"
#include "ap_drv_ops.h"
#include "common/hw_features_common.h"
#include "common/ieee802_11_defs.h"
#include "hostapd.h"
#include "hs20.h"
#include "ieee802_11.h"
#include "p2p/p2p.h"
#include "p2p_hostapd.h"
#include "sta_info.h"
#include "utils/common.h"
#include "common/ieee802_11_defs.h"
#include "common/hw_features_common.h"
#include "wps/wps.h"
#include "p2p/p2p.h"
#include "hostapd.h"
#include "ieee802_11.h"
#include "sta_info.h"
#include "ap_config.h"
#include "p2p_hostapd.h"
#include "hs20.h"
#include "ap_drv_ops.h"
u32 hostapd_sta_flags_to_drv(u32 flags) {
u32 hostapd_sta_flags_to_drv(u32 flags)
{
int res = 0;
if (flags & WLAN_STA_AUTHORIZED)
res |= WPA_STA_AUTHORIZED;
@@ -38,7 +40,9 @@ u32 hostapd_sta_flags_to_drv(u32 flags) {
return res;
}
static int add_buf(struct wpabuf **dst, const struct wpabuf *src) {
static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
{
if (!src)
return 0;
if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
@@ -47,7 +51,9 @@ static int add_buf(struct wpabuf **dst, const struct wpabuf *src) {
return 0;
}
static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len) {
static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
{
if (!data || !len)
return 0;
if (wpabuf_resize(dst, len) != 0)
@@ -56,10 +62,12 @@ static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len) {
return 0;
}
int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
struct wpabuf **beacon_ret,
struct wpabuf **proberesp_ret,
struct wpabuf **assocresp_ret) {
struct wpabuf **assocresp_ret)
{
struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
u8 buf[200], *pos;
@@ -186,53 +194,66 @@ fail:
return -1;
}
void hostapd_free_ap_extra_ies(struct hostapd_data *hapd, struct wpabuf *beacon,
void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
struct wpabuf *beacon,
struct wpabuf *proberesp,
struct wpabuf *assocresp) {
struct wpabuf *assocresp)
{
wpabuf_free(beacon);
wpabuf_free(proberesp);
wpabuf_free(assocresp);
}
int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd) {
int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
{
if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
return 0;
return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
}
int hostapd_set_ap_wps_ie(struct hostapd_data *hapd) {
int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
{
struct wpabuf *beacon, *proberesp, *assocresp;
int ret;
if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
return 0;
if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 0)
if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
0)
return -1;
ret =
hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp, assocresp);
ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
assocresp);
hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
return ret;
}
int hostapd_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
int authorized) {
int hostapd_set_authorized(struct hostapd_data *hapd,
struct sta_info *sta, int authorized)
{
if (authorized) {
return hostapd_sta_set_flags(hapd, sta->addr,
hostapd_sta_flags_to_drv(sta->flags),
hostapd_sta_flags_to_drv(
sta->flags),
WPA_STA_AUTHORIZED, ~0);
}
return hostapd_sta_set_flags(hapd, sta->addr,
hostapd_sta_flags_to_drv(sta->flags), 0,
~WPA_STA_AUTHORIZED);
hostapd_sta_flags_to_drv(sta->flags),
0, ~WPA_STA_AUTHORIZED);
}
int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta) {
int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
{
int set_flags, total_flags, flags_and, flags_or;
total_flags = hostapd_sta_flags_to_drv(sta->flags);
set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
@@ -242,12 +263,14 @@ int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta) {
set_flags |= WPA_STA_AUTHORIZED;
flags_or = total_flags & set_flags;
flags_and = total_flags | ~set_flags;
return hostapd_sta_set_flags(hapd, sta->addr, total_flags, flags_or,
flags_and);
return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
flags_or, flags_and);
}
int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
int enabled) {
int enabled)
{
struct wpa_bss_params params;
os_memset(&params, 0, sizeof(params));
params.ifname = ifname;
@@ -258,7 +281,8 @@ int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
params.wpa_group = hapd->conf->wpa_group;
if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
(WPA_PROTO_WPA | WPA_PROTO_RSN))
params.wpa_pairwise = hapd->conf->wpa_pairwise | hapd->conf->rsn_pairwise;
params.wpa_pairwise = hapd->conf->wpa_pairwise |
hapd->conf->rsn_pairwise;
else if (hapd->conf->wpa & WPA_PROTO_RSN)
params.wpa_pairwise = hapd->conf->rsn_pairwise;
else if (hapd->conf->wpa & WPA_PROTO_WPA)
@@ -272,19 +296,25 @@ int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
return hostapd_set_ieee8021x(hapd, &params);
}
int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname) {
int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
{
char force_ifname[IFNAMSIZ];
u8 if_addr[ETH_ALEN];
return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr, NULL,
NULL, force_ifname, if_addr, NULL, 0);
return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
NULL, NULL, force_ifname, if_addr, NULL, 0);
}
int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname) {
int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
{
return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
}
int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
const u8 *addr, int aid, int val) {
const u8 *addr, int aid, int val)
{
const char *bridge = NULL;
if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
@@ -293,40 +323,49 @@ int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
bridge = hapd->conf->wds_bridge;
else if (hapd->conf->bridge[0])
bridge = hapd->conf->bridge;
return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val, bridge,
ifname_wds);
return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
bridge, ifname_wds);
}
int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
u16 auth_alg) {
u16 auth_alg)
{
if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
return 0;
return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
}
int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr, u16 seq,
u16 status, const u8 *ie, size_t len) {
int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
u16 seq, u16 status, const u8 *ie, size_t len)
{
if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
return 0;
return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr, seq,
status, ie, len);
return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr,
seq, status, ie, len);
}
int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr, int reassoc,
u16 status, const u8 *ie, size_t len) {
int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
int reassoc, u16 status, const u8 *ie, size_t len)
{
if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
return 0;
return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr, reassoc,
status, ie, len);
return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
reassoc, status, ie, len);
}
int hostapd_sta_add(struct hostapd_data *hapd, const u8 *addr, u16 aid,
u16 capability, const u8 *supp_rates, size_t supp_rates_len,
int hostapd_sta_add(struct hostapd_data *hapd,
const u8 *addr, u16 aid, u16 capability,
const u8 *supp_rates, size_t supp_rates_len,
u16 listen_interval,
const struct ieee80211_ht_capabilities *ht_capab,
const struct ieee80211_vht_capabilities *vht_capab,
u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
int set) {
int set)
{
struct hostapd_sta_add_params params;
if (hapd->driver == NULL)
@@ -352,88 +391,113 @@ int hostapd_sta_add(struct hostapd_data *hapd, const u8 *addr, u16 aid,
return hapd->driver->sta_add(hapd->drv_priv, &params);
}
int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr, u8 *tspec_ie,
size_t tspec_ielen) {
int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
u8 *tspec_ie, size_t tspec_ielen)
{
if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
return 0;
return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie, tspec_ielen);
return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
tspec_ielen);
}
int hostapd_set_privacy(struct hostapd_data *hapd, int enabled) {
int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
{
if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
return 0;
return hapd->driver->set_privacy(hapd->drv_priv, enabled);
}
int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
size_t elem_len) {
size_t elem_len)
{
if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
return 0;
return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
}
int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len) {
int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
{
if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
return 0;
return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
}
int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len) {
int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
{
if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
return 0;
return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
}
int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
const char *ifname, const u8 *addr, void *bss_ctx,
void **drv_priv, char *force_ifname, u8 *if_addr,
const char *bridge, int use_existing) {
const char *bridge, int use_existing)
{
if (hapd->driver == NULL || hapd->driver->if_add == NULL)
return -1;
return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr, bss_ctx,
drv_priv, force_ifname, if_addr, bridge,
use_existing, 1);
return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
bss_ctx, drv_priv, force_ifname, if_addr,
bridge, use_existing, 1);
}
int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
const char *ifname) {
const char *ifname)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->if_remove == NULL)
return -1;
return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
}
int hostapd_set_ieee8021x(struct hostapd_data *hapd,
struct wpa_bss_params *params) {
struct wpa_bss_params *params)
{
if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
return 0;
return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
}
int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
const u8 *addr, int idx, u8 *seq) {
const u8 *addr, int idx, u8 *seq)
{
if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
return 0;
return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx, seq);
return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
seq);
}
int hostapd_flush(struct hostapd_data *hapd) {
int hostapd_flush(struct hostapd_data *hapd)
{
if (hapd->driver == NULL || hapd->driver->flush == NULL)
return 0;
return hapd->driver->flush(hapd->drv_priv);
}
int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
int freq, int channel, int ht_enabled, int vht_enabled,
int sec_channel_offset, int vht_oper_chwidth,
int center_segment0, int center_segment1) {
int center_segment0, int center_segment1)
{
struct hostapd_freq_params data;
if (hostapd_set_freq_params(
&data, mode, freq, channel, ht_enabled, vht_enabled,
sec_channel_offset, vht_oper_chwidth, center_segment0,
center_segment1,
hapd->iface->current_mode ? hapd->iface->current_mode->vht_capab : 0))
if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
vht_enabled, sec_channel_offset,
vht_oper_chwidth,
center_segment0, center_segment1,
hapd->iface->current_mode ?
hapd->iface->current_mode->vht_capab : 0))
return -1;
if (hapd->driver == NULL)
@@ -443,138 +507,184 @@ int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
return hapd->driver->set_freq(hapd->drv_priv, &data);
}
int hostapd_set_rts(struct hostapd_data *hapd, int rts) {
int hostapd_set_rts(struct hostapd_data *hapd, int rts)
{
if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
return 0;
return hapd->driver->set_rts(hapd->drv_priv, rts);
}
int hostapd_set_frag(struct hostapd_data *hapd, int frag) {
int hostapd_set_frag(struct hostapd_data *hapd, int frag)
{
if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
return 0;
return hapd->driver->set_frag(hapd->drv_priv, frag);
}
int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr, int total_flags,
int flags_or, int flags_and) {
int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
int total_flags, int flags_or, int flags_and)
{
if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
return 0;
return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
flags_or, flags_and);
}
int hostapd_set_country(struct hostapd_data *hapd, const char *country) {
if (hapd->driver == NULL || hapd->driver->set_country == NULL)
int hostapd_set_country(struct hostapd_data *hapd, const char *country)
{
if (hapd->driver == NULL ||
hapd->driver->set_country == NULL)
return 0;
return hapd->driver->set_country(hapd->drv_priv, country);
}
int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
int cw_min, int cw_max, int burst_time) {
int cw_min, int cw_max, int burst_time)
{
if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
return 0;
return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs, cw_min,
cw_max, burst_time);
return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
cw_min, cw_max, burst_time);
}
struct hostapd_hw_modes *hostapd_get_hw_feature_data(struct hostapd_data *hapd,
u16 *num_modes,
u16 *flags) {
if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
struct hostapd_hw_modes *
hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
u16 *flags)
{
if (hapd->driver == NULL ||
hapd->driver->get_hw_feature_data == NULL)
return NULL;
return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes, flags);
return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
flags);
}
int hostapd_driver_commit(struct hostapd_data *hapd) {
int hostapd_driver_commit(struct hostapd_data *hapd)
{
if (hapd->driver == NULL || hapd->driver->commit == NULL)
return 0;
return hapd->driver->commit(hapd->drv_priv);
}
int hostapd_drv_none(struct hostapd_data *hapd) {
int hostapd_drv_none(struct hostapd_data *hapd)
{
return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
}
int hostapd_driver_scan(struct hostapd_data *hapd,
struct wpa_driver_scan_params *params) {
struct wpa_driver_scan_params *params)
{
if (hapd->driver && hapd->driver->scan2)
return hapd->driver->scan2(hapd->drv_priv, params);
return -1;
}
struct wpa_scan_results *
hostapd_driver_get_scan_results(struct hostapd_data *hapd) {
struct wpa_scan_results * hostapd_driver_get_scan_results(
struct hostapd_data *hapd)
{
if (hapd->driver && hapd->driver->get_scan_results2)
return hapd->driver->get_scan_results2(hapd->drv_priv);
return NULL;
}
int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
int duration) {
int duration)
{
if (hapd->driver && hapd->driver->set_noa)
return hapd->driver->set_noa(hapd->drv_priv, count, start, duration);
return hapd->driver->set_noa(hapd->drv_priv, count, start,
duration);
return -1;
}
int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
enum wpa_alg alg, const u8 *addr, int key_idx,
int set_tx, const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len) {
enum wpa_alg alg, const u8 *addr,
int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
{
if (hapd->driver == NULL || hapd->driver->set_key == NULL)
return 0;
return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr, key_idx,
set_tx, seq, seq_len, key, key_len);
return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
key_idx, set_tx, seq, seq_len, key,
key_len);
}
int hostapd_drv_send_mlme(struct hostapd_data *hapd, const void *msg,
size_t len, int noack) {
int hostapd_drv_send_mlme(struct hostapd_data *hapd,
const void *msg, size_t len, int noack)
{
if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
return 0;
return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0, NULL, 0);
return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
NULL, 0);
}
int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd, const void *msg,
size_t len, int noack, const u16 *csa_offs,
size_t csa_offs_len) {
int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
const void *msg, size_t len, int noack,
const u16 *csa_offs, size_t csa_offs_len)
{
if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
return 0;
return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0, csa_offs,
csa_offs_len);
return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
csa_offs, csa_offs_len);
}
int hostapd_drv_sta_deauth(struct hostapd_data *hapd, const u8 *addr,
int reason) {
int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
const u8 *addr, int reason)
{
if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
return 0;
return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr, reason);
return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
reason);
}
int hostapd_drv_sta_disassoc(struct hostapd_data *hapd, const u8 *addr,
int reason) {
int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
const u8 *addr, int reason)
{
if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
return 0;
return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
reason);
}
int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
const u8 *peer, u8 *buf, u16 *buf_len) {
const u8 *peer, u8 *buf, u16 *buf_len)
{
if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
return -1;
return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf, buf_len);
return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
buf_len);
}
int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
unsigned int wait, const u8 *dst, const u8 *data,
size_t len) {
size_t len)
{
const u8 *bssid;
const u8 wildcard_bssid[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
const u8 wildcard_bssid[ETH_ALEN] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
return 0;
bssid = hapd->own_addr;
if (!is_multicast_ether_addr(dst) && len > 0 &&
data[0] == WLAN_ACTION_PUBLIC) {
if (!is_multicast_ether_addr(dst) &&
len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
struct sta_info *sta;
/*
@@ -589,22 +699,26 @@ int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
hapd->own_addr, bssid, data, len, 0);
}
int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
unsigned int freq, unsigned int wait,
const u8 *dst, const u8 *data,
size_t len) {
unsigned int freq,
unsigned int wait, const u8 *dst,
const u8 *data, size_t len)
{
if (hapd->driver == NULL || hapd->driver->send_action == NULL)
return 0;
return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
hapd->own_addr, hapd->own_addr, data, len,
0);
hapd->own_addr, hapd->own_addr, data,
len, 0);
}
int hostapd_start_dfs_cac(struct hostapd_iface *iface,
enum hostapd_hw_mode mode, int freq, int channel,
int ht_enabled, int vht_enabled,
enum hostapd_hw_mode mode, int freq,
int channel, int ht_enabled, int vht_enabled,
int sec_channel_offset, int vht_oper_chwidth,
int center_segment0, int center_segment1) {
int center_segment0, int center_segment1)
{
struct hostapd_data *hapd = iface->bss[0];
struct hostapd_freq_params data;
int res;
@@ -619,8 +733,9 @@ int hostapd_start_dfs_cac(struct hostapd_iface *iface,
}
if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
vht_enabled, sec_channel_offset, vht_oper_chwidth,
center_segment0, center_segment1,
vht_enabled, sec_channel_offset,
vht_oper_chwidth, center_segment0,
center_segment1,
iface->current_mode->vht_capab)) {
wpa_printf(MSG_ERROR, "Can't set freq params");
return -1;
@@ -635,42 +750,52 @@ int hostapd_start_dfs_cac(struct hostapd_iface *iface,
return res;
}
int hostapd_drv_set_qos_map(struct hostapd_data *hapd, const u8 *qos_map_set,
u8 qos_map_set_len) {
int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
const u8 *qos_map_set, u8 qos_map_set_len)
{
if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
return 0;
return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
qos_map_set_len);
}
static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
struct hostapd_hw_modes *mode,
int acs_ch_list_all,
int **freq_list) {
int **freq_list)
{
int i;
for (i = 0; i < mode->num_channels; i++) {
struct hostapd_channel_data *chan = &mode->channels[i];
if ((acs_ch_list_all || freq_range_list_includes(
&hapd->iface->conf->acs_ch_list, chan->chan)) &&
if ((acs_ch_list_all ||
freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
chan->chan)) &&
!(chan->flag & HOSTAPD_CHAN_DISABLED))
int_array_add_unique(freq_list, chan->freq);
}
}
void hostapd_get_ext_capa(struct hostapd_iface *iface) {
void hostapd_get_ext_capa(struct hostapd_iface *iface)
{
struct hostapd_data *hapd = iface->bss[0];
if (!hapd->driver || !hapd->driver->get_ext_capab)
return;
hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
&iface->extended_capa, &iface->extended_capa_mask,
&iface->extended_capa,
&iface->extended_capa_mask,
&iface->extended_capa_len);
}
int hostapd_drv_do_acs(struct hostapd_data *hapd) {
int hostapd_drv_do_acs(struct hostapd_data *hapd)
{
struct drv_acs_params params;
int ret, i, acs_ch_list_all = 0;
u8 *channels = NULL;
@@ -699,8 +824,10 @@ int hostapd_drv_do_acs(struct hostapd_data *hapd) {
for (i = 0; i < mode->num_channels; i++) {
struct hostapd_channel_data *chan = &mode->channels[i];
if (!acs_ch_list_all && !freq_range_list_includes(
&hapd->iface->conf->acs_ch_list, chan->chan))
if (!acs_ch_list_all &&
!freq_range_list_includes(
&hapd->iface->conf->acs_ch_list,
chan->chan))
continue;
if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
channels[num_channels++] = chan->chan;
@@ -710,7 +837,9 @@ int hostapd_drv_do_acs(struct hostapd_data *hapd) {
} else {
for (i = 0; i < hapd->iface->num_hw_features; i++) {
mode = &hapd->iface->hw_features[i];
hostapd_get_hw_mode_any_channels(hapd, mode, acs_ch_list_all, &freq_list);
hostapd_get_hw_mode_any_channels(hapd, mode,
acs_ch_list_all,
&freq_list);
}
}
@@ -719,8 +848,8 @@ int hostapd_drv_do_acs(struct hostapd_data *hapd) {
params.freq_list = freq_list;
params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
params.ht40_enabled =
!!(hapd->iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
params.ch_width = 20;
if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
@@ -731,8 +860,10 @@ int hostapd_drv_do_acs(struct hostapd_data *hapd) {
if (hapd->iface->conf->ieee80211ac && params.ht40_enabled) {
if (hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
params.ch_width = 80;
else if (hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_160MHZ ||
hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_80P80MHZ)
else if (hapd->iface->conf->vht_oper_chwidth ==
VHT_CHANWIDTH_160MHZ ||
hapd->iface->conf->vht_oper_chwidth ==
VHT_CHANWIDTH_80P80MHZ)
params.ch_width = 160;
}
@@ -26,8 +26,8 @@ void hostapd_free_ap_extra_ies(struct hostapd_data *hapd, struct wpabuf *beacon,
struct wpabuf *assocresp);
int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd);
int hostapd_set_ap_wps_ie(struct hostapd_data *hapd);
int hostapd_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
int authorized);
int hostapd_set_authorized(struct hostapd_data *hapd,
struct sta_info *sta, int authorized);
int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta);
int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
int enabled);
@@ -35,8 +35,9 @@ int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname);
int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname);
int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
const u8 *addr, int aid, int val);
int hostapd_sta_add(struct hostapd_data *hapd, const u8 *addr, u16 aid,
u16 capability, const u8 *supp_rates, size_t supp_rates_len,
int hostapd_sta_add(struct hostapd_data *hapd,
const u8 *addr, u16 aid, u16 capability,
const u8 *supp_rates, size_t supp_rates_len,
u16 listen_interval,
const struct ieee80211_ht_capabilities *ht_capab,
const struct ieee80211_vht_capabilities *vht_capab,
@@ -64,60 +65,65 @@ int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
int center_segment0, int center_segment1);
int hostapd_set_rts(struct hostapd_data *hapd, int rts);
int hostapd_set_frag(struct hostapd_data *hapd, int frag);
int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr, int total_flags,
int flags_or, int flags_and);
int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
int total_flags, int flags_or, int flags_and);
int hostapd_set_country(struct hostapd_data *hapd, const char *country);
int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
int cw_min, int cw_max, int burst_time);
struct hostapd_hw_modes *hostapd_get_hw_feature_data(struct hostapd_data *hapd,
u16 *num_modes,
struct hostapd_hw_modes *
hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
u16 *flags);
int hostapd_driver_commit(struct hostapd_data *hapd);
int hostapd_drv_none(struct hostapd_data *hapd);
int hostapd_driver_scan(struct hostapd_data *hapd,
struct wpa_driver_scan_params *params);
struct wpa_scan_results *
hostapd_driver_get_scan_results(struct hostapd_data *hapd);
struct wpa_scan_results * hostapd_driver_get_scan_results(
struct hostapd_data *hapd);
int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
int duration);
int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
enum wpa_alg alg, const u8 *addr, int key_idx,
int set_tx, const u8 *seq, size_t seq_len,
int hostapd_drv_set_key(const char *ifname,
struct hostapd_data *hapd,
enum wpa_alg alg, const u8 *addr,
int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len);
int hostapd_drv_send_mlme(struct hostapd_data *hapd, const void *msg,
size_t len, int noack);
int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd, const void *msg,
size_t len, int noack, const u16 *csa_offs,
size_t csa_offs_len);
int hostapd_drv_sta_deauth(struct hostapd_data *hapd, const u8 *addr,
int reason);
int hostapd_drv_sta_disassoc(struct hostapd_data *hapd, const u8 *addr,
int reason);
int hostapd_drv_send_mlme(struct hostapd_data *hapd,
const void *msg, size_t len, int noack);
int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
const void *msg, size_t len, int noack,
const u16 *csa_offs, size_t csa_offs_len);
int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
const u8 *addr, int reason);
int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
const u8 *addr, int reason);
int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
unsigned int wait, const u8 *dst, const u8 *data,
size_t len);
int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
unsigned int freq, unsigned int wait,
const u8 *dst, const u8 *data, size_t len);
unsigned int freq,
unsigned int wait, const u8 *dst,
const u8 *data, size_t len);
int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
u16 auth_alg);
int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr, u16 seq,
u16 status, const u8 *ie, size_t len);
int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr, int reassoc,
u16 status, const u8 *ie, size_t len);
int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr, u8 *tspec_ie,
size_t tspec_ielen);
int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
u16 seq, u16 status, const u8 *ie, size_t len);
int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
int reassoc, u16 status, const u8 *ie, size_t len);
int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
u8 *tspec_ie, size_t tspec_ielen);
int hostapd_start_dfs_cac(struct hostapd_iface *iface,
enum hostapd_hw_mode mode, int freq, int channel,
int ht_enabled, int vht_enabled,
enum hostapd_hw_mode mode, int freq,
int channel, int ht_enabled, int vht_enabled,
int sec_channel_offset, int vht_oper_chwidth,
int center_segment0, int center_segment1);
int hostapd_drv_do_acs(struct hostapd_data *hapd);
#include "drivers/driver.h"
int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
const u8 *peer, u8 *buf, u16 *buf_len);
int hostapd_drv_wnm_oper(struct hostapd_data *hapd,
enum wnm_oper oper, const u8 *peer,
u8 *buf, u16 *buf_len);
int hostapd_drv_set_qos_map(struct hostapd_data *hapd, const u8 *qos_map_set,
u8 qos_map_set_len);
@@ -125,29 +131,35 @@ int hostapd_drv_set_qos_map(struct hostapd_data *hapd, const u8 *qos_map_set,
void hostapd_get_ext_capa(struct hostapd_iface *iface);
static inline int hostapd_drv_set_countermeasures(struct hostapd_data *hapd,
int enabled) {
if (hapd->driver == NULL || hapd->driver->hapd_set_countermeasures == NULL)
int enabled)
{
if (hapd->driver == NULL ||
hapd->driver->hapd_set_countermeasures == NULL)
return 0;
return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
}
static inline int hostapd_drv_set_sta_vlan(const char *ifname,
struct hostapd_data *hapd,
const u8 *addr, int vlan_id) {
const u8 *addr, int vlan_id)
{
if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
return 0;
return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname,
vlan_id);
}
static inline int hostapd_drv_get_inact_sec(struct hostapd_data *hapd,
const u8 *addr) {
const u8 *addr)
{
if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
return 0;
return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
}
static inline int hostapd_drv_sta_remove(struct hostapd_data *hapd,
const u8 *addr) {
const u8 *addr)
{
if (!hapd->driver || !hapd->driver->sta_remove || !hapd->drv_priv)
return 0;
return hapd->driver->sta_remove(hapd->drv_priv, addr);
@@ -156,37 +168,43 @@ static inline int hostapd_drv_sta_remove(struct hostapd_data *hapd,
static inline int hostapd_drv_hapd_send_eapol(struct hostapd_data *hapd,
const u8 *addr, const u8 *data,
size_t data_len, int encrypt,
u32 flags) {
u32 flags)
{
if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
return 0;
return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data, data_len,
encrypt, hapd->own_addr, flags);
return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
data_len, encrypt,
hapd->own_addr, flags);
}
static inline int hostapd_drv_read_sta_data(struct hostapd_data *hapd,
struct hostap_sta_driver_data *data,
const u8 *addr) {
static inline int hostapd_drv_read_sta_data(
struct hostapd_data *hapd, struct hostap_sta_driver_data *data,
const u8 *addr)
{
if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
return -1;
return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
}
static inline int hostapd_drv_sta_clear_stats(struct hostapd_data *hapd,
const u8 *addr) {
const u8 *addr)
{
if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
return 0;
return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
}
static inline int hostapd_drv_set_acl(struct hostapd_data *hapd,
struct hostapd_acl_params *params) {
struct hostapd_acl_params *params)
{
if (hapd->driver == NULL || hapd->driver->set_acl == NULL)
return 0;
return hapd->driver->set_acl(hapd->drv_priv, params);
}
static inline int hostapd_drv_set_ap(struct hostapd_data *hapd,
struct wpa_driver_ap_params *params) {
struct wpa_driver_ap_params *params)
{
if (hapd->driver == NULL || hapd->driver->set_ap == NULL)
return 0;
return hapd->driver->set_ap(hapd->drv_priv, params);
@@ -194,7 +212,8 @@ static inline int hostapd_drv_set_ap(struct hostapd_data *hapd,
static inline int hostapd_drv_set_radius_acl_auth(struct hostapd_data *hapd,
const u8 *mac, int accepted,
u32 session_timeout) {
u32 session_timeout)
{
if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
return 0;
return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
@@ -202,14 +221,17 @@ static inline int hostapd_drv_set_radius_acl_auth(struct hostapd_data *hapd,
}
static inline int hostapd_drv_set_radius_acl_expire(struct hostapd_data *hapd,
const u8 *mac) {
if (hapd->driver == NULL || hapd->driver->set_radius_acl_expire == NULL)
const u8 *mac)
{
if (hapd->driver == NULL ||
hapd->driver->set_radius_acl_expire == NULL)
return 0;
return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
}
static inline int hostapd_drv_set_authmode(struct hostapd_data *hapd,
int auth_algs) {
int auth_algs)
{
if (hapd->driver == NULL || hapd->driver->set_authmode == NULL)
return 0;
return hapd->driver->set_authmode(hapd->drv_priv, auth_algs);
@@ -217,14 +239,16 @@ static inline int hostapd_drv_set_authmode(struct hostapd_data *hapd,
static inline void hostapd_drv_poll_client(struct hostapd_data *hapd,
const u8 *own_addr, const u8 *addr,
int qos) {
int qos)
{
if (hapd->driver == NULL || hapd->driver->poll_client == NULL)
return;
hapd->driver->poll_client(hapd->drv_priv, own_addr, addr, qos);
}
static inline int hostapd_drv_get_survey(struct hostapd_data *hapd,
unsigned int freq) {
unsigned int freq)
{
if (hapd->driver == NULL)
return -1;
if (!hapd->driver->get_survey)
@@ -232,14 +256,15 @@ static inline int hostapd_drv_get_survey(struct hostapd_data *hapd,
return hapd->driver->get_survey(hapd->drv_priv, freq);
}
static inline int hostapd_get_country(struct hostapd_data *hapd, char *alpha2) {
static inline int hostapd_get_country(struct hostapd_data *hapd, char *alpha2)
{
if (hapd->driver == NULL || hapd->driver->get_country == NULL)
return -1;
return hapd->driver->get_country(hapd->drv_priv, alpha2);
}
static inline const char *
hostapd_drv_get_radio_name(struct hostapd_data *hapd) {
static inline const char * hostapd_drv_get_radio_name(struct hostapd_data *hapd)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->get_radio_name == NULL)
return NULL;
@@ -247,7 +272,8 @@ hostapd_drv_get_radio_name(struct hostapd_data *hapd) {
}
static inline int hostapd_drv_switch_channel(struct hostapd_data *hapd,
struct csa_settings *settings) {
struct csa_settings *settings)
{
if (hapd->driver == NULL || hapd->driver->switch_channel == NULL)
return -ENOTSUP;
@@ -255,7 +281,8 @@ static inline int hostapd_drv_switch_channel(struct hostapd_data *hapd,
}
static inline int hostapd_drv_status(struct hostapd_data *hapd, char *buf,
size_t buflen) {
size_t buflen)
{
if (!hapd->driver || !hapd->driver->status || !hapd->drv_priv)
return -1;
return hapd->driver->status(hapd->drv_priv, buf, buflen);
@@ -263,7 +290,8 @@ static inline int hostapd_drv_status(struct hostapd_data *hapd, char *buf,
static inline int hostapd_drv_br_add_ip_neigh(struct hostapd_data *hapd,
int version, const u8 *ipaddr,
int prefixlen, const u8 *addr) {
int prefixlen, const u8 *addr)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->br_add_ip_neigh == NULL)
return -1;
@@ -272,16 +300,19 @@ static inline int hostapd_drv_br_add_ip_neigh(struct hostapd_data *hapd,
}
static inline int hostapd_drv_br_delete_ip_neigh(struct hostapd_data *hapd,
u8 version, const u8 *ipaddr) {
u8 version, const u8 *ipaddr)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->br_delete_ip_neigh == NULL)
return -1;
return hapd->driver->br_delete_ip_neigh(hapd->drv_priv, version, ipaddr);
return hapd->driver->br_delete_ip_neigh(hapd->drv_priv, version,
ipaddr);
}
static inline int hostapd_drv_br_port_set_attr(struct hostapd_data *hapd,
enum drv_br_port_attr attr,
unsigned int val) {
unsigned int val)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->br_port_set_attr == NULL)
return -1;
@@ -290,7 +321,8 @@ static inline int hostapd_drv_br_port_set_attr(struct hostapd_data *hapd,
static inline int hostapd_drv_br_set_net_param(struct hostapd_data *hapd,
enum drv_br_net_param param,
unsigned int val) {
unsigned int val)
{
if (hapd->driver == NULL || hapd->drv_priv == NULL ||
hapd->driver->br_set_net_param == NULL)
return -1;
@@ -300,14 +332,16 @@ static inline int hostapd_drv_br_set_net_param(struct hostapd_data *hapd,
static inline int hostapd_drv_vendor_cmd(struct hostapd_data *hapd,
int vendor_id, int subcmd,
const u8 *data, size_t data_len,
struct wpabuf *buf) {
struct wpabuf *buf)
{
if (hapd->driver == NULL || hapd->driver->vendor_cmd == NULL)
return -1;
return hapd->driver->vendor_cmd(hapd->drv_priv, vendor_id, subcmd, data,
data_len, buf);
}
static inline int hostapd_drv_stop_ap(struct hostapd_data *hapd) {
static inline int hostapd_drv_stop_ap(struct hostapd_data *hapd)
{
if (!hapd->driver || !hapd->driver->stop_ap || !hapd->drv_priv)
return 0;
return hapd->driver->stop_ap(hapd->drv_priv);
@@ -10,24 +10,26 @@
#include "utils/includes.h"
#include "ap_config.h"
#include "ap_list.h"
#include "beacon.h"
#include "common/ieee802_11_common.h"
#include "common/ieee802_11_defs.h"
#include "hostapd.h"
#include "ieee802_11.h"
#include "sta_info.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "common/ieee802_11_defs.h"
#include "common/ieee802_11_common.h"
#include "hostapd.h"
#include "ap_config.h"
#include "ieee802_11.h"
#include "sta_info.h"
#include "beacon.h"
#include "ap_list.h"
/* AP list is a double linked list with head->prev pointing to the end of the
* list and tail->next = NULL. Entries are moved to the head of the list
* whenever a beacon has been received from the AP in question. The tail entry
* in this link will thus be the least recently used entry. */
static int ap_list_beacon_olbc(struct hostapd_iface *iface,
struct ap_info *ap) {
static int ap_list_beacon_olbc(struct hostapd_iface *iface, struct ap_info *ap)
{
int i;
if (iface->current_mode == NULL ||
@@ -47,7 +49,9 @@ static int ap_list_beacon_olbc(struct hostapd_iface *iface,
return 1;
}
static struct ap_info *ap_get_ap(struct hostapd_iface *iface, const u8 *ap) {
static struct ap_info * ap_get_ap(struct hostapd_iface *iface, const u8 *ap)
{
struct ap_info *s;
s = iface->ap_hash[STA_HASH(ap)];
@@ -56,7 +60,9 @@ static struct ap_info *ap_get_ap(struct hostapd_iface *iface, const u8 *ap) {
return s;
}
static void ap_ap_list_add(struct hostapd_iface *iface, struct ap_info *ap) {
static void ap_ap_list_add(struct hostapd_iface *iface, struct ap_info *ap)
{
if (iface->ap_list) {
ap->prev = iface->ap_list->prev;
iface->ap_list->prev = ap;
@@ -66,7 +72,9 @@ static void ap_ap_list_add(struct hostapd_iface *iface, struct ap_info *ap) {
iface->ap_list = ap;
}
static void ap_ap_list_del(struct hostapd_iface *iface, struct ap_info *ap) {
static void ap_ap_list_del(struct hostapd_iface *iface, struct ap_info *ap)
{
if (iface->ap_list == ap)
iface->ap_list = ap->next;
else
@@ -78,32 +86,38 @@ static void ap_ap_list_del(struct hostapd_iface *iface, struct ap_info *ap) {
iface->ap_list->prev = ap->prev;
}
static void ap_ap_hash_add(struct hostapd_iface *iface, struct ap_info *ap) {
static void ap_ap_hash_add(struct hostapd_iface *iface, struct ap_info *ap)
{
ap->hnext = iface->ap_hash[STA_HASH(ap->addr)];
iface->ap_hash[STA_HASH(ap->addr)] = ap;
}
static void ap_ap_hash_del(struct hostapd_iface *iface, struct ap_info *ap) {
static void ap_ap_hash_del(struct hostapd_iface *iface, struct ap_info *ap)
{
struct ap_info *s;
s = iface->ap_hash[STA_HASH(ap->addr)];
if (s == NULL)
return;
if (s == NULL) return;
if (os_memcmp(s->addr, ap->addr, ETH_ALEN) == 0) {
iface->ap_hash[STA_HASH(ap->addr)] = s->hnext;
return;
}
while (s->hnext != NULL && os_memcmp(s->hnext->addr, ap->addr, ETH_ALEN) != 0)
while (s->hnext != NULL &&
os_memcmp(s->hnext->addr, ap->addr, ETH_ALEN) != 0)
s = s->hnext;
if (s->hnext != NULL)
s->hnext = s->hnext->hnext;
else
wpa_printf(MSG_INFO, "AP: could not remove AP " MACSTR " from hash table",
MAC2STR(ap->addr));
wpa_printf(MSG_INFO, "AP: could not remove AP " MACSTR
" from hash table", MAC2STR(ap->addr));
}
static void ap_free_ap(struct hostapd_iface *iface, struct ap_info *ap) {
static void ap_free_ap(struct hostapd_iface *iface, struct ap_info *ap)
{
ap_ap_hash_del(iface, ap);
ap_ap_list_del(iface, ap);
@@ -111,7 +125,9 @@ static void ap_free_ap(struct hostapd_iface *iface, struct ap_info *ap) {
os_free(ap);
}
static void hostapd_free_aps(struct hostapd_iface *iface) {
static void hostapd_free_aps(struct hostapd_iface *iface)
{
struct ap_info *ap, *prev;
ap = iface->ap_list;
@@ -125,7 +141,9 @@ static void hostapd_free_aps(struct hostapd_iface *iface) {
iface->ap_list = NULL;
}
static struct ap_info *ap_ap_add(struct hostapd_iface *iface, const u8 *addr) {
static struct ap_info * ap_ap_add(struct hostapd_iface *iface, const u8 *addr)
{
struct ap_info *ap;
ap = os_zalloc(sizeof(struct ap_info));
@@ -139,19 +157,20 @@ static struct ap_info *ap_ap_add(struct hostapd_iface *iface, const u8 *addr) {
ap_ap_hash_add(iface, ap);
if (iface->num_ap > iface->conf->ap_table_max_size && ap != ap->prev) {
wpa_printf(MSG_DEBUG,
"Removing the least recently used AP " MACSTR " from AP table",
MAC2STR(ap->prev->addr));
wpa_printf(MSG_DEBUG, "Removing the least recently used AP "
MACSTR " from AP table", MAC2STR(ap->prev->addr));
ap_free_ap(iface, ap->prev);
}
return ap;
}
void ap_list_process_beacon(struct hostapd_iface *iface,
const struct ieee80211_mgmt *mgmt,
struct ieee802_11_elems *elems,
struct hostapd_frame_info *fi) {
struct hostapd_frame_info *fi)
{
struct ap_info *ap;
int new_ap = 0;
int set_beacon = 0;
@@ -163,15 +182,16 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
if (!ap) {
ap = ap_ap_add(iface, mgmt->bssid);
if (!ap) {
wpa_printf(MSG_INFO, "Failed to allocate AP information entry");
wpa_printf(MSG_INFO,
"Failed to allocate AP information entry");
return;
}
new_ap = 1;
}
merge_byte_arrays(ap->supported_rates, WLAN_SUPP_RATES_MAX, elems->supp_rates,
elems->supp_rates_len, elems->ext_supp_rates,
elems->ext_supp_rates_len);
merge_byte_arrays(ap->supported_rates, WLAN_SUPP_RATES_MAX,
elems->supp_rates, elems->supp_rates_len,
elems->ext_supp_rates, elems->ext_supp_rates_len);
if (elems->erp_info)
ap->erp = elems->erp_info[0];
@@ -199,23 +219,24 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
ap_ap_list_add(iface, ap);
}
if (!iface->olbc && ap_list_beacon_olbc(iface, ap)) {
if (!iface->olbc &&
ap_list_beacon_olbc(iface, ap)) {
iface->olbc = 1;
wpa_printf(MSG_DEBUG,
"OLBC AP detected: " MACSTR " (channel %d) - enable protection",
wpa_printf(MSG_DEBUG, "OLBC AP detected: " MACSTR
" (channel %d) - enable protection",
MAC2STR(ap->addr), ap->channel);
set_beacon++;
}
#ifdef CONFIG_IEEE80211N
if (!iface->olbc_ht && !ap->ht_support &&
(ap->channel == 0 || ap->channel == iface->conf->channel ||
ap->channel ==
iface->conf->channel + iface->conf->secondary_channel * 4)) {
(ap->channel == 0 ||
ap->channel == iface->conf->channel ||
ap->channel == iface->conf->channel +
iface->conf->secondary_channel * 4)) {
iface->olbc_ht = 1;
hostapd_ht_operation_update(iface);
wpa_printf(MSG_DEBUG,
"OLBC HT AP detected: " MACSTR
wpa_printf(MSG_DEBUG, "OLBC HT AP detected: " MACSTR
" (channel %d) - enable protection",
MAC2STR(ap->addr), ap->channel);
set_beacon++;
@@ -226,7 +247,9 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
ieee802_11_update_beacons(iface);
}
void ap_list_timer(struct hostapd_iface *iface) {
void ap_list_timer(struct hostapd_iface *iface)
{
struct os_reltime now;
struct ap_info *ap;
int set_beacon = 0;
@@ -276,6 +299,14 @@ void ap_list_timer(struct hostapd_iface *iface) {
ieee802_11_update_beacons(iface);
}
int ap_list_init(struct hostapd_iface *iface) { return 0; }
void ap_list_deinit(struct hostapd_iface *iface) { hostapd_free_aps(iface); }
int ap_list_init(struct hostapd_iface *iface)
{
return 0;
}
void ap_list_deinit(struct hostapd_iface *iface)
{
hostapd_free_aps(iface);
}
@@ -41,11 +41,18 @@ int ap_list_init(struct hostapd_iface *iface);
void ap_list_deinit(struct hostapd_iface *iface);
void ap_list_timer(struct hostapd_iface *iface);
#else /* NEED_AP_MLME */
static inline int ap_list_init(struct hostapd_iface *iface) { return 0; }
static inline int ap_list_init(struct hostapd_iface *iface)
{
return 0;
}
static inline void ap_list_deinit(struct hostapd_iface *iface) {}
static inline void ap_list_deinit(struct hostapd_iface *iface)
{
}
static inline void ap_list_timer(struct hostapd_iface *iface) {}
static inline void ap_list_timer(struct hostapd_iface *iface)
{
}
#endif /* NEED_AP_MLME */
#endif /* AP_LIST_H */
@@ -10,16 +10,18 @@
#include "utils/includes.h"
#include "ap_mlme.h"
#include "common/ieee802_11_defs.h"
#include "hostapd.h"
#include "ieee802_11.h"
#include "sta_info.h"
#include "utils/common.h"
#include "common/ieee802_11_defs.h"
#include "ieee802_11.h"
#include "wpa_auth.h"
#include "sta_info.h"
#include "ap_mlme.h"
#include "hostapd.h"
#ifndef CONFIG_NO_HOSTAPD_LOGGER
static const char *mlme_auth_alg_str(int alg) {
static const char * mlme_auth_alg_str(int alg)
{
switch (alg) {
case WLAN_AUTH_OPEN:
return "OPEN_SYSTEM";
@@ -33,6 +35,7 @@ static const char *mlme_auth_alg_str(int alg) {
}
#endif /* CONFIG_NO_HOSTAPD_LOGGER */
/**
* mlme_authenticate_indication - Report the establishment of an authentication
* relationship with a specific peer MAC entity
@@ -48,8 +51,10 @@ static const char *mlme_auth_alg_str(int alg) {
* AuthenticationType = sta->auth_alg (WLAN_AUTH_OPEN / WLAN_AUTH_SHARED_KEY)
*/
void mlme_authenticate_indication(struct hostapd_data *hapd,
struct sta_info *sta) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
struct sta_info *sta)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-AUTHENTICATE.indication(" MACSTR ", %s)",
MAC2STR(sta->addr), mlme_auth_alg_str(sta->auth_alg));
if (sta->auth_alg != WLAN_AUTH_FT && !(sta->flags & WLAN_STA_MFP))
@@ -57,6 +62,7 @@ void mlme_authenticate_indication(struct hostapd_data *hapd,
ap_sta_clear_disconnect_timeouts(hapd, sta);
}
/**
* mlme_deauthenticate_indication - Report the invalidation of an
* authentication relationship with a specific peer MAC entity
@@ -70,14 +76,17 @@ void mlme_authenticate_indication(struct hostapd_data *hapd,
* PeerSTAAddress = sta->addr
*/
void mlme_deauthenticate_indication(struct hostapd_data *hapd,
struct sta_info *sta, u16 reason_code) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
struct sta_info *sta, u16 reason_code)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-DEAUTHENTICATE.indication(" MACSTR ", %d)",
MAC2STR(sta->addr), reason_code);
if (!hapd->iface->driver_ap_teardown)
mlme_deletekeys_request(hapd, sta);
}
/**
* mlme_associate_indication - Report the establishment of an association with
* a specific peer MAC entity
@@ -90,15 +99,18 @@ void mlme_deauthenticate_indication(struct hostapd_data *hapd,
*
* PeerSTAAddress = sta->addr
*/
void mlme_associate_indication(struct hostapd_data *hapd,
struct sta_info *sta) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
"MLME-ASSOCIATE.indication(" MACSTR ")", MAC2STR(sta->addr));
void mlme_associate_indication(struct hostapd_data *hapd, struct sta_info *sta)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-ASSOCIATE.indication(" MACSTR ")",
MAC2STR(sta->addr));
if (sta->auth_alg != WLAN_AUTH_FT)
mlme_deletekeys_request(hapd, sta);
ap_sta_clear_disconnect_timeouts(hapd, sta);
}
/**
* mlme_reassociate_indication - Report the establishment of an reassociation
* with a specific peer MAC entity
@@ -112,14 +124,18 @@ void mlme_associate_indication(struct hostapd_data *hapd,
* PeerSTAAddress = sta->addr
*/
void mlme_reassociate_indication(struct hostapd_data *hapd,
struct sta_info *sta) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
"MLME-REASSOCIATE.indication(" MACSTR ")", MAC2STR(sta->addr));
struct sta_info *sta)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-REASSOCIATE.indication(" MACSTR ")",
MAC2STR(sta->addr));
if (sta->auth_alg != WLAN_AUTH_FT)
mlme_deletekeys_request(hapd, sta);
ap_sta_clear_disconnect_timeouts(hapd, sta);
}
/**
* mlme_disassociate_indication - Report disassociation with a specific peer
* MAC entity
@@ -133,23 +149,32 @@ void mlme_reassociate_indication(struct hostapd_data *hapd,
* PeerSTAAddress = sta->addr
*/
void mlme_disassociate_indication(struct hostapd_data *hapd,
struct sta_info *sta, u16 reason_code) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
struct sta_info *sta, u16 reason_code)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-DISASSOCIATE.indication(" MACSTR ", %d)",
MAC2STR(sta->addr), reason_code);
mlme_deletekeys_request(hapd, sta);
}
void mlme_michaelmicfailure_indication(struct hostapd_data *hapd,
const u8 *addr) {
hostapd_logger(hapd, addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
const u8 *addr)
{
hostapd_logger(hapd, addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-MichaelMICFailure.indication(" MACSTR ")",
MAC2STR(addr));
}
void mlme_deletekeys_request(struct hostapd_data *hapd, struct sta_info *sta) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME, HOSTAPD_LEVEL_DEBUG,
"MLME-DELETEKEYS.request(" MACSTR ")", MAC2STR(sta->addr));
void mlme_deletekeys_request(struct hostapd_data *hapd, struct sta_info *sta)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
HOSTAPD_LEVEL_DEBUG,
"MLME-DELETEKEYS.request(" MACSTR ")",
MAC2STR(sta->addr));
if (sta->wpa_sm)
wpa_remove_ptk(sta->wpa_sm);
@@ -17,7 +17,8 @@ void mlme_authenticate_indication(struct hostapd_data *hapd,
void mlme_deauthenticate_indication(struct hostapd_data *hapd,
struct sta_info *sta, u16 reason_code);
void mlme_associate_indication(struct hostapd_data *hapd, struct sta_info *sta);
void mlme_associate_indication(struct hostapd_data *hapd,
struct sta_info *sta);
void mlme_reassociate_indication(struct hostapd_data *hapd,
struct sta_info *sta);
@@ -8,30 +8,35 @@
#include "utils/includes.h"
#include "ap_config.h"
#include "authsrv.h"
#include "utils/common.h"
#include "crypto/tls.h"
#include "eap_server/eap.h"
#include "eap_server/eap_sim_db.h"
#include "eapol_auth/eapol_auth_sm.h"
#include "hostapd.h"
#include "radius/radius_server.h"
#include "hostapd.h"
#include "ap_config.h"
#include "sta_info.h"
#include "utils/common.h"
#include "authsrv.h"
#if defined(EAP_SERVER_SIM) || defined(EAP_SERVER_AKA)
#define EAP_SIM_DB
#endif /* EAP_SERVER_SIM || EAP_SERVER_AKA */
#ifdef EAP_SIM_DB
static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
struct sta_info *sta, void *ctx) {
struct sta_info *sta, void *ctx)
{
if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
return 1;
return 0;
}
static void hostapd_sim_db_cb(void *ctx, void *session_ctx) {
static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
{
struct hostapd_data *hapd = ctx;
if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0) {
#ifdef RADIUS_SERVER
@@ -41,11 +46,13 @@ static void hostapd_sim_db_cb(void *ctx, void *session_ctx) {
}
#endif /* EAP_SIM_DB */
#ifdef RADIUS_SERVER
static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
size_t identity_len, int phase2,
struct eap_user *user) {
struct eap_user *user)
{
const struct hostapd_eap_user *eap_user;
int i;
int rv = -1;
@@ -67,7 +74,8 @@ static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
user->password = os_malloc(eap_user->password_len);
if (user->password == NULL)
goto out;
os_memcpy(user->password, eap_user->password, eap_user->password_len);
os_memcpy(user->password, eap_user->password,
eap_user->password_len);
user->password_len = eap_user->password_len;
user->password_hash = eap_user->password_hash;
}
@@ -85,7 +93,9 @@ out:
return rv;
}
static int hostapd_setup_radius_srv(struct hostapd_data *hapd) {
static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
{
struct radius_server_conf srv;
struct hostapd_bss_config *conf = hapd->conf;
os_memset(&srv, 0, sizeof(srv));
@@ -135,7 +145,9 @@ static int hostapd_setup_radius_srv(struct hostapd_data *hapd) {
#endif /* RADIUS_SERVER */
int authsrv_init(struct hostapd_data *hapd) {
int authsrv_init(struct hostapd_data *hapd)
{
#ifdef EAP_TLS_FUNCS
if (hapd->conf->eap_server &&
(hapd->conf->ca_cert || hapd->conf->server_cert ||
@@ -159,7 +171,8 @@ int authsrv_init(struct hostapd_data *hapd) {
params.private_key_passwd = hapd->conf->private_key_passwd;
params.dh_file = hapd->conf->dh_file;
params.openssl_ciphers = hapd->conf->openssl_ciphers;
params.ocsp_stapling_response = hapd->conf->ocsp_stapling_response;
params.ocsp_stapling_response =
hapd->conf->ocsp_stapling_response;
params.ocsp_stapling_response_multi =
hapd->conf->ocsp_stapling_response_multi;
@@ -169,7 +182,8 @@ int authsrv_init(struct hostapd_data *hapd) {
return -1;
}
if (tls_global_set_verify(hapd->ssl_ctx, hapd->conf->check_crl)) {
if (tls_global_set_verify(hapd->ssl_ctx,
hapd->conf->check_crl)) {
wpa_printf(MSG_ERROR, "Failed to enable check_crl");
authsrv_deinit(hapd);
return -1;
@@ -180,7 +194,8 @@ int authsrv_init(struct hostapd_data *hapd) {
#ifdef EAP_SIM_DB
if (hapd->conf->eap_sim_db) {
hapd->eap_sim_db_priv =
eap_sim_db_init(hapd->conf->eap_sim_db, hapd->conf->eap_sim_db_timeout,
eap_sim_db_init(hapd->conf->eap_sim_db,
hapd->conf->eap_sim_db_timeout,
hostapd_sim_db_cb, hapd);
if (hapd->eap_sim_db_priv == NULL) {
wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
@@ -192,14 +207,17 @@ int authsrv_init(struct hostapd_data *hapd) {
#endif /* EAP_SIM_DB */
#ifdef RADIUS_SERVER
if (hapd->conf->radius_server_clients && hostapd_setup_radius_srv(hapd))
if (hapd->conf->radius_server_clients &&
hostapd_setup_radius_srv(hapd))
return -1;
#endif /* RADIUS_SERVER */
return 0;
}
void authsrv_deinit(struct hostapd_data *hapd) {
void authsrv_deinit(struct hostapd_data *hapd)
{
#ifdef RADIUS_SERVER
radius_server_deinit(hapd->radius_srv);
hapd->radius_srv = NULL;
+228 -140
View File
@@ -12,29 +12,31 @@
#ifndef CONFIG_NATIVE_WINDOWS
#include "utils/common.h"
#include "common/ieee802_11_defs.h"
#include "common/ieee802_11_common.h"
#include "common/hw_features_common.h"
#include "wps/wps_defs.h"
#include "p2p/p2p.h"
#include "hostapd.h"
#include "ieee802_11.h"
#include "wpa_auth.h"
#include "wmm.h"
#include "ap_config.h"
#include "sta_info.h"
#include "p2p_hostapd.h"
#include "ap_drv_ops.h"
#include "beacon.h"
#include "common/hw_features_common.h"
#include "common/ieee802_11_common.h"
#include "common/ieee802_11_defs.h"
#include "dfs.h"
#include "hostapd.h"
#include "hs20.h"
#include "ieee802_11.h"
#include "p2p/p2p.h"
#include "p2p_hostapd.h"
#include "sta_info.h"
#include "dfs.h"
#include "taxonomy.h"
#include "utils/common.h"
#include "wmm.h"
#include "wpa_auth.h"
#include "wps/wps_defs.h"
#ifdef NEED_AP_MLME
static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
size_t len) {
size_t len)
{
size_t i;
for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
@@ -52,8 +54,9 @@ static u8 *hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
return eid + RRM_CAPABILITIES_IE_LEN;
}
static u8 *hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid,
size_t len) {
static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
{
if (len < 2 + 5)
return eid;
@@ -78,7 +81,9 @@ static u8 *hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid,
return eid;
}
static u8 ieee802_11_erp_info(struct hostapd_data *hapd) {
static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
{
u8 erp = 0;
if (hapd->iface->current_mode == NULL ||
@@ -88,7 +93,8 @@ static u8 ieee802_11_erp_info(struct hostapd_data *hapd) {
if (hapd->iface->olbc)
erp |= ERP_INFO_USE_PROTECTION;
if (hapd->iface->num_sta_non_erp > 0) {
erp |= ERP_INFO_NON_ERP_PRESENT | ERP_INFO_USE_PROTECTION;
erp |= ERP_INFO_NON_ERP_PRESENT |
ERP_INFO_USE_PROTECTION;
}
if (hapd->iface->num_sta_no_short_preamble > 0 ||
hapd->iconf->preamble == LONG_PREAMBLE)
@@ -97,14 +103,18 @@ static u8 ieee802_11_erp_info(struct hostapd_data *hapd) {
return erp;
}
static u8 *hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid) {
static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
{
*eid++ = WLAN_EID_DS_PARAMS;
*eid++ = 1;
*eid++ = hapd->iconf->channel;
return eid;
}
static u8 *hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid) {
static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
{
if (hapd->iface->current_mode == NULL ||
hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
return eid;
@@ -126,7 +136,9 @@ static u8 *hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid) {
return eid;
}
static u8 *hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) {
static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
{
u8 *pos = eid;
u8 local_pwr_constraint = 0;
int dfs;
@@ -143,13 +155,15 @@ static u8 *hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) {
* There is no DFS support and power constraint was not directly
* requested by config option.
*/
if (!hapd->iconf->ieee80211h && hapd->iconf->local_pwr_constraint == -1)
if (!hapd->iconf->ieee80211h &&
hapd->iconf->local_pwr_constraint == -1)
return eid;
/* Check if DFS is required by regulatory. */
dfs = hostapd_is_dfs_required(hapd->iface);
if (dfs < 0) {
wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", dfs);
wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
dfs);
dfs = 0;
}
@@ -190,9 +204,11 @@ static u8 *hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) {
return pos;
}
static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
struct hostapd_channel_data *start,
struct hostapd_channel_data *prev) {
struct hostapd_channel_data *prev)
{
if (end - pos < 3)
return pos;
@@ -206,8 +222,10 @@ static u8 *hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
return pos;
}
static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
int max_len) {
int max_len)
{
u8 *pos = eid;
u8 *end = eid + max_len;
int i;
@@ -233,14 +251,16 @@ static u8 *hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
struct hostapd_channel_data *chan = &mode->channels[i];
if (chan->flag & HOSTAPD_CHAN_DISABLED)
continue;
if (start && prev && prev->chan + chan_spacing == chan->chan &&
if (start && prev &&
prev->chan + chan_spacing == chan->chan &&
start->max_tx_power == chan->max_tx_power) {
prev = chan;
continue; /* can use same entry */
}
if (start && prev) {
pos = hostapd_eid_country_add(pos, end, chan_spacing, start, prev);
pos = hostapd_eid_country_add(pos, end, chan_spacing,
start, prev);
start = NULL;
}
@@ -249,7 +269,8 @@ static u8 *hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
}
if (start) {
pos = hostapd_eid_country_add(pos, end, chan_spacing, start, prev);
pos = hostapd_eid_country_add(pos, end, chan_spacing,
start, prev);
}
if ((pos - eid) & 1) {
@@ -263,7 +284,9 @@ static u8 *hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
return pos;
}
static u8 *hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len) {
static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
{
const u8 *ie;
size_t ielen;
@@ -275,7 +298,9 @@ static u8 *hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len) {
return eid + ielen;
}
static u8 *hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) {
static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
{
#ifdef CONFIG_TESTING_OPTIONS
if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
return eid;
@@ -293,7 +318,9 @@ static u8 *hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) {
return eid;
}
static u8 *hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) {
static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
{
if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
return eid;
@@ -307,17 +334,20 @@ static u8 *hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) {
return eid;
}
static u8 *hostapd_eid_supported_op_classes(struct hostapd_data *hapd,
u8 *eid) {
static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
{
u8 op_class, channel;
if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || !hapd->iface->freq)
if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
!hapd->iface->freq)
return eid;
if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
hapd->iconf->secondary_channel,
hapd->iconf->vht_oper_chwidth, &op_class,
&channel) == NUM_HOSTAPD_MODES)
hapd->iconf->vht_oper_chwidth,
&op_class, &channel) ==
NUM_HOSTAPD_MODES)
return eid;
*eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
@@ -332,9 +362,11 @@ static u8 *hostapd_eid_supported_op_classes(struct hostapd_data *hapd,
return eid;
}
static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
const struct ieee80211_mgmt *req, int is_p2p,
size_t *resp_len) {
const struct ieee80211_mgmt *req,
int is_p2p, size_t *resp_len)
{
struct ieee80211_mgmt *resp;
u8 *pos, *epos, *csa_pos;
size_t buflen;
@@ -356,8 +388,8 @@ static u8 *hostapd_gen_probe_resp(struct hostapd_data *hapd,
if (hapd->conf->vendor_elements)
buflen += wpabuf_len(hapd->conf->vendor_elements);
if (hapd->conf->vendor_vht) {
buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + 2 +
sizeof(struct ieee80211_vht_operation);
buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
2 + sizeof(struct ieee80211_vht_operation);
}
buflen += hostapd_mbo_ie_len(hapd);
@@ -368,17 +400,19 @@ static u8 *hostapd_gen_probe_resp(struct hostapd_data *hapd,
epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
resp->frame_control =
IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_PROBE_RESP);
resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
WLAN_FC_STYPE_PROBE_RESP);
if (req)
os_memcpy(resp->da, req->sa, ETH_ALEN);
os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
resp->u.probe_resp.beacon_int = host_to_le16(hapd->iconf->beacon_int);
resp->u.probe_resp.beacon_int =
host_to_le16(hapd->iconf->beacon_int);
/* hardware or low-level driver will setup seq_ctrl and timestamp */
resp->u.probe_resp.capab_info = host_to_le16(hostapd_own_capab_info(hapd));
resp->u.probe_resp.capab_info =
host_to_le16(hostapd_own_capab_info(hapd));
pos = resp->u.probe_resp.variable;
*pos++ = WLAN_EID_SSID;
@@ -473,7 +507,8 @@ static u8 *hostapd_gen_probe_resp(struct hostapd_data *hapd,
#endif /* CONFIG_WPS */
#ifdef CONFIG_P2P
if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && hapd->p2p_probe_resp_ie) {
if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
hapd->p2p_probe_resp_ie) {
os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
wpabuf_len(hapd->p2p_probe_resp_ie));
pos += wpabuf_len(hapd->p2p_probe_resp_ie);
@@ -502,12 +537,18 @@ static u8 *hostapd_gen_probe_resp(struct hostapd_data *hapd,
return (u8 *) resp;
}
enum ssid_match_result { NO_SSID_MATCH, EXACT_SSID_MATCH, WILDCARD_SSID_MATCH };
enum ssid_match_result {
NO_SSID_MATCH,
EXACT_SSID_MATCH,
WILDCARD_SSID_MATCH
};
static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
const u8 *ssid, size_t ssid_len,
const u8 *ssid_list,
size_t ssid_list_len) {
size_t ssid_list_len)
{
const u8 *pos, *end;
int wildcard = 0;
@@ -536,7 +577,9 @@ static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
}
void sta_track_expire(struct hostapd_iface *iface, int force) {
void sta_track_expire(struct hostapd_iface *iface, int force)
{
struct os_reltime now;
struct hostapd_sta_info *info;
@@ -544,33 +587,39 @@ void sta_track_expire(struct hostapd_iface *iface, int force) {
return;
os_get_reltime(&now);
while (
(info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, list))) {
if (!force && !os_reltime_expired(&now, &info->last_seen,
while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
list))) {
if (!force &&
!os_reltime_expired(&now, &info->last_seen,
iface->conf->track_sta_max_age))
break;
force = 0;
wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " MACSTR,
iface->bss[0]->conf->iface, MAC2STR(info->addr));
wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
MACSTR, iface->bss[0]->conf->iface,
MAC2STR(info->addr));
dl_list_del(&info->list);
iface->num_sta_seen--;
sta_track_del(info);
}
}
static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
const u8 *addr) {
const u8 *addr)
{
struct hostapd_sta_info *info;
dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info,
list) if (os_memcmp(addr, info->addr, ETH_ALEN) ==
0) return info;
dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
return info;
return NULL;
}
void sta_track_add(struct hostapd_iface *iface, const u8 *addr) {
void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
{
struct hostapd_sta_info *info;
info = sta_track_get(iface, addr);
@@ -594,14 +643,17 @@ void sta_track_add(struct hostapd_iface *iface, const u8 *addr) {
sta_track_expire(iface, 1);
}
wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " MACSTR,
iface->bss[0]->conf->iface, MAC2STR(addr));
wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
dl_list_add_tail(&iface->sta_seen, &info->list);
iface->num_sta_seen++;
}
struct hostapd_data *sta_track_seen_on(struct hostapd_iface *iface,
const u8 *addr, const char *ifname) {
struct hostapd_data *
sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
const char *ifname)
{
struct hapd_interfaces *interfaces = iface->interfaces;
size_t i, j;
@@ -623,9 +675,11 @@ struct hostapd_data *sta_track_seen_on(struct hostapd_iface *iface,
return NULL;
}
#ifdef CONFIG_TAXONOMY
void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
struct wpabuf **probe_ie_taxonomy) {
struct wpabuf **probe_ie_taxonomy)
{
struct hostapd_sta_info *info;
info = sta_track_get(iface, addr);
@@ -638,9 +692,11 @@ void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
}
#endif /* CONFIG_TAXONOMY */
void handle_probe_req(struct hostapd_data *hapd,
const struct ieee80211_mgmt *mgmt, size_t len,
int ssi_signal) {
int ssi_signal)
{
u8 *resp;
struct ieee802_11_elems elems;
const u8 *ie;
@@ -660,8 +716,9 @@ void handle_probe_req(struct hostapd_data *hapd,
ie_len = len - IEEE80211_HDRLEN;
for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, mgmt->sa, mgmt->da,
mgmt->bssid, ie, ie_len, ssi_signal) > 0)
if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
mgmt->sa, mgmt->da, mgmt->bssid,
ie, ie_len, ssi_signal) > 0)
return;
if (!hapd->iconf->send_probe_response)
@@ -674,8 +731,7 @@ void handle_probe_req(struct hostapd_data *hapd,
}
if ((!elems.ssid || !elems.supp_rates)) {
wpa_printf(MSG_DEBUG,
"STA " MACSTR " sent probe request "
wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
"without SSID or supported rates element",
MAC2STR(mgmt->sa));
return;
@@ -691,12 +747,12 @@ void handle_probe_req(struct hostapd_data *hapd,
* is less likely to see them (Probe Request frame sent on a
* neighboring, but partially overlapping, channel).
*/
if (elems.ds_params && hapd->iface->current_mode &&
if (elems.ds_params &&
hapd->iface->current_mode &&
(hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
hapd->iconf->channel != elems.ds_params[0]) {
wpa_printf(
MSG_DEBUG,
wpa_printf(MSG_DEBUG,
"Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
hapd->iconf->channel, elems.ds_params[0]);
return;
@@ -731,17 +787,16 @@ void handle_probe_req(struct hostapd_data *hapd,
if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
elems.ssid_list_len == 0) {
wpa_printf(MSG_MSGDUMP,
"Probe Request from " MACSTR " for "
"broadcast SSID ignored",
MAC2STR(mgmt->sa));
wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
"broadcast SSID ignored", MAC2STR(mgmt->sa));
return;
}
#ifdef CONFIG_P2P
if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
os_memcmp(elems.ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == 0) {
os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
P2P_WILDCARD_SSID_LEN) == 0) {
/* Process P2P Wildcard SSID like Wildcard SSID */
elems.ssid_len = 0;
}
@@ -754,33 +809,36 @@ void handle_probe_req(struct hostapd_data *hapd,
if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
} else if ((info = sta_track_get(hapd->iface, mgmt->sa)) != NULL) {
taxonomy_hostapd_sta_info_probe_req(hapd, info, ie, ie_len);
} else if ((info = sta_track_get(hapd->iface,
mgmt->sa)) != NULL) {
taxonomy_hostapd_sta_info_probe_req(hapd, info,
ie, ie_len);
}
}
#endif /* CONFIG_TAXONOMY */
res = ssid_match(hapd, elems.ssid, elems.ssid_len, elems.ssid_list,
elems.ssid_list_len);
res = ssid_match(hapd, elems.ssid, elems.ssid_len,
elems.ssid_list, elems.ssid_list_len);
if (res == NO_SSID_MATCH) {
if (!(mgmt->da[0] & 0x01)) {
wpa_printf(MSG_MSGDUMP,
"Probe Request from " MACSTR
wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
" for foreign SSID '%s' (DA " MACSTR ")%s",
MAC2STR(mgmt->sa), wpa_ssid_txt(elems.ssid, elems.ssid_len),
MAC2STR(mgmt->da), elems.ssid_list ? " (SSID list)" : "");
MAC2STR(mgmt->sa),
wpa_ssid_txt(elems.ssid, elems.ssid_len),
MAC2STR(mgmt->da),
elems.ssid_list ? " (SSID list)" : "");
}
return;
}
#ifdef CONFIG_INTERWORKING
if (hapd->conf->interworking && elems.interworking &&
elems.interworking_len >= 1) {
if (hapd->conf->interworking &&
elems.interworking && elems.interworking_len >= 1) {
u8 ant = elems.interworking[0] & 0x0f;
if (ant != INTERWORKING_ANT_WILDCARD &&
ant != hapd->conf->access_network_type) {
wpa_printf(MSG_MSGDUMP,
"Probe Request from " MACSTR " for mismatching ANT %u ignored",
wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
" for mismatching ANT %u ignored",
MAC2STR(mgmt->sa), ant);
return;
}
@@ -795,8 +853,8 @@ void handle_probe_req(struct hostapd_data *hapd,
hessid = elems.interworking + 1 + 2;
if (!is_broadcast_ether_addr(hessid) &&
os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
wpa_printf(MSG_MSGDUMP,
"Probe Request from " MACSTR " for mismatching HESSID " MACSTR
wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
" for mismatching HESSID " MACSTR
" ignored",
MAC2STR(mgmt->sa), MAC2STR(hessid));
return;
@@ -805,11 +863,11 @@ void handle_probe_req(struct hostapd_data *hapd,
#endif /* CONFIG_INTERWORKING */
#ifdef CONFIG_P2P
if ((hapd->conf->p2p & P2P_GROUP_OWNER) && supp_rates_11b_only(&elems)) {
if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
supp_rates_11b_only(&elems)) {
/* Indicates support for 11b rates only */
wpa_printf(MSG_EXCESSIVE,
"P2P: Ignore Probe Request from " MACSTR
" with only 802.11b rates",
wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
MACSTR " with only 802.11b rates",
MAC2STR(mgmt->sa));
return;
}
@@ -823,8 +881,7 @@ void handle_probe_req(struct hostapd_data *hapd,
is_multicast_ether_addr(mgmt->bssid) &&
sta_track_seen_on(hapd->iface, mgmt->sa,
hapd->conf->no_probe_resp_if_seen_on)) {
wpa_printf(MSG_MSGDUMP,
"%s: Ignore Probe Request from " MACSTR
wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
" since STA has been seen on %s",
hapd->conf->iface, MAC2STR(mgmt->sa),
hapd->conf->no_probe_resp_if_seen_on);
@@ -834,9 +891,9 @@ void handle_probe_req(struct hostapd_data *hapd,
if (hapd->conf->no_probe_resp_if_max_sta &&
is_multicast_ether_addr(mgmt->da) &&
is_multicast_ether_addr(mgmt->bssid) &&
hapd->num_sta >= hapd->conf->max_num_sta && !ap_get_sta(hapd, mgmt->sa)) {
wpa_printf(MSG_MSGDUMP,
"%s: Ignore Probe Request from " MACSTR
hapd->num_sta >= hapd->conf->max_num_sta &&
!ap_get_sta(hapd, mgmt->sa)) {
wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
" since no room for additional STA",
hapd->conf->iface, MAC2STR(mgmt->sa));
return;
@@ -845,13 +902,15 @@ void handle_probe_req(struct hostapd_data *hapd,
#ifdef CONFIG_TESTING_OPTIONS
if (hapd->iconf->ignore_probe_probability > 0.0 &&
drand48() < hapd->iconf->ignore_probe_probability) {
wpa_printf(MSG_INFO, "TESTING: ignoring probe request from " MACSTR,
wpa_printf(MSG_INFO,
"TESTING: ignoring probe request from " MACSTR,
MAC2STR(mgmt->sa));
return;
}
#endif /* CONFIG_TESTING_OPTIONS */
resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, &resp_len);
resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
&resp_len);
if (resp == NULL)
return;
@@ -859,33 +918,38 @@ void handle_probe_req(struct hostapd_data *hapd,
* If this is a broadcast probe request, apply no ack policy to avoid
* excessive retries.
*/
noack = !!(res == WILDCARD_SSID_MATCH && is_broadcast_ether_addr(mgmt->da));
noack = !!(res == WILDCARD_SSID_MATCH &&
is_broadcast_ether_addr(mgmt->da));
csa_offs_len = 0;
if (hapd->csa_in_progress) {
if (hapd->cs_c_off_proberesp)
csa_offs[csa_offs_len++] = hapd->cs_c_off_proberesp;
csa_offs[csa_offs_len++] =
hapd->cs_c_off_proberesp;
if (hapd->cs_c_off_ecsa_proberesp)
csa_offs[csa_offs_len++] = hapd->cs_c_off_ecsa_proberesp;
csa_offs[csa_offs_len++] =
hapd->cs_c_off_ecsa_proberesp;
}
ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
csa_offs_len ? csa_offs : NULL, csa_offs_len);
csa_offs_len ? csa_offs : NULL,
csa_offs_len);
if (ret < 0)
wpa_printf(MSG_INFO, "handle_probe_req: send failed");
os_free(resp);
wpa_printf(MSG_EXCESSIVE,
"STA " MACSTR " sent probe request for %s "
"SSID",
MAC2STR(mgmt->sa), elems.ssid_len == 0 ? "broadcast" : "our");
wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
"SSID", MAC2STR(mgmt->sa),
elems.ssid_len == 0 ? "broadcast" : "our");
}
static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
size_t *resp_len) {
size_t *resp_len)
{
/* check probe response offloading caps and print warnings */
if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
return NULL;
@@ -901,12 +965,14 @@ static u8 *hostapd_probe_resp_offloads(struct hostapd_data *hapd,
#ifdef CONFIG_P2P
if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
!(hapd->iface->probe_resp_offloads & WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
!(hapd->iface->probe_resp_offloads &
WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
"Probe Response while not supporting this");
#endif /* CONFIG_P2P */
if (hapd->conf->interworking && !(hapd->iface->probe_resp_offloads &
if (hapd->conf->interworking &&
!(hapd->iface->probe_resp_offloads &
WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
wpa_printf(MSG_WARNING, "Device is trying to offload "
"Interworking Probe Response while not supporting "
@@ -918,7 +984,9 @@ static u8 *hostapd_probe_resp_offloads(struct hostapd_data *hapd,
#endif /* NEED_AP_MLME */
void sta_track_del(struct hostapd_sta_info *info) {
void sta_track_del(struct hostapd_sta_info *info)
{
#ifdef CONFIG_TAXONOMY
wpabuf_free(info->probe_ie_taxonomy);
info->probe_ie_taxonomy = NULL;
@@ -926,8 +994,10 @@ void sta_track_del(struct hostapd_sta_info *info) {
os_free(info);
}
int ieee802_11_build_ap_params(struct hostapd_data *hapd,
struct wpa_driver_ap_params *params) {
struct wpa_driver_ap_params *params)
{
struct ieee80211_mgmt *head = NULL;
u8 *tail = NULL;
size_t head_len = 0, tail_len = 0;
@@ -958,8 +1028,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
#ifdef CONFIG_IEEE80211AC
if (hapd->conf->vendor_vht) {
tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + 2 +
sizeof(struct ieee80211_vht_operation);
tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
2 + sizeof(struct ieee80211_vht_operation);
}
#endif /* CONFIG_IEEE80211AC */
@@ -973,13 +1043,15 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
return -1;
}
head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_BEACON);
head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
WLAN_FC_STYPE_BEACON);
head->duration = host_to_le16(0);
os_memset(head->da, 0xff, ETH_ALEN);
os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
head->u.beacon.beacon_int = host_to_le16(hapd->iconf->beacon_int);
head->u.beacon.beacon_int =
host_to_le16(hapd->iconf->beacon_int);
/* hardware or low-level driver will setup seq_ctrl and timestamp */
capab_info = hostapd_own_capab_info(hapd);
@@ -997,7 +1069,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
*pos++ = 0; /* empty SSID */
} else {
*pos++ = hapd->conf->ssid.ssid_len;
os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
os_memcpy(pos, hapd->conf->ssid.ssid,
hapd->conf->ssid.ssid_len);
pos += hapd->conf->ssid.ssid_len;
}
@@ -1009,8 +1082,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
head_len = pos - (u8 *) head;
tailpos =
hostapd_eid_country(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - tailpos);
tailpos = hostapd_eid_country(hapd, tailpos,
tail + BEACON_TAIL_BUF_SIZE - tailpos);
/* Power Constraint element */
tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
@@ -1028,11 +1101,12 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
/* RSN, MDIE, WPA */
tailpos =
hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - tailpos);
tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
tailpos);
tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
tail + BEACON_TAIL_BUF_SIZE - tailpos);
tail + BEACON_TAIL_BUF_SIZE -
tailpos);
tailpos = hostapd_eid_bss_load(hapd, tailpos,
tail + BEACON_TAIL_BUF_SIZE - tailpos);
@@ -1141,8 +1215,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
params->ssid_len = hapd->conf->ssid.ssid_len;
if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
(WPA_PROTO_WPA | WPA_PROTO_RSN))
params->pairwise_ciphers =
hapd->conf->wpa_pairwise | hapd->conf->rsn_pairwise;
params->pairwise_ciphers = hapd->conf->wpa_pairwise |
hapd->conf->rsn_pairwise;
else if (hapd->conf->wpa & WPA_PROTO_RSN)
params->pairwise_ciphers = hapd->conf->rsn_pairwise;
else if (hapd->conf->wpa & WPA_PROTO_WPA)
@@ -1151,10 +1225,10 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
params->auth_algs = hapd->conf->auth_algs;
params->wpa_version = hapd->conf->wpa;
params->privacy =
hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
(hapd->conf->ieee802_1x &&
(hapd->conf->default_wep_key_len || hapd->conf->individual_wep_key_len));
(hapd->conf->default_wep_key_len ||
hapd->conf->individual_wep_key_len));
switch (hapd->conf->ignore_broadcast_ssid) {
case 0:
params->hide_ssid = NO_SSID_HIDING;
@@ -1169,7 +1243,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
params->isolate = hapd->conf->isolate;
params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
#ifdef NEED_AP_MLME
params->cts_protect = !!(ieee802_11_erp_info(hapd) & ERP_INFO_USE_PROTECTION);
params->cts_protect = !!(ieee802_11_erp_info(hapd) &
ERP_INFO_USE_PROTECTION);
params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
hapd->iconf->preamble == SHORT_PREAMBLE;
if (hapd->iface->current_mode &&
@@ -1184,7 +1259,8 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
params->ht_opmode = hapd->iface->ht_op_mode;
#endif /* NEED_AP_MLME */
params->interworking = hapd->conf->interworking;
if (hapd->conf->interworking && !is_zero_ether_addr(hapd->conf->hessid))
if (hapd->conf->interworking &&
!is_zero_ether_addr(hapd->conf->hessid))
params->hessid = hapd->conf->hessid;
params->access_network_type = hapd->conf->access_network_type;
params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
@@ -1202,7 +1278,9 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
return 0;
}
void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) {
void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
{
os_free(params->tail);
params->tail = NULL;
os_free(params->head);
@@ -1211,7 +1289,9 @@ void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) {
params->proberesp = NULL;
}
int ieee802_11_set_beacon(struct hostapd_data *hapd) {
int ieee802_11_set_beacon(struct hostapd_data *hapd)
{
struct wpa_driver_ap_params params;
struct hostapd_freq_params freq;
struct hostapd_iface *iface = hapd->iface;
@@ -1229,7 +1309,8 @@ int ieee802_11_set_beacon(struct hostapd_data *hapd) {
if (ieee802_11_build_ap_params(hapd, &params) < 0)
return -1;
if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 0)
if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
0)
goto fail;
params.beacon_ies = beacon;
@@ -1239,9 +1320,11 @@ int ieee802_11_set_beacon(struct hostapd_data *hapd) {
hapd->reenable_beacon = 0;
if (iface->current_mode &&
hostapd_set_freq_params(
&freq, iconf->hw_mode, iface->freq, iconf->channel, iconf->ieee80211n,
iconf->ieee80211ac, iconf->secondary_channel, iconf->vht_oper_chwidth,
hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
iconf->channel, iconf->ieee80211n,
iconf->ieee80211ac,
iconf->secondary_channel,
iconf->vht_oper_chwidth,
iconf->vht_oper_centr_freq_seg0_idx,
iconf->vht_oper_centr_freq_seg1_idx,
iface->current_mode->vht_capab) == 0)
@@ -1258,20 +1341,25 @@ fail:
return ret;
}
int ieee802_11_set_beacons(struct hostapd_iface *iface) {
int ieee802_11_set_beacons(struct hostapd_iface *iface)
{
size_t i;
int ret = 0;
for (i = 0; i < iface->num_bss; i++) {
if (iface->bss[i]->started && ieee802_11_set_beacon(iface->bss[i]) < 0)
if (iface->bss[i]->started &&
ieee802_11_set_beacon(iface->bss[i]) < 0)
ret = -1;
}
return ret;
}
/* only update beacons if started */
int ieee802_11_update_beacons(struct hostapd_iface *iface) {
int ieee802_11_update_beacons(struct hostapd_iface *iface)
{
size_t i;
int ret = 0;
@@ -24,8 +24,9 @@ void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params);
void sta_track_add(struct hostapd_iface *iface, const u8 *addr);
void sta_track_del(struct hostapd_sta_info *info);
void sta_track_expire(struct hostapd_iface *iface, int force);
struct hostapd_data *sta_track_seen_on(struct hostapd_iface *iface,
const u8 *addr, const char *ifname);
struct hostapd_data *
sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
const char *ifname);
void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
struct wpabuf **probe_ie_taxonomy);
@@ -8,14 +8,16 @@
#include "utils/includes.h"
#include "ap_drv_ops.h"
#include "beacon.h"
#include "bss_load.h"
#include "hostapd.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "hostapd.h"
#include "bss_load.h"
#include "ap_drv_ops.h"
#include "beacon.h"
static void update_channel_utilization(void *eloop_data, void *user_data) {
static void update_channel_utilization(void *eloop_data, void *user_data)
{
struct hostapd_data *hapd = eloop_data;
unsigned int sec, usec;
int err;
@@ -33,10 +35,13 @@ static void update_channel_utilization(void *eloop_data, void *user_data) {
sec = ((hapd->bss_load_update_timeout / 1000) * 1024) / 1000;
usec = (hapd->bss_load_update_timeout % 1000) * 1024;
eloop_register_timeout(sec, usec, update_channel_utilization, hapd, NULL);
eloop_register_timeout(sec, usec, update_channel_utilization, hapd,
NULL);
}
int bss_load_update_init(struct hostapd_data *hapd) {
int bss_load_update_init(struct hostapd_data *hapd)
{
struct hostapd_bss_config *conf = hapd->conf;
struct hostapd_config *iconf = hapd->iconf;
unsigned int sec, usec;
@@ -44,14 +49,17 @@ int bss_load_update_init(struct hostapd_data *hapd) {
if (!conf->bss_load_update_period || !iconf->beacon_int)
return -1;
hapd->bss_load_update_timeout =
conf->bss_load_update_period * iconf->beacon_int;
hapd->bss_load_update_timeout = conf->bss_load_update_period *
iconf->beacon_int;
sec = ((hapd->bss_load_update_timeout / 1000) * 1024) / 1000;
usec = (hapd->bss_load_update_timeout % 1000) * 1024;
eloop_register_timeout(sec, usec, update_channel_utilization, hapd, NULL);
eloop_register_timeout(sec, usec, update_channel_utilization, hapd,
NULL);
return 0;
}
void bss_load_update_deinit(struct hostapd_data *hapd) {
void bss_load_update_deinit(struct hostapd_data *hapd)
{
eloop_cancel_timeout(update_channel_utilization, hapd, NULL);
}
@@ -9,7 +9,9 @@
#ifndef BSS_LOAD_UPDATE_H
#define BSS_LOAD_UPDATE_H
int bss_load_update_init(struct hostapd_data *hapd);
void bss_load_update_deinit(struct hostapd_data *hapd);
#endif /* BSS_LOAD_UPDATE_H */
@@ -8,44 +8,47 @@
#include "utils/includes.h"
#include "ap_drv_ops.h"
#include "utils/common.h"
#include "common/ieee802_11_defs.h"
#include "common/sae.h"
#include "ctrl_iface_ap.h"
#include "eapol_auth/eapol_auth_sm.h"
#include "fst/fst_ctrl_iface.h"
#include "hostapd.h"
#include "ieee802_11.h"
#include "ieee802_1x.h"
#include "mbo_ap.h"
#include "p2p_hostapd.h"
#include "sta_info.h"
#include "taxonomy.h"
#include "utils/common.h"
#include "wpa_auth.h"
#include "ieee802_11.h"
#include "sta_info.h"
#include "wps_hostapd.h"
#include "p2p_hostapd.h"
#include "ctrl_iface_ap.h"
#include "ap_drv_ops.h"
#include "mbo_ap.h"
#include "taxonomy.h"
static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
struct sta_info *sta, char *buf,
size_t buflen) {
struct sta_info *sta,
char *buf, size_t buflen)
{
struct hostap_sta_driver_data data;
int ret;
if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
return 0;
ret = os_snprintf(buf, buflen,
"rx_packets=%lu\ntx_packets=%lu\n"
ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n"
"rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n",
data.rx_packets, data.tx_packets, data.rx_bytes,
data.tx_bytes, data.inactive_msec);
data.rx_packets, data.tx_packets,
data.rx_bytes, data.tx_bytes, data.inactive_msec);
if (os_snprintf_error(buflen, ret))
return 0;
return ret;
}
static int hostapd_get_sta_conn_time(struct sta_info *sta, char *buf,
size_t buflen) {
static int hostapd_get_sta_conn_time(struct sta_info *sta,
char *buf, size_t buflen)
{
struct os_reltime age;
int ret;
@@ -54,13 +57,16 @@ static int hostapd_get_sta_conn_time(struct sta_info *sta, char *buf,
os_reltime_age(&sta->connected_time, &age);
ret = os_snprintf(buf, buflen, "connected_time=%u\n", (unsigned int)age.sec);
ret = os_snprintf(buf, buflen, "connected_time=%u\n",
(unsigned int) age.sec);
if (os_snprintf_error(buflen, ret))
return 0;
return ret;
}
static const char *timeout_next_str(int val) {
static const char * timeout_next_str(int val)
{
switch (val) {
case STA_NULLFUNC:
return "NULLFUNC POLL";
@@ -77,17 +83,19 @@ static const char *timeout_next_str(int val) {
return "?";
}
static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
struct sta_info *sta, char *buf,
size_t buflen) {
struct sta_info *sta,
char *buf, size_t buflen)
{
int len, res, ret, i;
if (!sta)
return 0;
len = 0;
ret = os_snprintf(buf + len, buflen - len,
MACSTR "\nflags=", MAC2STR(sta->addr));
ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
MAC2STR(sta->addr));
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
@@ -97,8 +105,7 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
return len;
len += ret;
ret = os_snprintf(buf + len, buflen - len,
"\naid=%d\ncapability=0x%x\n"
ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
"listen_interval=%d\nsupported_rates=",
sta->aid, sta->capability, sta->listen_interval);
if (os_snprintf_error(buflen - len, ret))
@@ -106,8 +113,8 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
len += ret;
for (i = 0; i < sta->supported_rates_len; i++) {
ret =
os_snprintf(buf + len, buflen - len, "%02x%s", sta->supported_rates[i],
ret = os_snprintf(buf + len, buflen - len, "%02x%s",
sta->supported_rates[i],
i + 1 < sta->supported_rates_len ? " " : "");
if (os_snprintf_error(buflen - len, ret))
return len;
@@ -129,7 +136,8 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
if (res >= 0)
len += res;
res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len, buflen - len);
res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
buflen - len);
if (res >= 0)
len += res;
res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len);
@@ -141,15 +149,16 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
#ifdef CONFIG_SAE
if (sta->sae && sta->sae->state == SAE_ACCEPTED) {
res =
os_snprintf(buf + len, buflen - len, "sae_group=%d\n", sta->sae->group);
res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n",
sta->sae->group);
if (!os_snprintf_error(buflen - len, res))
len += res;
}
#endif /* CONFIG_SAE */
if (sta->vlan_id > 0) {
res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n", sta->vlan_id);
res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n",
sta->vlan_id);
if (!os_snprintf_error(buflen - len, res))
len += res;
}
@@ -161,7 +170,8 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
if (sta->supp_op_classes &&
buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) {
len += os_snprintf(buf + len, buflen - len, "supp_op_classes=");
len += wpa_snprintf_hex(buf + len, buflen - len, sta->supp_op_classes + 1,
len += wpa_snprintf_hex(buf + len, buflen - len,
sta->supp_op_classes + 1,
sta->supp_op_classes[0]);
len += os_snprintf(buf + len, buflen - len, "\n");
}
@@ -169,13 +179,17 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
return len;
}
int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd, char *buf,
size_t buflen) {
int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
char *buf, size_t buflen)
{
return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
}
int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
char *buf, size_t buflen) {
char *buf, size_t buflen)
{
u8 addr[ETH_ALEN];
int ret;
const char *pos;
@@ -200,7 +214,8 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
if (os_strcmp(pos, "eapol") == 0) {
if (sta->eapol_sm == NULL)
return -1;
return eapol_auth_dump_state(sta->eapol_sm, buf, buflen);
return eapol_auth_dump_state(sta->eapol_sm, buf,
buflen);
}
#endif /* HOSTAPD_DUMP_STATE */
@@ -213,13 +228,16 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
return ret;
}
int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
char *buf, size_t buflen) {
char *buf, size_t buflen)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
int ret;
if (hwaddr_aton(txtaddr, addr) || (sta = ap_get_sta(hapd, addr)) == NULL) {
if (hwaddr_aton(txtaddr, addr) ||
(sta = ap_get_sta(hapd, addr)) == NULL) {
ret = os_snprintf(buf, buflen, "FAIL\n");
if (os_snprintf_error(buflen, ret))
return 0;
@@ -232,9 +250,11 @@ int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
}
#ifdef CONFIG_P2P_MANAGER
static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
u8 minor_reason_code, const u8 *addr) {
u8 minor_reason_code, const u8 *addr)
{
struct ieee80211_mgmt *mgmt;
int ret;
u8 *pos;
@@ -247,8 +267,7 @@ static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
return -1;
mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
"P2P: Disconnect STA " MACSTR
wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR
" with minor reason code %u (stype=%u (%s))",
MAC2STR(addr), minor_reason_code, stype,
fc2str(le_to_host16(mgmt->frame_control)));
@@ -257,7 +276,8 @@ static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
if (stype == WLAN_FC_STYPE_DEAUTH) {
mgmt->u.deauth.reason_code = host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
mgmt->u.deauth.reason_code =
host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
pos = (u8 *) (&mgmt->u.deauth.reason_code + 1);
} else {
mgmt->u.disassoc.reason_code =
@@ -275,22 +295,25 @@ static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
pos += 2;
*pos++ = minor_reason_code;
ret =
hapd->driver->send_frame(hapd->drv_priv, (u8 *)mgmt, pos - (u8 *)mgmt, 1);
ret = hapd->driver->send_frame(hapd->drv_priv, (u8 *) mgmt,
pos - (u8 *) mgmt, 1);
os_free(mgmt);
return ret < 0 ? -1 : 0;
}
#endif /* CONFIG_P2P_MANAGER */
int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
const char *txtaddr) {
const char *txtaddr)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
const char *pos;
u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s", txtaddr);
wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s",
txtaddr);
if (hwaddr_aton(txtaddr, addr))
return -1;
@@ -308,13 +331,15 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
pos += 6;
encrypt = atoi(pos);
os_memset(&mgmt, 0, sizeof(mgmt));
mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
WLAN_FC_STYPE_DEAUTH);
os_memcpy(mgmt.da, addr, ETH_ALEN);
os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
mgmt.u.deauth.reason_code = host_to_le16(reason);
if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
IEEE80211_HDRLEN + sizeof(mgmt.u.deauth),
IEEE80211_HDRLEN +
sizeof(mgmt.u.deauth),
encrypt) < 0)
return -1;
return 0;
@@ -323,8 +348,8 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
#ifdef CONFIG_P2P_MANAGER
pos = os_strstr(txtaddr, " p2p=");
if (pos) {
return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH, atoi(pos + 5),
addr);
return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH,
atoi(pos + 5), addr);
}
#endif /* CONFIG_P2P_MANAGER */
@@ -341,14 +366,17 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
return 0;
}
int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
const char *txtaddr) {
const char *txtaddr)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
const char *pos;
u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s", txtaddr);
wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s",
txtaddr);
if (hwaddr_aton(txtaddr, addr))
return -1;
@@ -366,14 +394,15 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
pos += 6;
encrypt = atoi(pos);
os_memset(&mgmt, 0, sizeof(mgmt));
mgmt.frame_control =
IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DISASSOC);
mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
WLAN_FC_STYPE_DISASSOC);
os_memcpy(mgmt.da, addr, ETH_ALEN);
os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
mgmt.u.disassoc.reason_code = host_to_le16(reason);
if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
IEEE80211_HDRLEN + sizeof(mgmt.u.deauth),
IEEE80211_HDRLEN +
sizeof(mgmt.u.deauth),
encrypt) < 0)
return -1;
return 0;
@@ -382,8 +411,8 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
#ifdef CONFIG_P2P_MANAGER
pos = os_strstr(txtaddr, " p2p=");
if (pos) {
return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC, atoi(pos + 5),
addr);
return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC,
atoi(pos + 5), addr);
}
#endif /* CONFIG_P2P_MANAGER */
@@ -400,9 +429,12 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
return 0;
}
#ifdef CONFIG_TAXONOMY
int hostapd_ctrl_iface_signature(struct hostapd_data *hapd, const char *txtaddr,
char *buf, size_t buflen) {
int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
const char *txtaddr,
char *buf, size_t buflen)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
@@ -419,8 +451,10 @@ int hostapd_ctrl_iface_signature(struct hostapd_data *hapd, const char *txtaddr,
}
#endif /* CONFIG_TAXONOMY */
int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
const char *txtaddr) {
const char *txtaddr)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
@@ -438,8 +472,10 @@ int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
return 0;
}
int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
size_t buflen) {
size_t buflen)
{
struct hostapd_iface *iface = hapd->iface;
int len = 0, ret;
size_t i;
@@ -458,12 +494,19 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
"num_sta_ht40_intolerant=%d\n"
"olbc_ht=%d\n"
"ht_op_mode=0x%x\n",
hostapd_state_text(iface->state), iface->phy, iface->freq,
iface->num_sta_non_erp, iface->num_sta_no_short_slot_time,
iface->num_sta_no_short_preamble, iface->olbc,
iface->num_sta_ht_no_gf, iface->num_sta_no_ht,
iface->num_sta_ht_20mhz, iface->num_sta_ht40_intolerant,
iface->olbc_ht, iface->ht_op_mode);
hostapd_state_text(iface->state),
iface->phy,
iface->freq,
iface->num_sta_non_erp,
iface->num_sta_no_short_slot_time,
iface->num_sta_no_short_preamble,
iface->olbc,
iface->num_sta_ht_no_gf,
iface->num_sta_no_ht,
iface->num_sta_ht_20mhz,
iface->num_sta_ht40_intolerant,
iface->olbc_ht,
iface->ht_op_mode);
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
@@ -483,7 +526,8 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
ret = os_snprintf(buf + len, buflen - len,
"cac_time_seconds=%u\n"
"cac_time_left_seconds=%u\n",
iface->dfs_cac_ms / 1000, left_time);
iface->dfs_cac_ms / 1000,
left_time);
}
if (os_snprintf_error(buflen - len, ret))
return len;
@@ -495,11 +539,11 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
"ieee80211n=%d\n"
"ieee80211ac=%d\n",
iface->conf->channel,
iface->conf->ieee80211n && !hapd->conf->disable_11n
? iface->conf->secondary_channel
: 0,
iface->conf->ieee80211n && !hapd->conf->disable_11n ?
iface->conf->secondary_channel : 0,
iface->conf->ieee80211n && !hapd->conf->disable_11n,
iface->conf->ieee80211ac && !hapd->conf->disable_11ac);
iface->conf->ieee80211ac &&
!hapd->conf->disable_11ac);
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
@@ -518,15 +562,17 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
for (i = 0; i < iface->num_bss; i++) {
struct hostapd_data *bss = iface->bss[i];
ret = os_snprintf(
buf + len, buflen - len,
ret = os_snprintf(buf + len, buflen - len,
"bss[%d]=%s\n"
"bssid[%d]=" MACSTR "\n"
"ssid[%d]=%s\n"
"num_sta[%d]=%d\n",
(int)i, bss->conf->iface, (int)i, MAC2STR(bss->own_addr), (int)i,
wpa_ssid_txt(bss->conf->ssid.ssid, bss->conf->ssid.ssid_len), (int)i,
bss->num_sta);
(int) i, bss->conf->iface,
(int) i, MAC2STR(bss->own_addr),
(int) i,
wpa_ssid_txt(bss->conf->ssid.ssid,
bss->conf->ssid.ssid_len),
(int) i, bss->num_sta);
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
@@ -535,7 +581,10 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
return len;
}
int hostapd_parse_csa_settings(const char *pos, struct csa_settings *settings) {
int hostapd_parse_csa_settings(const char *pos,
struct csa_settings *settings)
{
char *end;
os_memset(settings, 0, sizeof(*settings));
@@ -572,15 +621,21 @@ int hostapd_parse_csa_settings(const char *pos, struct csa_settings *settings) {
return 0;
}
int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd) {
int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
{
return hostapd_drv_stop_ap(hapd);
}
int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
size_t len) {
size_t len)
{
return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len);
}
void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd) {
void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd)
{
wpa_auth_pmksa_flush(hapd->wpa_auth);
}
@@ -9,8 +9,8 @@
#ifndef CTRL_IFACE_AP_H
#define CTRL_IFACE_AP_H
int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd, char *buf,
size_t buflen);
int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
char *buf, size_t buflen);
int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
char *buf, size_t buflen);
int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
@@ -19,12 +19,15 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
const char *txtaddr);
int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
const char *txtaddr);
int hostapd_ctrl_iface_signature(struct hostapd_data *hapd, const char *txtaddr,
int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
const char *txtaddr,
char *buf, size_t buflen);
int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd, const char *txtaddr);
int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
const char *txtaddr);
int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
size_t buflen);
int hostapd_parse_csa_settings(const char *pos, struct csa_settings *settings);
int hostapd_parse_csa_settings(const char *pos,
struct csa_settings *settings);
int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd);
int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
size_t len);
+219 -123
View File
@@ -9,16 +9,18 @@
#include "utils/includes.h"
#include "ap_drv_ops.h"
#include "common/hw_features_common.h"
#include "common/ieee802_11_defs.h"
#include "common/wpa_ctrl.h"
#include "dfs.h"
#include "drivers/driver.h"
#include "hostapd.h"
#include "utils/common.h"
#include "common/ieee802_11_defs.h"
#include "common/hw_features_common.h"
#include "common/wpa_ctrl.h"
#include "hostapd.h"
#include "ap_drv_ops.h"
#include "drivers/driver.h"
#include "dfs.h"
static int dfs_get_used_n_chans(struct hostapd_iface *iface, int *seg1) {
static int dfs_get_used_n_chans(struct hostapd_iface *iface, int *seg1)
{
int n_chans = 1;
*seg1 = 0;
@@ -48,32 +50,38 @@ static int dfs_get_used_n_chans(struct hostapd_iface *iface, int *seg1) {
return n_chans;
}
static int dfs_channel_available(struct hostapd_channel_data *chan,
int skip_radar) {
int skip_radar)
{
/*
* When radar detection happens, CSA is performed. However, there's no
* time for CAC, so radar channels must be skipped when finding a new
* channel for CSA, unless they are available for immediate use.
*/
if (skip_radar && (chan->flag & HOSTAPD_CHAN_RADAR) &&
((chan->flag & HOSTAPD_CHAN_DFS_MASK) != HOSTAPD_CHAN_DFS_AVAILABLE))
((chan->flag & HOSTAPD_CHAN_DFS_MASK) !=
HOSTAPD_CHAN_DFS_AVAILABLE))
return 0;
if (chan->flag & HOSTAPD_CHAN_DISABLED)
return 0;
if ((chan->flag & HOSTAPD_CHAN_RADAR) &&
((chan->flag & HOSTAPD_CHAN_DFS_MASK) == HOSTAPD_CHAN_DFS_UNAVAILABLE))
((chan->flag & HOSTAPD_CHAN_DFS_MASK) ==
HOSTAPD_CHAN_DFS_UNAVAILABLE))
return 0;
return 1;
}
static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans) {
static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans)
{
/*
* The tables contain first valid channel number based on channel width.
* We will also choose this first channel as the control one.
*/
int allowed_40[] = {36, 44, 52, 60, 100, 108, 116,
124, 132, 149, 157, 184, 192};
int allowed_40[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
184, 192 };
/*
* VHT80, valid channels based on center frequency:
* 42, 58, 106, 122, 138, 155
@@ -113,8 +121,10 @@ static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans) {
return 0;
}
static struct hostapd_channel_data *
dfs_get_chan_data(struct hostapd_hw_modes *mode, int freq, int first_chan_idx) {
dfs_get_chan_data(struct hostapd_hw_modes *mode, int freq, int first_chan_idx)
{
int i;
for (i = first_chan_idx; i < mode->num_channels; i++) {
@@ -125,9 +135,11 @@ dfs_get_chan_data(struct hostapd_hw_modes *mode, int freq, int first_chan_idx) {
return NULL;
}
static int dfs_chan_range_available(struct hostapd_hw_modes *mode,
int first_chan_idx, int num_chans,
int skip_radar) {
int skip_radar)
{
struct hostapd_channel_data *first_chan, *chan;
int i;
@@ -137,7 +149,8 @@ static int dfs_chan_range_available(struct hostapd_hw_modes *mode,
first_chan = &mode->channels[first_chan_idx];
for (i = 0; i < num_chans; i++) {
chan = dfs_get_chan_data(mode, first_chan->freq + i * 20, first_chan_idx);
chan = dfs_get_chan_data(mode, first_chan->freq + i * 20,
first_chan_idx);
if (!chan)
return 0;
@@ -148,14 +161,17 @@ static int dfs_chan_range_available(struct hostapd_hw_modes *mode,
return 1;
}
static int is_in_chanlist(struct hostapd_iface *iface,
struct hostapd_channel_data *chan) {
struct hostapd_channel_data *chan)
{
if (!iface->conf->acs_ch_list.num)
return 1;
return freq_range_list_includes(&iface->conf->acs_ch_list, chan->chan);
}
/*
* The function assumes HT40+ operation.
* Make sure to adjust the following variables after calling this:
@@ -164,8 +180,9 @@ static int is_in_chanlist(struct hostapd_iface *iface,
* - hapd->vht_oper_centr_freq_seg1_idx
*/
static int dfs_find_channel(struct hostapd_iface *iface,
struct hostapd_channel_data **ret_chan, int idx,
int skip_radar) {
struct hostapd_channel_data **ret_chan,
int idx, int skip_radar)
{
struct hostapd_hw_modes *mode;
struct hostapd_channel_data *chan;
int i, channel_idx = 0, n_chans, n_chans1;
@@ -178,7 +195,8 @@ static int dfs_find_channel(struct hostapd_iface *iface,
chan = &mode->channels[i];
/* Skip HT40/VHT incompatible channels */
if (iface->conf->ieee80211n && iface->conf->secondary_channel &&
if (iface->conf->ieee80211n &&
iface->conf->secondary_channel &&
!dfs_is_chan_allowed(chan, n_chans))
continue;
@@ -200,11 +218,13 @@ static int dfs_find_channel(struct hostapd_iface *iface,
return channel_idx;
}
static void dfs_adjust_vht_center_freq(struct hostapd_iface *iface,
struct hostapd_channel_data *chan,
int secondary_channel,
u8 *vht_oper_centr_freq_seg0_idx,
u8 *vht_oper_centr_freq_seg1_idx) {
u8 *vht_oper_centr_freq_seg1_idx)
{
if (!iface->conf->ieee80211ac)
return;
@@ -235,12 +255,14 @@ static void dfs_adjust_vht_center_freq(struct hostapd_iface *iface,
}
wpa_printf(MSG_DEBUG, "DFS adjusting VHT center frequency: %d, %d",
*vht_oper_centr_freq_seg0_idx, *vht_oper_centr_freq_seg1_idx);
*vht_oper_centr_freq_seg0_idx,
*vht_oper_centr_freq_seg1_idx);
}
/* Return start channel idx we will use for mode->channels[idx] */
static int dfs_get_start_chan_idx(struct hostapd_iface *iface,
int *seg1_start) {
static int dfs_get_start_chan_idx(struct hostapd_iface *iface, int *seg1_start)
{
struct hostapd_hw_modes *mode;
struct hostapd_channel_data *chan;
int channel_no = iface->conf->channel;
@@ -259,17 +281,22 @@ static int dfs_get_start_chan_idx(struct hostapd_iface *iface,
case VHT_CHANWIDTH_USE_HT:
break;
case VHT_CHANWIDTH_80MHZ:
channel_no = iface->conf->vht_oper_centr_freq_seg0_idx - 6;
channel_no =
iface->conf->vht_oper_centr_freq_seg0_idx - 6;
break;
case VHT_CHANWIDTH_160MHZ:
channel_no = iface->conf->vht_oper_centr_freq_seg0_idx - 14;
channel_no =
iface->conf->vht_oper_centr_freq_seg0_idx - 14;
break;
case VHT_CHANWIDTH_80P80MHZ:
channel_no = iface->conf->vht_oper_centr_freq_seg0_idx - 6;
chan_seg1 = iface->conf->vht_oper_centr_freq_seg1_idx - 6;
channel_no =
iface->conf->vht_oper_centr_freq_seg0_idx - 6;
chan_seg1 =
iface->conf->vht_oper_centr_freq_seg1_idx - 6;
break;
default:
wpa_printf(MSG_INFO, "DFS only VHT20/40/80/160/80+80 is supported now");
wpa_printf(MSG_INFO,
"DFS only VHT20/40/80/160/80+80 is supported now");
channel_no = -1;
break;
}
@@ -304,23 +331,26 @@ static int dfs_get_start_chan_idx(struct hostapd_iface *iface,
if (res == -1) {
wpa_printf(MSG_DEBUG,
"DFS chan_idx seems wrong; num-ch: %d ch-no: %d conf-ch-no: %d "
"11n: %d sec-ch: %d vht-oper-width: %d",
"DFS chan_idx seems wrong; num-ch: %d ch-no: %d conf-ch-no: %d 11n: %d sec-ch: %d vht-oper-width: %d",
mode->num_channels, channel_no, iface->conf->channel,
iface->conf->ieee80211n, iface->conf->secondary_channel,
iface->conf->ieee80211n,
iface->conf->secondary_channel,
iface->conf->vht_oper_chwidth);
for (i = 0; i < mode->num_channels; i++) {
wpa_printf(MSG_DEBUG, "Available channel: %d", mode->channels[i].chan);
wpa_printf(MSG_DEBUG, "Available channel: %d",
mode->channels[i].chan);
}
}
return res;
}
/* At least one channel have radar flag */
static int dfs_check_chans_radar(struct hostapd_iface *iface,
int start_chan_idx, int n_chans) {
int start_chan_idx, int n_chans)
{
struct hostapd_channel_data *channel;
struct hostapd_hw_modes *mode;
int i, res = 0;
@@ -336,9 +366,11 @@ static int dfs_check_chans_radar(struct hostapd_iface *iface,
return res;
}
/* All channels available */
static int dfs_check_chans_available(struct hostapd_iface *iface,
int start_chan_idx, int n_chans) {
int start_chan_idx, int n_chans)
{
struct hostapd_channel_data *channel;
struct hostapd_hw_modes *mode;
int i;
@@ -354,16 +386,20 @@ static int dfs_check_chans_available(struct hostapd_iface *iface,
if (!(channel->flag & HOSTAPD_CHAN_RADAR))
continue;
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) != HOSTAPD_CHAN_DFS_AVAILABLE)
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) !=
HOSTAPD_CHAN_DFS_AVAILABLE)
break;
}
return i == n_chans;
}
/* At least one channel unavailable */
static int dfs_check_chans_unavailable(struct hostapd_iface *iface,
int start_chan_idx, int n_chans) {
int start_chan_idx,
int n_chans)
{
struct hostapd_channel_data *channel;
struct hostapd_hw_modes *mode;
int i, res = 0;
@@ -374,17 +410,22 @@ static int dfs_check_chans_unavailable(struct hostapd_iface *iface,
channel = &mode->channels[start_chan_idx + i];
if (channel->flag & HOSTAPD_CHAN_DISABLED)
res++;
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) == HOSTAPD_CHAN_DFS_UNAVAILABLE)
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) ==
HOSTAPD_CHAN_DFS_UNAVAILABLE)
res++;
}
return res;
}
static struct hostapd_channel_data *
dfs_get_valid_channel(struct hostapd_iface *iface, int *secondary_channel,
dfs_get_valid_channel(struct hostapd_iface *iface,
int *secondary_channel,
u8 *vht_oper_centr_freq_seg0_idx,
u8 *vht_oper_centr_freq_seg1_idx, int skip_radar) {
u8 *vht_oper_centr_freq_seg1_idx,
int skip_radar)
{
struct hostapd_hw_modes *mode;
struct hostapd_channel_data *chan = NULL;
int num_available_chandefs;
@@ -419,15 +460,17 @@ dfs_get_valid_channel(struct hostapd_iface *iface, int *secondary_channel,
else
*secondary_channel = 0;
dfs_adjust_vht_center_freq(iface, chan, *secondary_channel,
dfs_adjust_vht_center_freq(iface, chan,
*secondary_channel,
vht_oper_centr_freq_seg0_idx,
vht_oper_centr_freq_seg1_idx);
return chan;
}
static int set_dfs_state_freq(struct hostapd_iface *iface, int freq,
u32 state) {
static int set_dfs_state_freq(struct hostapd_iface *iface, int freq, u32 state)
{
struct hostapd_hw_modes *mode;
struct hostapd_channel_data *chan = NULL;
int i;
@@ -451,9 +494,11 @@ static int set_dfs_state_freq(struct hostapd_iface *iface, int freq,
return 0;
}
static int set_dfs_state(struct hostapd_iface *iface, int freq, int ht_enabled,
int chan_offset, int chan_width, int cf1, int cf2,
u32 state) {
int chan_offset, int chan_width, int cf1,
int cf2, u32 state)
{
int n_chans = 1, i;
struct hostapd_hw_modes *mode;
int frequency = freq;
@@ -489,11 +534,13 @@ static int set_dfs_state(struct hostapd_iface *iface, int freq, int ht_enabled,
frequency = cf1 - 70;
break;
default:
wpa_printf(MSG_INFO, "DFS chan_width %d not supported", chan_width);
wpa_printf(MSG_INFO, "DFS chan_width %d not supported",
chan_width);
break;
}
wpa_printf(MSG_DEBUG, "DFS freq: %dMHz, n_chans: %d", frequency, n_chans);
wpa_printf(MSG_DEBUG, "DFS freq: %dMHz, n_chans: %d", frequency,
n_chans);
for (i = 0; i < n_chans; i++) {
ret += set_dfs_state_freq(iface, frequency, state);
frequency = frequency + 20;
@@ -502,8 +549,10 @@ static int set_dfs_state(struct hostapd_iface *iface, int freq, int ht_enabled,
return ret;
}
static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq,
int chan_width, int cf1, int cf2) {
int chan_width, int cf1, int cf2)
{
int start_chan_idx, start_chan_idx1;
struct hostapd_hw_modes *mode;
struct hostapd_channel_data *chan;
@@ -541,7 +590,8 @@ static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq,
frequency = cf1 - 70;
break;
default:
wpa_printf(MSG_INFO, "DFS chan_width %d not supported", chan_width);
wpa_printf(MSG_INFO, "DFS chan_width %d not supported",
chan_width);
break;
}
@@ -552,8 +602,8 @@ static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq,
if (!(chan->flag & HOSTAPD_CHAN_RADAR))
continue;
for (j = 0; j < radar_n_chans; j++) {
wpa_printf(MSG_DEBUG, "checking our: %d, radar: %d", chan->chan,
radar_chan + j * 4);
wpa_printf(MSG_DEBUG, "checking our: %d, radar: %d",
chan->chan, radar_chan + j * 4);
if (chan->chan == radar_chan + j * 4)
res++;
}
@@ -564,8 +614,10 @@ static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq,
return res;
}
static unsigned int dfs_get_cac_time(struct hostapd_iface *iface,
int start_chan_idx, int n_chans) {
int start_chan_idx, int n_chans)
{
struct hostapd_channel_data *channel;
struct hostapd_hw_modes *mode;
int i;
@@ -584,13 +636,15 @@ static unsigned int dfs_get_cac_time(struct hostapd_iface *iface,
return cac_time_ms;
}
/*
* Main DFS handler
* 1 - continue channel/ap setup
* 0 - channel/ap setup will be continued after CAC
* -1 - hit critical error
*/
int hostapd_handle_dfs(struct hostapd_iface *iface) {
int hostapd_handle_dfs(struct hostapd_iface *iface)
{
struct hostapd_channel_data *channel;
int res, n_chans, n_chans1, start_chan_idx, start_chan_idx1;
int skip_radar = 0;
@@ -600,8 +654,8 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) {
* This can happen with drivers that do not provide mode
* information and as such, cannot really use hostapd for DFS.
*/
wpa_printf(MSG_DEBUG, "DFS: No current_mode information - assume no need "
"to perform DFS operations by hostapd");
wpa_printf(MSG_DEBUG,
"DFS: No current_mode information - assume no need to perform DFS operations by hostapd");
return 1;
}
@@ -609,7 +663,8 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) {
do {
/* Get start (first) channel for current configuration */
start_chan_idx = dfs_get_start_chan_idx(iface, &start_chan_idx1);
start_chan_idx = dfs_get_start_chan_idx(iface,
&start_chan_idx1);
if (start_chan_idx == -1)
return -1;
@@ -617,30 +672,36 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) {
n_chans = dfs_get_used_n_chans(iface, &n_chans1);
/* Setup CAC time */
iface->dfs_cac_ms = dfs_get_cac_time(iface, start_chan_idx, n_chans);
iface->dfs_cac_ms = dfs_get_cac_time(iface, start_chan_idx,
n_chans);
/* Check if any of configured channels require DFS */
res = dfs_check_chans_radar(iface, start_chan_idx, n_chans);
wpa_printf(MSG_DEBUG, "DFS %d channels required radar detection", res);
wpa_printf(MSG_DEBUG,
"DFS %d channels required radar detection",
res);
if (!res)
return 1;
/* Check if all channels are DFS available */
res = dfs_check_chans_available(iface, start_chan_idx, n_chans);
wpa_printf(MSG_DEBUG, "DFS all channels available, (SKIP CAC): %s",
wpa_printf(MSG_DEBUG,
"DFS all channels available, (SKIP CAC): %s",
res ? "yes" : "no");
if (res)
return 1;
/* Check if any of configured channels is unavailable */
res = dfs_check_chans_unavailable(iface, start_chan_idx, n_chans);
res = dfs_check_chans_unavailable(iface, start_chan_idx,
n_chans);
wpa_printf(MSG_DEBUG, "DFS %d chans unavailable - choose other channel: %s",
res, res ? "yes": "no");
if (res) {
int sec = 0;
u8 cf1 = 0, cf2 = 0;
channel = dfs_get_valid_channel(iface, &sec, &cf1, &cf2, skip_radar);
channel = dfs_get_valid_channel(iface, &sec, &cf1, &cf2,
skip_radar);
if (!channel) {
wpa_printf(MSG_ERROR, "could not get valid channel");
hostapd_set_state(iface, HAPD_IFACE_DFS);
@@ -658,18 +719,22 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) {
/* Finally start CAC */
hostapd_set_state(iface, HAPD_IFACE_DFS);
wpa_printf(MSG_DEBUG, "DFS start CAC on %d MHz", iface->freq);
wpa_msg(
iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_CAC_START
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START
"freq=%d chan=%d sec_chan=%d, width=%d, seg0=%d, seg1=%d, cac_time=%ds",
iface->freq, iface->conf->channel, iface->conf->secondary_channel,
iface->conf->vht_oper_chwidth, iface->conf->vht_oper_centr_freq_seg0_idx,
iface->conf->vht_oper_centr_freq_seg1_idx, iface->dfs_cac_ms / 1000);
iface->freq,
iface->conf->channel, iface->conf->secondary_channel,
iface->conf->vht_oper_chwidth,
iface->conf->vht_oper_centr_freq_seg0_idx,
iface->conf->vht_oper_centr_freq_seg1_idx,
iface->dfs_cac_ms / 1000);
res = hostapd_start_dfs_cac(
iface, iface->conf->hw_mode, iface->freq, iface->conf->channel,
iface->conf->ieee80211n, iface->conf->ieee80211ac,
iface->conf->secondary_channel, iface->conf->vht_oper_chwidth,
res = hostapd_start_dfs_cac(iface, iface->conf->hw_mode,
iface->freq,
iface->conf->channel,
iface->conf->ieee80211n,
iface->conf->ieee80211ac,
iface->conf->secondary_channel,
iface->conf->vht_oper_chwidth,
iface->conf->vht_oper_centr_freq_seg0_idx,
iface->conf->vht_oper_centr_freq_seg1_idx);
@@ -681,12 +746,13 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) {
return 0;
}
int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2) {
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_CAC_COMPLETED "success=%d freq=%d ht_enabled=%d "
"chan_offset=%d chan_width=%d cf1=%d cf2=%d",
int cf1, int cf2)
{
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_COMPLETED
"success=%d freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
success, freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
if (success) {
@@ -698,7 +764,8 @@ int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
else
iface->cac_started = 0;
} else {
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, cf1, cf2,
set_dfs_state(iface, freq, ht_enabled, chan_offset,
chan_width, cf1, cf2,
HOSTAPD_CHAN_DFS_AVAILABLE);
iface->cac_started = 0;
hostapd_setup_interface_complete(iface, 0);
@@ -708,7 +775,9 @@ int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
return 0;
}
static int hostapd_dfs_start_channel_switch_cac(struct hostapd_iface *iface) {
static int hostapd_dfs_start_channel_switch_cac(struct hostapd_iface *iface)
{
struct hostapd_channel_data *channel;
int secondary_channel;
u8 vht_oper_centr_freq_seg0_idx = 0;
@@ -720,30 +789,36 @@ static int hostapd_dfs_start_channel_switch_cac(struct hostapd_iface *iface) {
iface->cac_started = 0;
channel = dfs_get_valid_channel(iface, &secondary_channel,
&vht_oper_centr_freq_seg0_idx,
&vht_oper_centr_freq_seg1_idx, skip_radar);
&vht_oper_centr_freq_seg1_idx,
skip_radar);
if (!channel) {
wpa_printf(MSG_ERROR, "No valid channel available");
return err;
}
wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d", channel->chan);
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_NEW_CHANNEL "freq=%d chan=%d sec_chan=%d", channel->freq,
wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d",
channel->chan);
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL
"freq=%d chan=%d sec_chan=%d", channel->freq,
channel->chan, secondary_channel);
iface->freq = channel->freq;
iface->conf->channel = channel->chan;
iface->conf->secondary_channel = secondary_channel;
iface->conf->vht_oper_centr_freq_seg0_idx = vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx = vht_oper_centr_freq_seg1_idx;
iface->conf->vht_oper_centr_freq_seg0_idx =
vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx =
vht_oper_centr_freq_seg1_idx;
err = 0;
hostapd_setup_interface_complete(iface, err);
return err;
}
static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface)
{
struct hostapd_channel_data *channel;
int secondary_channel;
u8 vht_oper_centr_freq_seg0_idx;
@@ -753,8 +828,8 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
unsigned int i;
int err = 1;
wpa_printf(MSG_DEBUG, "%s called (CAC active: %s, CSA active: %s)", __func__,
iface->cac_started ? "yes" : "no",
wpa_printf(MSG_DEBUG, "%s called (CAC active: %s, CSA active: %s)",
__func__, iface->cac_started ? "yes" : "no",
hostapd_csa_in_progress(iface) ? "yes" : "no");
/* Check if CSA in progress */
@@ -768,7 +843,8 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
/* Perform channel switch/CSA */
channel = dfs_get_valid_channel(iface, &secondary_channel,
&vht_oper_centr_freq_seg0_idx,
&vht_oper_centr_freq_seg1_idx, skip_radar);
&vht_oper_centr_freq_seg1_idx,
skip_radar);
if (!channel) {
/*
@@ -779,7 +855,8 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
skip_radar = 0;
channel = dfs_get_valid_channel(iface, &secondary_channel,
&vht_oper_centr_freq_seg0_idx,
&vht_oper_centr_freq_seg1_idx, skip_radar);
&vht_oper_centr_freq_seg1_idx,
skip_radar);
if (!channel) {
wpa_printf(MSG_INFO,
"%s: no DFS channels left, waiting for NOP to finish",
@@ -790,28 +867,36 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
iface->freq = channel->freq;
iface->conf->channel = channel->chan;
iface->conf->secondary_channel = secondary_channel;
iface->conf->vht_oper_centr_freq_seg0_idx = vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx = vht_oper_centr_freq_seg1_idx;
iface->conf->vht_oper_centr_freq_seg0_idx =
vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx =
vht_oper_centr_freq_seg1_idx;
hostapd_disable_iface(iface);
hostapd_enable_iface(iface);
return 0;
}
wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d", channel->chan);
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_NEW_CHANNEL "freq=%d chan=%d sec_chan=%d", channel->freq,
wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d",
channel->chan);
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL
"freq=%d chan=%d sec_chan=%d", channel->freq,
channel->chan, secondary_channel);
/* Setup CSA request */
os_memset(&csa_settings, 0, sizeof(csa_settings));
csa_settings.cs_count = 5;
csa_settings.block_tx = 1;
err = hostapd_set_freq_params(
&csa_settings.freq_params, iface->conf->hw_mode, channel->freq,
channel->chan, iface->conf->ieee80211n, iface->conf->ieee80211ac,
secondary_channel, iface->conf->vht_oper_chwidth,
vht_oper_centr_freq_seg0_idx, vht_oper_centr_freq_seg1_idx,
err = hostapd_set_freq_params(&csa_settings.freq_params,
iface->conf->hw_mode,
channel->freq,
channel->chan,
iface->conf->ieee80211n,
iface->conf->ieee80211ac,
secondary_channel,
iface->conf->vht_oper_chwidth,
vht_oper_centr_freq_seg0_idx,
vht_oper_centr_freq_seg1_idx,
iface->current_mode->vht_capab);
if (err) {
@@ -832,8 +917,10 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
iface->freq = channel->freq;
iface->conf->channel = channel->chan;
iface->conf->secondary_channel = secondary_channel;
iface->conf->vht_oper_centr_freq_seg0_idx = vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx = vht_oper_centr_freq_seg1_idx;
iface->conf->vht_oper_centr_freq_seg0_idx =
vht_oper_centr_freq_seg0_idx;
iface->conf->vht_oper_centr_freq_seg1_idx =
vht_oper_centr_freq_seg1_idx;
hostapd_disable_iface(iface);
hostapd_enable_iface(iface);
@@ -847,13 +934,14 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) {
return 0;
}
int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2) {
int cf1, int cf2)
{
int res;
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_RADAR_DETECTED
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_RADAR_DETECTED
"freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
@@ -865,8 +953,8 @@ int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
return 0;
/* mark radar frequency as invalid */
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, cf1, cf2,
HOSTAPD_CHAN_DFS_UNAVAILABLE);
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width,
cf1, cf2, HOSTAPD_CHAN_DFS_UNAVAILABLE);
/* Skip if reported radar event not overlapped our channels */
res = dfs_are_channels_overlapped(iface, freq, chan_width, cf1, cf2);
@@ -879,11 +967,12 @@ int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
return res;
}
int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2) {
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_NOP_FINISHED
int cf1, int cf2)
{
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NOP_FINISHED
"freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
@@ -892,8 +981,8 @@ int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
return 0;
/* TODO add correct implementation here */
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, cf1, cf2,
HOSTAPD_CHAN_DFS_USABLE);
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width,
cf1, cf2, HOSTAPD_CHAN_DFS_USABLE);
/* Handle cases where all channels were initially unavailable */
if (iface->state == HAPD_IFACE_DFS && !iface->cac_started)
@@ -902,7 +991,9 @@ int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
return 0;
}
int hostapd_is_dfs_required(struct hostapd_iface *iface) {
int hostapd_is_dfs_required(struct hostapd_iface *iface)
{
int n_chans, n_chans1, start_chan_idx, start_chan_idx1, res;
if (!iface->conf->ieee80211h || !iface->current_mode ||
@@ -926,16 +1017,20 @@ int hostapd_is_dfs_required(struct hostapd_iface *iface) {
return res;
}
int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq, int ht_enabled,
int chan_offset, int chan_width, int cf1, int cf2) {
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
DFS_EVENT_CAC_START "freq=%d chan=%d chan_offset=%d width=%d seg0=%d "
int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2)
{
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START
"freq=%d chan=%d chan_offset=%d width=%d seg0=%d "
"seg1=%d cac_time=%ds",
freq, (freq - 5000) / 5, chan_offset, chan_width, cf1, cf2, 60);
iface->cac_started = 1;
return 0;
}
/*
* Main DFS handler for offloaded case.
* 2 - continue channel/AP setup for non-DFS channel
@@ -943,9 +1038,10 @@ int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq, int ht_enabled,
* 0 - channel/AP setup will be continued after CAC
* -1 - hit critical error
*/
int hostapd_handle_dfs_offload(struct hostapd_iface *iface) {
wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d", __func__,
iface->cac_started);
int hostapd_handle_dfs_offload(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d",
__func__, iface->cac_started);
/*
* If DFS has already been started, then we are being called from a
@@ -953,15 +1049,15 @@ int hostapd_handle_dfs_offload(struct hostapd_iface *iface) {
* return.
*/
if (iface->cac_started) {
wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d", __func__,
iface->cac_started);
wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d",
__func__, iface->cac_started);
iface->cac_started = 0;
return 1;
}
if (ieee80211_is_dfs(iface->freq)) {
wpa_printf(MSG_DEBUG, "%s: freq %d MHz requires DFS", __func__,
iface->freq);
wpa_printf(MSG_DEBUG, "%s: freq %d MHz requires DFS",
__func__, iface->freq);
return 0;
}
@@ -15,14 +15,16 @@ int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2);
int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
int ht_enabled, int chan_offset, int chan_width,
int ht_enabled,
int chan_offset, int chan_width,
int cf1, int cf2);
int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
int ht_enabled,
int chan_offset, int chan_width, int cf1, int cf2);
int hostapd_is_dfs_required(struct hostapd_iface *iface);
int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq,
int ht_enabled, int chan_offset, int chan_width,
int cf1, int cf2);
int hostapd_is_dfs_required(struct hostapd_iface *iface);
int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq, int ht_enabled,
int chan_offset, int chan_width, int cf1, int cf2);
int hostapd_handle_dfs_offload(struct hostapd_iface *iface);
#endif /* DFS_H */
@@ -10,13 +10,13 @@
#include <netinet/ip.h>
#include <netinet/udp.h>
#include "ap_drv_ops.h"
#include "dhcp_snoop.h"
#include "hostapd.h"
#include "l2_packet/l2_packet.h"
#include "sta_info.h"
#include "utils/common.h"
#include "l2_packet/l2_packet.h"
#include "hostapd.h"
#include "sta_info.h"
#include "ap_drv_ops.h"
#include "x_snoop.h"
#include "dhcp_snoop.h"
struct bootp_pkt {
struct iphdr iph;
@@ -41,16 +41,21 @@ struct bootp_pkt {
#define DHCPACK 5
static const u8 ic_bootp_cookie[] = { 99, 130, 83, 99 };
static const char *ipaddr_str(u32 addr) {
static const char * ipaddr_str(u32 addr)
{
static char buf[17];
os_snprintf(buf, sizeof(buf), "%u.%u.%u.%u", (addr >> 24) & 0xff,
(addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
os_snprintf(buf, sizeof(buf), "%u.%u.%u.%u",
(addr >> 24) & 0xff, (addr >> 16) & 0xff,
(addr >> 8) & 0xff, addr & 0xff);
return buf;
}
static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf,
size_t len) {
size_t len)
{
struct hostapd_data *hapd = ctx;
const struct bootp_pkt *b;
struct sta_info *sta;
@@ -114,9 +119,10 @@ static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf,
if (!sta)
return;
wpa_printf(MSG_DEBUG,
"dhcp_snoop: Found DHCPACK for " MACSTR " @ IPv4 address %s/%d",
MAC2STR(sta->addr), ipaddr_str(be_to_host32(b->your_ip)),
wpa_printf(MSG_DEBUG, "dhcp_snoop: Found DHCPACK for " MACSTR
" @ IPv4 address %s/%d",
MAC2STR(sta->addr),
ipaddr_str(be_to_host32(b->your_ip)),
prefixlen);
if (sta->ipaddr == b->your_ip)
@@ -126,13 +132,15 @@ static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf,
wpa_printf(MSG_DEBUG,
"dhcp_snoop: Removing IPv4 address %s from the ip neigh table",
ipaddr_str(be_to_host32(sta->ipaddr)));
hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *)&sta->ipaddr);
hostapd_drv_br_delete_ip_neigh(hapd, 4,
(u8 *) &sta->ipaddr);
}
res = hostapd_drv_br_add_ip_neigh(hapd, 4, (u8 *)&b->your_ip, prefixlen,
sta->addr);
res = hostapd_drv_br_add_ip_neigh(hapd, 4, (u8 *) &b->your_ip,
prefixlen, sta->addr);
if (res) {
wpa_printf(MSG_DEBUG, "dhcp_snoop: Adding ip neigh table failed: %d",
wpa_printf(MSG_DEBUG,
"dhcp_snoop: Adding ip neigh table failed: %d",
res);
return;
}
@@ -143,18 +151,20 @@ static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf,
for (sta = hapd->sta_list; sta; sta = sta->next) {
if (!(sta->flags & WLAN_STA_AUTHORIZED))
continue;
x_snoop_mcast_to_ucast_convert_send(hapd, sta, (u8 *)buf, len);
x_snoop_mcast_to_ucast_convert_send(hapd, sta,
(u8 *) buf, len);
}
}
}
int dhcp_snoop_init(struct hostapd_data *hapd) {
hapd->sock_dhcp =
x_snoop_get_l2_packet(hapd, handle_dhcp, L2_PACKET_FILTER_DHCP);
int dhcp_snoop_init(struct hostapd_data *hapd)
{
hapd->sock_dhcp = x_snoop_get_l2_packet(hapd, handle_dhcp,
L2_PACKET_FILTER_DHCP);
if (hapd->sock_dhcp == NULL) {
wpa_printf(MSG_DEBUG,
"dhcp_snoop: Failed to initialize L2 packet processing for DHCP "
"packet: %s",
"dhcp_snoop: Failed to initialize L2 packet processing for DHCP packet: %s",
strerror(errno));
return -1;
}
@@ -162,6 +172,8 @@ int dhcp_snoop_init(struct hostapd_data *hapd) {
return 0;
}
void dhcp_snoop_deinit(struct hostapd_data *hapd) {
void dhcp_snoop_deinit(struct hostapd_data *hapd)
{
l2_packet_deinit(hapd->sock_dhcp);
}
@@ -16,9 +16,14 @@ void dhcp_snoop_deinit(struct hostapd_data *hapd);
#else /* CONFIG_PROXYARP */
static inline int dhcp_snoop_init(struct hostapd_data *hapd) { return 0; }
static inline int dhcp_snoop_init(struct hostapd_data *hapd)
{
return 0;
}
static inline void dhcp_snoop_deinit(struct hostapd_data *hapd) {}
static inline void dhcp_snoop_deinit(struct hostapd_data *hapd)
{
}
#endif /* CONFIG_PROXYARP */

Some files were not shown because too many files have changed in this diff Show More