Share TEST_FAIL/TEST_ALLOC_FAIL/GET_FAIL/GET_ALLOC_FAIL handler
Move the hostapd and wpa_supplicant control interface handlers into a shared functions instead of duplicated implementation. Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
This commit is contained in:
parent
85c96b7cf7
commit
e9bdecce4d
4 changed files with 72 additions and 151 deletions
|
@ -2006,74 +2006,6 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_ctrl_test_alloc_fail(struct hostapd_data *hapd, char *cmd)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
char *pos;
|
|
||||||
|
|
||||||
wpa_trace_fail_after = atoi(cmd);
|
|
||||||
pos = os_strchr(cmd, ':');
|
|
||||||
if (pos) {
|
|
||||||
pos++;
|
|
||||||
os_strlcpy(wpa_trace_fail_func, pos,
|
|
||||||
sizeof(wpa_trace_fail_func));
|
|
||||||
} else {
|
|
||||||
wpa_trace_fail_after = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
|
|
||||||
char *buf, size_t buflen)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
|
|
||||||
wpa_trace_fail_func);
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
char *pos;
|
|
||||||
|
|
||||||
wpa_trace_test_fail_after = atoi(cmd);
|
|
||||||
pos = os_strchr(cmd, ':');
|
|
||||||
if (pos) {
|
|
||||||
pos++;
|
|
||||||
os_strlcpy(wpa_trace_test_fail_func, pos,
|
|
||||||
sizeof(wpa_trace_test_fail_func));
|
|
||||||
} else {
|
|
||||||
wpa_trace_test_fail_after = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
|
|
||||||
char *buf, size_t buflen)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
|
|
||||||
wpa_trace_test_fail_func);
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
|
static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
|
||||||
{
|
{
|
||||||
struct sta_info *sta;
|
struct sta_info *sta;
|
||||||
|
@ -3703,16 +3635,15 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
|
||||||
if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
|
if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
|
} else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
|
||||||
if (hostapd_ctrl_test_alloc_fail(hapd, buf + 16) < 0)
|
if (testing_set_fail_pattern(true, buf + 16) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
|
} else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
|
||||||
reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
|
reply_len = testing_get_fail_pattern(true, reply, reply_size);
|
||||||
reply_size);
|
|
||||||
} else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
|
} else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
|
||||||
if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
|
if (testing_set_fail_pattern(false, buf + 10) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strcmp(buf, "GET_FAIL") == 0) {
|
} else if (os_strcmp(buf, "GET_FAIL") == 0) {
|
||||||
reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
|
reply_len = testing_get_fail_pattern(false, reply, reply_size);
|
||||||
} else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
|
} else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
|
||||||
if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
|
if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
|
|
|
@ -669,12 +669,20 @@ int os_exec(const char *program, const char *arg, int wait_completion);
|
||||||
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
|
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
|
||||||
#define TEST_FAIL() testing_test_fail()
|
#define TEST_FAIL() testing_test_fail()
|
||||||
int testing_test_fail(void);
|
int testing_test_fail(void);
|
||||||
extern char wpa_trace_fail_func[256];
|
int testing_set_fail_pattern(bool is_alloc, char *patterns);
|
||||||
extern unsigned int wpa_trace_fail_after;
|
int testing_get_fail_pattern(bool is_alloc, char *buf, size_t buflen);
|
||||||
extern char wpa_trace_test_fail_func[256];
|
|
||||||
extern unsigned int wpa_trace_test_fail_after;
|
|
||||||
#else
|
#else
|
||||||
#define TEST_FAIL() 0
|
#define TEST_FAIL() 0
|
||||||
|
static inline int testing_set_fail_pattern(bool is_alloc, char *patterns)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int testing_get_fail_pattern(bool is_alloc, char *buf,
|
||||||
|
size_t buflen)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* OS_H */
|
#endif /* OS_H */
|
||||||
|
|
|
@ -540,8 +540,8 @@ void * os_memdup(const void *src, size_t len)
|
||||||
#ifdef WPA_TRACE
|
#ifdef WPA_TRACE
|
||||||
|
|
||||||
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
|
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
|
||||||
char wpa_trace_fail_func[256] = { 0 };
|
static char wpa_trace_fail_func[256] = { 0 };
|
||||||
unsigned int wpa_trace_fail_after;
|
static unsigned int wpa_trace_fail_after;
|
||||||
|
|
||||||
static int testing_fail_alloc(void)
|
static int testing_fail_alloc(void)
|
||||||
{
|
{
|
||||||
|
@ -626,8 +626,8 @@ static int testing_fail_alloc(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char wpa_trace_test_fail_func[256] = { 0 };
|
static char wpa_trace_test_fail_func[256] = { 0 };
|
||||||
unsigned int wpa_trace_test_fail_after;
|
static unsigned int wpa_trace_test_fail_after;
|
||||||
|
|
||||||
int testing_test_fail(void)
|
int testing_test_fail(void)
|
||||||
{
|
{
|
||||||
|
@ -697,6 +697,54 @@ int testing_test_fail(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int testing_set_fail_pattern(bool is_alloc, char *patterns)
|
||||||
|
{
|
||||||
|
#ifdef WPA_TRACE_BFD
|
||||||
|
char *pos;
|
||||||
|
|
||||||
|
if (is_alloc) {
|
||||||
|
wpa_trace_fail_after = atoi(patterns);
|
||||||
|
pos = os_strchr(patterns, ':');
|
||||||
|
if (pos) {
|
||||||
|
pos++;
|
||||||
|
os_strlcpy(wpa_trace_fail_func, pos,
|
||||||
|
sizeof(wpa_trace_fail_func));
|
||||||
|
} else {
|
||||||
|
wpa_trace_fail_after = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wpa_trace_test_fail_after = atoi(patterns);
|
||||||
|
pos = os_strchr(patterns, ':');
|
||||||
|
if (pos) {
|
||||||
|
pos++;
|
||||||
|
os_strlcpy(wpa_trace_test_fail_func, pos,
|
||||||
|
sizeof(wpa_trace_test_fail_func));
|
||||||
|
} else {
|
||||||
|
wpa_trace_test_fail_after = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#else /* WPA_TRACE_BFD */
|
||||||
|
return -1;
|
||||||
|
#endif /* WPA_TRACE_BFD */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int testing_get_fail_pattern(bool is_alloc, char *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
#ifdef WPA_TRACE_BFD
|
||||||
|
if (is_alloc)
|
||||||
|
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
|
||||||
|
wpa_trace_fail_func);
|
||||||
|
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
|
||||||
|
wpa_trace_test_fail_func);
|
||||||
|
#else /* WPA_TRACE_BFD */
|
||||||
|
return -1;
|
||||||
|
#endif /* WPA_TRACE_BFD */
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline int testing_fail_alloc(void)
|
static inline int testing_fail_alloc(void)
|
||||||
|
|
|
@ -10134,72 +10134,6 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
char *pos;
|
|
||||||
|
|
||||||
wpa_trace_fail_after = atoi(cmd);
|
|
||||||
pos = os_strchr(cmd, ':');
|
|
||||||
if (pos) {
|
|
||||||
pos++;
|
|
||||||
os_strlcpy(wpa_trace_fail_func, pos,
|
|
||||||
sizeof(wpa_trace_fail_func));
|
|
||||||
} else {
|
|
||||||
wpa_trace_fail_after = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
|
|
||||||
char *buf, size_t buflen)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
|
|
||||||
wpa_trace_fail_func);
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
char *pos;
|
|
||||||
|
|
||||||
wpa_trace_test_fail_after = atoi(cmd);
|
|
||||||
pos = os_strchr(cmd, ':');
|
|
||||||
if (pos) {
|
|
||||||
pos++;
|
|
||||||
os_strlcpy(wpa_trace_test_fail_func, pos,
|
|
||||||
sizeof(wpa_trace_test_fail_func));
|
|
||||||
} else {
|
|
||||||
wpa_trace_test_fail_after = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
|
|
||||||
char *buf, size_t buflen)
|
|
||||||
{
|
|
||||||
#ifdef WPA_TRACE_BFD
|
|
||||||
return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
|
|
||||||
wpa_trace_test_fail_func);
|
|
||||||
#else /* WPA_TRACE_BFD */
|
|
||||||
return -1;
|
|
||||||
#endif /* WPA_TRACE_BFD */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
|
static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
|
||||||
{
|
{
|
||||||
struct wpa_supplicant *wpa_s = eloop_ctx;
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
||||||
|
@ -12886,15 +12820,15 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
|
||||||
if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
|
if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
|
} else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
|
||||||
if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
|
if (testing_set_fail_pattern(true, buf + 16) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
|
} else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
|
||||||
reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
|
reply_len = testing_get_fail_pattern(true, reply, reply_size);
|
||||||
} else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
|
} else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
|
||||||
if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
|
if (testing_set_fail_pattern(false, buf + 10) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strcmp(buf, "GET_FAIL") == 0) {
|
} else if (os_strcmp(buf, "GET_FAIL") == 0) {
|
||||||
reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
|
reply_len = testing_get_fail_pattern(false, reply, reply_size);
|
||||||
} else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
|
} else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
|
||||||
if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
|
if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
|
|
Loading…
Reference in a new issue