]> git.decadent.org.uk Git - ap-utils.git/blobdiff - src/stations.c
Imported Upstream version 1.4.2~pre2~a
[ap-utils.git] / src / stations.c
index 2c435d092523af249b69200c0916c9ddde692544..5eb272d3815f08c7e6f9a625abc0418c9a8f94e6 100644 (file)
 #include "ap-curses.h"
 
 #define STAS _("Associated Stations")
+#define STAS_HEADER \
+       _(" #            MAC                                               ")
+/* following for VERNET-enhanced ATMEL12350 MIB */
+#define STAS_HEADER_VERNET \
+       _(" #     MAC       Parent MAC    RSSI  Status MACn      IP        ")
 
 #define MAX_LINES LINES-4
 
 extern int LINES;
 extern WINDOW *main_sub;
 extern short ap_type;
+extern char IS_ATMEL12350_VERNET;
+extern int sts_viewtype;
 
 void stations()
 {
+    char bridgeOperationalMode[] = {
+       0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
+    };
+    char StasNum[] = {
+       0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, 0x00
+    };
+    char StasMac[] = {
+       0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02, 0x00
+    };
+
     struct AssociatedSTAsInfo {
        unsigned short Num;
        unsigned char MacAddress[6];
+       /* following ones are specific for enhanced ATMEL 12350 MIB by VERNET */
+       unsigned char Status;
+       unsigned char Port;
+       unsigned char ParentMacAddress[6];
+       unsigned char RSSI;
+       unsigned char IP[4];
     } *mac = NULL, get;
-    char StasNum[] =
-       { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01,
-       0x00
-    };
-
-    char StasMac[] =
-       { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02,
-       0x00
-    };
 
-    char bridgeOperationalMode[] = {
-               0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
-    };
-       
-    
     struct MacListStat *first = NULL, *curr = NULL;
     char message[1024];
-    int mac_num, begin, end, total_mac;
+    int mac_idx, begin, end, total_mac;
     varbind varbinds[1];
 
-  
+
     if (ap_type == ATMEL12350) {
+        bridgeOperationalMode[5] = 0xE0;
+       bridgeOperationalMode[6] = 0x3E;
        StasNum[5] = 0xE0;
        StasNum[6] = 0x3E;
        StasMac[5] = 0xE0;
        StasMac[6] = 0x3E;
-        bridgeOperationalMode[5] = 0xE0;
-       bridgeOperationalMode[6] = 0x3E;
     }  
 
-    print_title(STAS);
-
+    /* find out in what mode the AP currently is */
     varbinds[0].oid = bridgeOperationalMode;
     varbinds[0].len_oid = sizeof(bridgeOperationalMode);
     varbinds[0].value = bridgeOperationalMode;
@@ -83,22 +91,34 @@ void stations()
          goto exit;
     }
 
