00001
00028 #include "top_defs.h"
00029 #include "util.h"
00030 #include "wl_util.h"
00031 #include <stdio.h>
00032 #include <errno.h>
00033 #include <string.h>
00034
00035 char* ip2str(struct ip_addr addr)
00036 {
00037 static char buf[16];
00038 sniprintf(buf, sizeof(buf), "%lu.%lu.%lu.%lu",
00039 (addr.addr >> 24) & 0xff,
00040 (addr.addr >> 16) & 0xff,
00041 (addr.addr >> 8) & 0xff,
00042 (addr.addr) & 0xff);
00043 return buf;
00044 }
00045
00046 struct ip_addr str2ip(const char* str)
00047 {
00048 int a,b,c,d;
00049 uint32_t ip = 0;
00050
00051 if (siscanf(str,"%d.%d.%d.%d",&a,&b,&c,&d) != 4)
00052 goto out;
00053
00054 if (a < 0 || a > 255 || b < 0 || b > 255 ||
00055 c < 0 || c > 255 || d < 0 || d > 255)
00056 goto out;
00057
00058 ip = (a << 24) | (b << 16) | (c << 8) | d;
00059
00060 out:
00061 return *(struct ip_addr*) &ip;
00062 }
00063
00064 void print_network(struct wl_network_t* wl_network)
00065 {
00066 char ssid[WL_SSID_MAX_LENGTH + 1];
00067 printk("%s ", mac2str(wl_network->bssid.octet));
00068 memset(ssid, 0, sizeof(ssid));
00069 if (wl_network->ssid.len) {
00070 strncpy(ssid, wl_network->ssid.ssid, wl_network->ssid.len);
00071 printk("\"%s\"", ssid);
00072 }
00073 else {
00074 printk("\"\"");
00075 }
00076 printk(" RSSI %d dBm ", wl_network->rssi);
00077 switch (wl_network->enc_type) {
00078 case ENC_TYPE_WEP :
00079 printk(" (WEP encryption)");
00080 break;
00081 case ENC_TYPE_TKIP :
00082 printk(" (TKIP encryption)");
00083 break;
00084 case ENC_TYPE_CCMP :
00085 printk(" (CCMP encryption)");
00086 break;
00087 case ENC_TYPE_NONE :
00088 break;
00089 }
00090 printk("\n");
00091 }
00092
00093 void print_network_list(void)
00094 {
00095 struct wl_network_t* wl_network_list;
00096 uint8_t wl_network_cnt, i;
00097
00098 wl_get_network_list(&wl_network_list, &wl_network_cnt);
00099 if (wl_network_cnt == 0)
00100 printk("no nets found\n");
00101
00102 for (i = 0; i < wl_network_cnt; i++)
00103 print_network(&wl_network_list[i]);
00104 }