00001
00028 #include <ctype.h>
00029
00030 #include "cmd_wl.h"
00031
00032 #include "wl_cm.h"
00033 #include "console.h"
00034 #include "wl_util.h"
00035 #include "util.h"
00036 #include "lwip/netif.h"
00037
00041 cmd_state_t
00042 cmd_scan(int argc, char* argv[], void* ctx)
00043 {
00044
00045
00046
00047 wl_scan();
00048 print_network_list();
00049 return CMD_DONE;
00050 }
00051
00052
00056 cmd_state_t
00057 cmd_connect(int argc, char* argv[], void* ctx)
00058 {
00059 struct wl_ssid_t ssid;
00060 char* desired_ssid;
00061
00062 if (argc < 2) {
00063 printk("usage: connect <ssid>\n");
00064 return CMD_DONE;
00065 }
00066
00067 desired_ssid = argv[1];
00068
00069 if (strlen(desired_ssid) > WL_SSID_MAX_LENGTH) {
00070 printk("ssid too long (max 32)\n");
00071 return CMD_DONE;
00072 }
00073
00074 memcpy(ssid.ssid, desired_ssid, WL_SSID_MAX_LENGTH);
00075 ssid.len = strlen(desired_ssid);
00076 wl_cm_set_network(&ssid, NULL);
00077 return CMD_DONE;
00078 }
00079
00080
00081 #ifdef WITH_WPA
00082
00086 cmd_state_t
00087 cmd_delpass(int argc, char* argv[], void* ctx)
00088 {
00089 const char *usage = "usage: dpass <ssid>\n";
00090 struct wl_network_t net;
00091
00092 if (argc != 2) {
00093 printk(usage);
00094 return CMD_DONE;
00095 }
00096
00097
00098
00099 memset(&net, 0, sizeof net);
00100 memset(net.bssid.octet, 0xFF, sizeof net.bssid.octet);
00101 strncpy(net.ssid.ssid, argv[1], strlen(argv[1]));
00102 net.ssid.len = strlen(argv[1]);
00103 net.enc_type = ENC_TYPE_AUTO;
00104 if (wl_clear_passphrase(&net) != WL_SUCCESS) {
00105 printk("%s : Failed to delete passphrase\n", __func__);
00106 }
00107
00108 return CMD_DONE;
00109 }
00110
00111
00115 cmd_state_t
00116 cmd_setpass(int argc, char* argv[], void* ctx)
00117 {
00118 const char *usage = "usage: wpass <ssid> <passphrase>\n";
00119 struct wl_network_t net;
00120
00121 if (argc != 3) {
00122 printk(usage);
00123 return CMD_DONE;
00124 }
00125
00126
00127
00128 memset(&net, 0, sizeof net);
00129 memset(net.bssid.octet, 0xFF, sizeof net.bssid.octet);
00130 strncpy(net.ssid.ssid, argv[1], strlen(argv[1]));
00131 net.ssid.len = strlen(argv[1]);
00132 net.enc_type = ENC_TYPE_AUTO;
00133 if (wl_set_passphrase(&net,
00134 argv[2],
00135 strlen(argv[2]),
00136 ENC_TYPE_AUTO,
00137 AUTH_MODE_AUTO)
00138 != WL_SUCCESS) {
00139 printk("%s : Failed to add passphrase\n", __func__);
00140 }
00141
00142 return CMD_DONE;
00143 }
00144 #endif
00145
00146
00150 cmd_state_t
00151 cmd_status(int argc, char* argv[], void* ctx)
00152 {
00153 struct wl_network_t* net;
00154 uint8_t mac[WL_MAC_ADDR_LENGTH];
00155
00156 printk("wl_api version " WL_API_RELEASE_NAME "\n");
00157
00158 if (wl_get_mac_addr(mac) != WL_SUCCESS) {
00159 printk("failed to get mac address\n");
00160 return CMD_DONE;
00161 }
00162 printk("hw addr: %s\n", mac2str(mac));
00163
00164
00165 net = wl_get_current_network();
00166 printk("link status: ");
00167 if (!net) {
00168 printk("down\n");
00169 return CMD_DONE;
00170 }
00171 print_network(net);
00172
00173
00174 if (netif_is_up(netif_default))
00175 printk("ip addr: %s\n", ip2str(netif_default->ip_addr));
00176 else
00177 printk("ip addr: none\n");
00178
00179 return CMD_DONE;
00180 }
00181
00182
00186 cmd_state_t
00187 cmd_power(int argc, char* argv[], void* ctx)
00188 {
00189 const char *usage = "usage: powersave <on|off>\n";
00190
00191 if (argc < 2) {
00192 printk(usage);
00193 return CMD_DONE;
00194 }
00195
00196 if (!strcmp(argv[1], "on")) {
00197 if (wl_enable_ps() != WL_SUCCESS) {
00198 printk("could not enable power save\n");
00199 return CMD_DONE;
00200 }
00201 return CMD_DONE;
00202 }
00203 else if(!strcmp(argv[1], "off")) {
00204 if (wl_disable_ps() != WL_SUCCESS) {
00205 printk("could not disable power save\n");
00206 return CMD_DONE;
00207 }
00208 return CMD_DONE;
00209 }
00210
00211 printk(usage);
00212 return CMD_DONE;
00213 }
00214
00215
00219 cmd_state_t
00220 cmd_psconf(int argc, char* argv[], void* ctx)
00221 {
00222 const char *usage =
00223 "usage: psconf <use_ps_poll> (0/1 default 0)\n" \
00224 " <traffic_timeout> ([ms] default 10)\n" \
00225 " <ps_delay> ([ms] default 5000)\n";
00226
00227 uint8_t use_ps_poll;
00228 uint32_t traffic_timeout;
00229 uint32_t ps_delay;
00230
00231 if (argc < 4) {
00232 printk(usage);
00233 return CMD_DONE;
00234 }
00235
00236 use_ps_poll = atoi(argv[1]);
00237 traffic_timeout = atoi(argv[2]);
00238 ps_delay = atoi(argv[3]);
00239
00240 if (use_ps_poll > 1) {
00241 printk(usage);
00242 return CMD_DONE;
00243 }
00244
00245 if (wl_conf_ps(use_ps_poll, traffic_timeout, ps_delay) != WL_SUCCESS)
00246 printk("configuration failed\n");
00247
00248 return CMD_DONE;
00249 }
00250
00251 #define MAX_KEY_LEN 64
00252
00256 static uint8_t ascii_to_key(char *outp, const char *inp) {
00257 char buf[3];
00258 int len;
00259 buf[2] = '\0';
00260 len = strlen(inp);
00261 if (len % 2) {
00262 printk("Invalid length\n");
00263 }
00264 len = 0;
00265 while (*inp) {
00266 if (! isxdigit(*inp) || ! isxdigit(*(inp+1)) ||
00267 len > MAX_KEY_LEN) {
00268 return 0;
00269 }
00270 buf[0] = *inp++;
00271 buf[1] = *inp++;
00272 *outp++ = strtol(buf, NULL, 16);
00273 len++;
00274 }
00275 return len;
00276 }
00277
00278
00282 cmd_state_t
00283 cmd_setkey(int argc, char* argv[], void* ctx)
00284 {
00285 int idx, len;
00286 char key[13];
00287 struct wl_mac_addr_t bssid;
00288 const char *usage = "usage: setkey <key_idx (0-3)> <key in hex>\n\t "\
00289 "or: setkey none\n";
00290
00291 memset(&bssid.octet, 0xff, sizeof bssid.octet);
00292 if (argc == 2 && strcmp(argv[1], "none") == 0) {
00293 printk("Deleting WEP keys\n");
00294 wl_set_auth_mode(AUTH_MODE_OPEN_SYSTEM);
00295 wl_delete_wep_key(0, &bssid);
00296 wl_delete_wep_key(1, &bssid);
00297 wl_delete_wep_key(2, &bssid);
00298 wl_delete_wep_key(3, &bssid);
00299 return CMD_DONE;
00300 }
00301 if (argc < 3) {
00302 printk(usage);
00303 return CMD_DONE;
00304 }
00305 idx = atoi(argv[1]);
00306 len = ascii_to_key(key, argv[2]);
00307 if (0 == len || idx > 3 || idx < 0 || (idx == 0 && *argv[1] != '0')) {
00308 printk(usage);
00309 return CMD_DONE;
00310 }
00311 if (len != 5 && len != 13) {
00312 printk(" WEP key must be 10 (WEP-40) or 26 (WEP-104) digits\n");
00313 return CMD_DONE;
00314 }
00315 wl_add_wep_key(idx, len, key, &bssid);
00316 wl_set_auth_mode(AUTH_MODE_SHARED_KEY);
00317 wl_set_default_wep_key(idx);
00318
00319 return CMD_DONE;
00320 }