-    if (*(varbinds[0].value) == 3) {
-           mvwaddstr(main_sub, 3, 1, _("AP now in AP Client Mode and don't has any associated stations"));
-           print_help(ANY_KEY);
-           wrefresh(main_sub);
-           getch();
-           goto exit;
+    /* for AP in AP-Client mode & without VERNET firmware, disable status */
+    if (*(varbinds[0].value) == 3 && !IS_ATMEL12350_VERNET) {
+       mvwaddstr(main_sub, 3, 1, _("AP is currently in AP Client Mode => "
+           "no associated STAtions."));
+       print_help(ANY_KEY);
+       wrefresh(main_sub);
+       getch();
+       goto exit;
     }
 
-                           
-
+    noecho();
+    wattrset(main_sub, COLOR_PAIR(3));
+    if (IS_ATMEL12350_VERNET)
+       mvwaddstr(main_sub, 0, 0, STAS_HEADER_VERNET);
+    else
+       mvwaddstr(main_sub, 0, 0, STAS_HEADER);
+    wattrset(main_sub, A_NORMAL);
+
+refresh:
+    /* find out how many STAtions is in the list */
     varbinds[0].oid = StasNum;
     varbinds[0].len_oid = sizeof(StasNum);
     varbinds[0].value = StasNum;
     varbinds[0].type = NULL_VALUE;
     varbinds[0].len_val = 0;
+
     print_help(WAIT_RET);
+
     if (snmp(varbinds, 1, GET) <= 0) {
        print_helperr(ERR_RET);
        getch();
@@ -106,19 +126,15 @@ void stations()
     }
 
     total_mac = *(varbinds[0].value);
-    mac_num = 1;
-
-    sprintf(message, "%s: %d", STAS, total_mac);
-    print_title(message);
-    mvwaddstr(main_sub, 0, 3, _("Id       MAC address"));
-    noecho();
-
-    while (mac_num <= total_mac) {
+    print_help(WAIT_SET);
+    mac_idx = 1;
+    while (mac_idx <= total_mac) {
 
+       /* tell the AP we want first mac_idx-th MAC */
        varbinds[0].oid = StasMac;
        varbinds[0].len_oid = sizeof(StasMac);
        varbinds[0].type = INT_VALUE;
-       get.Num = swap2(mac_num);
+       get.Num = swap2(mac_idx);
        varbinds[0].value = (char *) &get;
        varbinds[0].len_val = sizeof(get);
 
@@ -134,13 +150,12 @@ void stations()
            mac =
                (struct AssociatedSTAsInfo *) malloc(varbinds[0].len_val);
            memcpy(mac, varbinds[0].value, varbinds[0].len_val);
-/*         mac = (struct AssociatedSTAsInfo *) varbinds[0].value;*/
+           /* mac = (struct AssociatedSTAsInfo *) varbinds[0].value; */
        } else {
            print_helperr(_("AssociatedSTAsInfo packet error"));
            goto exit;
        }
 
-
        if (first == NULL) {
            first =
                (struct MacListStat *) malloc(sizeof(struct MacListStat));
@@ -152,42 +167,80 @@ void stations()
        }
 
        memcpy(curr->addr, mac->MacAddress, 6);
+
+       if (IS_ATMEL12350_VERNET) {
+           curr->Status = mac->Status;
+           curr->Port = mac->Port;
+           memcpy(curr->ParentMacAddress, mac->ParentMacAddress, 6);
+           curr->rssi = mac->RSSI;
+           memcpy(&(curr->IP.s_addr), mac->IP, 4);
+       }
+
        curr->next = NULL;
-       mac_num++;
+       mac_idx++;
     }
+
     begin = 1;
-    end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
-    scroll_rows(first, begin, end, 1, 0);
-    print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
+    end = (MAX_LINES < mac_idx) ? MAX_LINES : mac_idx;
+
+    if (IS_ATMEL12350_VERNET)
+       print_help(_("Arrows - scroll; S - save to file; Q - return; "
+                    "T - toggle view; Other key - refresh"));
+    else
+       print_help(_("Arrows - scroll; S - save to file; Q - return; "
+                    "Other key - refresh"));
+
     while (1) {
+       sprintf(message, "%s: %d", STAS, total_mac);
+       print_title(message);
+
+       if (IS_ATMEL12350_VERNET) {
+           print_viewtype_rssi();
+           scroll_rows(first, begin, end, 1, 3);
+       } else
+           scroll_rows(first, begin, end, 1, 0);
+
        switch (getch()) {
-       case 'S':
-       case 's':
-           save_Stations(first);
-           continue;
-       case KEY_RIGHT:
-       case KEY_DOWN:
-           if (end < mac_num) {
-               begin++;
-               end++;
-               scroll_rows(first, begin, end, 1, 0);
-           }
-           continue;
-       case KEY_UP:
-       case KEY_LEFT:
-           if (begin > 1) {
-               begin--;
-               end--;
-               scroll_rows(first, begin, end, 1, 0);
-           }
-           continue;
-       case 'Q':
-       case 'q':
-           goto exit;
+           case 'S':
+           case 's':
+               save_Stations(first);
+               continue;
+           case KEY_RIGHT:
+           case KEY_DOWN:
+               if (end < mac_idx) {
+                   begin++;
+                   end++;
+               }
+               continue;
+           case KEY_UP:
+           case KEY_LEFT:
+               if (begin > 1) {
+                   begin--;
+                   end--;
+               }
+               continue;
+           case 'Q':
+           case 'q':
+               goto exit;
+           case 'T':
+           case 't':
+               if (IS_ATMEL12350_VERNET) {
+                   sts_viewtype += 1;
+                   if (sts_viewtype == 3)
+                       sts_viewtype = 0;
+               }
+               continue;
+           default:
+               while ((curr = first)) {
+                   first = curr->next;
+                   free(curr);
+               }
+               first = curr = NULL;
+               goto refresh;
        }
     }
 
-  exit:
+exit:
     while ((curr = first)) {
        first = curr->next;
        free(curr);
@@ -198,28 +251,27 @@ void stations()
 
 void nwn_stations()
 {
-    unsigned char Mac[] =
-       0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
+    unsigned char Mac[] = {
+       0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
        0x02, 0x01, 0x02, 0x80, 0x00 };
-
-    unsigned char Quality[] =
-       { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
-       0x02, 0x01, 0x03, 0x80, 0x00  };
-    unsigned char Age[] =
-       { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
-       0x02, 0x01, 0x04, 0x80, 0x00    };
-    unsigned char RSSI[] =
-       { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
-       0x02, 0x01, 0x05, 0x80, 0x00    };
+    unsigned char Quality[] = {
+       0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
+       0x02, 0x01, 0x03, 0x80, 0x00 };
+    unsigned char Age[] = {
+       0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
+       0x02, 0x01, 0x04, 0x80, 0x00 };
+    unsigned char RSSI[] = {
+       0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
+       0x02, 0x01, 0x05, 0x80, 0x00 };
 
     struct MacListStat *first = NULL, *curr = NULL;
     char null[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, message[1024];
-    int mac_num, begin, end;
+    int mac_idx, begin, end;
     varbind varbinds[4];
     unsigned char next_num;
 
 
-    mac_num = 0;
+    mac_idx = 0;
     print_title(_("Associated stations"));
     mvwaddstr(main_sub, 0, 3,
              _("Id       MAC address     Quality  Age  RSSI"));
@@ -272,7 +324,6 @@ void nwn_stations()
            goto exit;
        }
 
-
        if (memcmp(null, varbinds[0].value, 6)) {
            if (first == NULL) {
                first =
@@ -285,12 +336,12 @@ void nwn_stations()
                    malloc(sizeof(struct MacListStat));
                curr = curr->next;
            } 
-               memcpy(curr->addr, varbinds[0].value, 6);
-               curr->quality = *varbinds[1].value;
-               curr->idle = *varbinds[2].value;
-               curr->rssi = *varbinds[3].value;
-               curr->next = NULL;
-               mac_num++;
+           memcpy(curr->addr, varbinds[0].value, 6);
+           curr->quality = *varbinds[1].value;
+           curr->idle = *varbinds[2].value;
+           curr->rssi = *varbinds[3].value;
+           curr->next = NULL;
+           mac_idx++;
        }
 
        varbinds[0].oid = Mac;
@@ -304,11 +355,11 @@ void nwn_stations()
        next_num = varbinds[0].oid[varbinds[0].len_oid - 1];
                                                
     }
-   sprintf(message, "%s: %d", _("Associated stations"), mac_num);
+   sprintf(message, "%s: %d", _("Associated stations"), mac_idx);
    print_title(message);
-   if(mac_num) {
+   if(mac_idx) {
     begin = 1;
-    end = (MAX_LINES < mac_num+1) ? MAX_LINES : mac_num+1;
+    end = (MAX_LINES < mac_idx+1) ? MAX_LINES : mac_idx+1;
     scroll_rows(first, begin, end, 1, 1);
     print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
     while (1) {
@@ -319,7 +370,7 @@ void nwn_stations()
            continue;
        case KEY_DOWN:
        case KEY_RIGHT:
-           if (end < mac_num+1) {
+           if (end < mac_idx+1) {
                begin++;
                end++;
                scroll_rows(first, begin, end, 1, 1);