00001
00028 #include <ctype.h>
00029 #include <board.h>
00030 #include "wl_api.h"
00031 #include "wl_cm.h"
00032
00033 #include "lwip/netif.h"
00034
00035 #include "http_server_gui.h"
00036 #include "gui.h"
00037 #if BOARD == EVK1104 || BOARD == EVK1105
00038 #include "et024006dhu.h"
00039 #else
00040 #define WHITE 0
00041 #endif
00042 #include "clocks.h"
00043 #include "board.h"
00044 #include "wl_util.h"
00045 #include "util.h"
00046
00047 #include <string.h>
00048
00049 #define GUI_MAX_NETWORKS 16
00050
00051 #define MAX_KEY_LEN 64
00052 char ascii_key[MAX_KEY_LEN];
00053
00054 char gui_print_buf[80];
00055 static struct wl_network_t gui_network_list[GUI_MAX_NETWORKS];
00056 static int gui_network_cnt = 0;
00057 #define gui_printk(line, args...) do { \
00058 extern char gui_print_buf[80]; \
00059 sniprintf(gui_print_buf, sizeof(gui_print_buf), args); \
00060 gui_set_title(gui_print_buf, line); \
00061 } while(0)
00062
00066 static void
00067 gui_scan_cb(void)
00068 {
00069 struct wl_network_t* wl_network_list;
00070 uint8_t wl_network_cnt, i;
00071
00072 gui_clear_scroll_box();
00073 gui_set_bg_color(WHITE);
00074 gui_add_scroll_box_item("Scan Contents:", sizeof "Scan Contents:");
00075
00076 wl_get_network_list(&wl_network_list, &wl_network_cnt);
00077 if (wl_network_cnt == 0)
00078 gui_printk(1, "No networks found");
00079 else
00080 gui_printk(1, " ");
00081
00082 gui_network_cnt = wl_network_cnt > GUI_MAX_NETWORKS ? GUI_MAX_NETWORKS :
00083 wl_network_cnt;
00084
00085 memcpy(gui_network_list, wl_network_list,
00086 sizeof(struct wl_network_t) * gui_network_cnt);
00087
00088 for (i = 0; i < gui_network_cnt; i++) {
00089 struct wl_network_t* net = &gui_network_list[i];
00090 char print_buf[80];
00091 siprintf(print_buf, "%s (%ld) %s", ssid2str(&net->ssid),
00092 net->rssi, enc_type2str(net->enc_type));
00093 printk("%s\n", print_buf);
00094 gui_add_scroll_box_item(print_buf, strlen(print_buf));
00095 }
00096
00097 gui_inc_scroll_cursor();
00098 }
00099
00100
00101 static void set_wpa_key_cb(char *ascii_key, size_t len, void *ctx) {
00102 struct wl_network_t *net = ctx;
00103 char cmd[80];
00104
00105 if (NULL == ascii_key || 0 == len || NULL == ctx) {
00106 printk("%s : Failed to add pass phrase\n", __func__);
00107 gui_printk(1, "Failed to add pass phrase");
00108 return;
00109 }
00110
00111 sniprintf(cmd, sizeof cmd, "wpass %s %s", ssid2str(&net->ssid), ascii_key);
00112 printk("%s : \"%s\"\n", __func__, cmd);
00113 console_schedule_cmd(cmd, 1);
00114
00115 gui_printk(0, "Connecting ... ");
00116 gui_printk(1, " ");
00117 if ( WL_SUCCESS != wl_cm_set_network(&net->ssid, NULL) ) {
00118 printk("FAIL\n");
00119 }
00120 }
00121
00122 static void set_wep_key_cb(char *ascii_key, size_t len, void *ctx) {
00123 struct wl_network_t *net = ctx;
00124 char cmd[80];
00125
00126 if (NULL == ascii_key || 0 == len || NULL == ctx) {
00127 printk("%s : Failed to add wep key\n", __func__);
00128 gui_printk(1, "Failed to add key");
00129 return;
00130 }
00131
00132 sniprintf(cmd, sizeof cmd, "setkey 0 %s", ascii_key);
00133 printk("%s : \"%s\"\n", __func__, cmd);
00134 console_schedule_cmd(cmd, 1);
00135
00136 gui_printk(0, "Connecting ... ");
00137 gui_printk(1, " ");
00138 if ( WL_SUCCESS != wl_cm_set_network(&net->ssid, NULL) ) {
00139 printk("FAIL\n");
00140 }
00141 }
00142
00146 static void
00147 gui_connect_cb(void)
00148 {
00149 int index;
00150 struct wl_network_t* selected_net;
00151 struct wl_network_t* current_net = wl_get_current_network();
00152
00153 index = gui_scroll_idx() - 1;
00154 if (index < 0 || index > gui_network_cnt) {
00155 return;
00156 }
00157 selected_net = &gui_network_list[index];
00158 if (equal_bssid(&selected_net->bssid, ¤t_net->bssid)) {
00159 return;
00160 }
00161
00162 if (selected_net->enc_type != ENC_TYPE_NONE)
00163 {
00164 if (selected_net->enc_type == ENC_TYPE_WEP) {
00165
00166 gui_getstring(set_wep_key_cb, selected_net);
00167 }
00168 else {
00169 gui_getstring(set_wpa_key_cb, selected_net);
00170
00171 }
00172 }
00173 else {
00174 console_schedule_cmd("setkey none", 1);
00175 gui_printk(0, "Connecting ... ");
00176 gui_printk(1, " ");
00177 wl_cm_set_network(&selected_net->ssid, NULL);
00178 }
00179 }
00180
00181 #if BOARD == EVK1100
00182
00183 static void
00184 go_back_cb(void)
00185 {
00186 gui_restore_buttons();
00187 gui_infobox_onoff(FALSE);
00188 }
00189 #endif
00190
00194 void
00195 gui_status_up_cb(void)
00196 {
00197 struct wl_network_t *net = wl_get_current_network();
00198
00199 gui_printk(0, "Connected to \"%s\"", ssid2str(&net->ssid));
00200 gui_printk(1, "My ip address is %s", ip2str(netif_default->ip_addr));
00201 #if BOARD == EVK1100
00202 gui_save_buttons();
00203 gui_clear_infobox(0);
00204
00205 gui_add_infobox_item(ssid2str(&net->ssid), 0);
00206
00207 gui_add_infobox_item(ip2str(netif_default->ip_addr), 1);
00208 gui_infobox_onoff(TRUE);
00209 gui_set_button(0, "Back", sizeof "Back", go_back_cb);
00210 #endif
00211 }
00212
00213
00217 void gui_status_down_cb(void)
00218 {
00219
00220 }
00221
00222
00226 void gui_link_up_cb(void)
00227 {
00228 char str[WL_SSID_MAX_LENGTH + 1];
00229 struct wl_network_t *net = wl_get_current_network();
00230
00231 memset(str, 0, sizeof(str));
00232 strncpy(str, net->ssid.ssid, net->ssid.len);
00233 gui_printk(0, "Connected to \"%s\"", str);
00234 gui_printk(1, "Requesting dhcp ... ");
00235 }
00236
00237
00241 void gui_link_down_cb(void)
00242 {
00243 gui_printk(0, "Connecting ... ");
00244 gui_printk(1, " ");
00245 }
00246
00247
00251 void
00252 gui_start(void)
00253 {
00254 pm_freq_param_t pm_freq_param = {
00255 .cpu_f = FCPU_HZ,
00256 .pba_f = FPBA_HZ,
00257 .osc0_f = FOSC0,
00258 .osc0_startup = OSC0_STARTUP
00259 };
00260 gui_init(&pm_freq_param);
00261 gui_draw(1);
00262 gui_printk(0, "Disconnected");
00263 gui_set_button(0, "Scan", sizeof "Scan", gui_scan_cb);
00264 gui_set_button(1, "Connect", sizeof "Connect", gui_connect_cb);
00265 gui_set_button(2, "Up", sizeof "Up", gui_dec_scroll_cursor);
00266 gui_set_button(3, "Down", sizeof "Down", gui_inc_scroll_cursor);
00267 gui_clear_scroll_box();
00268 gui_set_bg_color(WHITE);
00269 gui_add_scroll_box_item("Scan Contents:", sizeof "Scan Contents:");
00270 }