2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "wman_test_common.h"
22 #include <wifi-manager.h>
24 const char *wman_test_strerror(wifi_manager_error_e err_type)
27 case WIFI_MANAGER_ERROR_NONE:
29 case WIFI_MANAGER_ERROR_INVALID_PARAMETER:
30 return "INVALID_PARAMETER";
31 case WIFI_MANAGER_ERROR_OUT_OF_MEMORY:
32 return "OUT_OF_MEMORY";
33 case WIFI_MANAGER_ERROR_INVALID_OPERATION:
34 return "INVALID_OPERATION";
35 case WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
36 return "ADDRESS_FAMILY_NOT_SUPPORTED";
37 case WIFI_MANAGER_ERROR_OPERATION_FAILED:
38 return "OPERATION_FAILED";
39 case WIFI_MANAGER_ERROR_NO_CONNECTION:
40 return "NO_CONNECTION";
41 case WIFI_MANAGER_ERROR_NOW_IN_PROGRESS:
42 return "NOW_IN_PROGRESS";
43 case WIFI_MANAGER_ERROR_ALREADY_EXISTS:
44 return "ALREADY_EXISTS";
45 case WIFI_MANAGER_ERROR_OPERATION_ABORTED:
46 return "OPERATION_ABORTED";
47 case WIFI_MANAGER_ERROR_DHCP_FAILED:
49 case WIFI_MANAGER_ERROR_INVALID_KEY:
51 case WIFI_MANAGER_ERROR_NO_REPLY:
53 case WIFI_MANAGER_ERROR_SECURITY_RESTRICTED:
54 return "SECURITY_RESTRICTED";
55 case WIFI_MANAGER_ERROR_ALREADY_INITIALIZED:
56 return "ALREADY_INITIALIZED";
57 case WIFI_MANAGER_ERROR_OUT_OF_RANGE:
58 return "OUT_OF_RANGE";
59 case WIFI_MANAGER_ERROR_CONNECT_FAILED:
60 return "CONNECT_FAILED";
61 case WIFI_MANAGER_ERROR_LOGIN_FAILED:
62 return "LOGIN_FAILED";
63 case WIFI_MANAGER_ERROR_AUTHENTICATION_FAILED:
65 case WIFI_MANAGER_ERROR_ASSOCIATION_FAILED:
66 return "ASSOC_FAILED";
67 case WIFI_MANAGER_ERROR_PIN_MISSING:
69 case WIFI_MANAGER_ERROR_WPS_OVERLAP:
71 case WIFI_MANAGER_ERROR_WPS_TIMEOUT:
73 case WIFI_MANAGER_ERROR_WPS_WEP_PROHIBITED:
74 return "WPS_WEP_PROHIBITED";
75 case WIFI_MANAGER_ERROR_PERMISSION_DENIED:
76 return "PERMISSION_DENIED";
77 case WIFI_MANAGER_ERROR_OFFLINE:
79 case WIFI_MANAGER_ERROR_INVALID_GATEWAY:
80 return "INVALID_GATEWAY";
81 case WIFI_MANAGER_ERROR_NOT_SUPPORTED:
82 return "NOT_SUPPORTED";
83 case WIFI_MANAGER_ERROR_NOT_INITIALIZED:
84 return "NOT_INITIALIZED";
90 bool wman_test_compare_ap_name(const char *ap_name, const char *ap_name_part)
92 int ap_name_len = strlen(ap_name);
93 int ap_name_part_len = strlen(ap_name_part);
95 if (strncmp(ap_name, ap_name_part,
96 ap_name_len > ap_name_part_len ? ap_name_len : ap_name_part_len) == 0)
102 void wman_test_connected_cb(wifi_manager_error_e result, void* user_data)
104 if (result == WIFI_MANAGER_ERROR_NONE)
105 printf("Wi-Fi Connection Succeeded\n");
107 printf("Wi-Fi Connection Failed! error : %s\n", wman_test_strerror(result));
110 bool test_get_user_int(const char *msg, int *num)
112 if (msg == NULL || num == NULL)
118 rv = read(0, buf, 32);
120 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
127 bool test_get_user_string(const char *msg, char *buf, int buf_size)
129 if (msg == NULL || buf == NULL || buf_size < 2)
134 memset(buf, 0, buf_size);
135 rv = read(0, buf, buf_size - 1);
137 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
146 static inline int __test_convert_byte_to_txt(const unsigned char *src, char **dst, int src_len)
153 printf("Invalid source length\n");
157 *dst = malloc((2 * src_len) + 1);
159 printf("failed to allocate memory to buffer\n");
165 for (i = 0; i < src_len; i++) {
166 snprintf(buf, 3, "%02x", src[i]);
174 bool __test_vendor_specific_cb(unsigned char *vsie_bytes, int vsie_len, void *user_data)
180 int buf_len = __test_convert_byte_to_txt(vsie_bytes, &vsie, vsie_len);
182 printf("vsie_len: %d, vsie: %s\n", vsie_len, vsie);