-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/proto.cc | 104 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/proto.hh | 28 |
2 files changed, 132 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc new file mode 100644 index 0000000..359bdb5 --- a/dev/null +++ b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc @@ -0,0 +1,104 @@ +/* + * Communication protocol + * + * $Id$ + */ + +#include "proto.hh" +#include "sock.hh" + +/* Send found network to GUI */ +int send_network_found (const char *guihost, int guiport, void *structure) +{ + wl_network_t *ptr; + char buffer[2048]; + char temp[4]; + + ptr = (wl_network_t *)structure; + + memset(buffer, 0, 2048); + + /* Type = Found new net */ + memcpy(buffer, "01", 2); + + /* Set Net-type */ + memset(temp, 0, sizeof(temp)); + snprintf(temp, 2, "%d", ptr->net_type); + memcpy(buffer + 2, temp, 1); + + /* Set channel */ + memset(temp, 0, sizeof(temp)); + + if(ptr->channel < 10) + snprintf(temp, 3, "0%d", ptr->channel); + else + snprintf(temp, 3, "%d", ptr->channel); + + memcpy(buffer + 3, temp, 2); + + /* Set WEP y/n */ + memset(temp, 0, sizeof(temp)); + snprintf(temp, 2, "%d", ptr->wep); + memcpy(buffer + 5, temp, 1); + + /* Set MAC address */ + memcpy(buffer + 6, ptr->mac, 17); + + /* Set lenght of ssid */ + memset(temp, 0, sizeof(temp)); + + if(ptr->ssid_len > 99) + snprintf(temp, 4, "%d", ptr->ssid_len); + else if(ptr->ssid_len < 10) + snprintf(temp, 4, "00%d", ptr->ssid_len); + else + snprintf(temp, 4, "0%d", ptr->ssid_len); + + memcpy(buffer + 23, temp, 3); + + /* Set ssid */ + memcpy(buffer + 26, ptr->bssid, ptr->ssid_len); + + /* Send prepared buffer to GUI */ + sendcomm(guihost, guiport, buffer); + + return 1; +} + +/* Fill buffer into structur */ +int get_network_found (void *structure, const char *buffer) +{ + wl_network_t *ptr; + char temp[512]; + + ptr = (wl_network_t *)structure; + + /* Get net type */ + memset(temp, 0, sizeof(temp)); + memcpy(temp, buffer + 2, 1); + ptr->net_type = atoi(temp); + + /* Get channel */ + memset(temp, 0, sizeof(temp)); + memcpy(temp, buffer + 3, 2); + ptr->channel = atoi(temp); + + /* Set WEP y/n */ + memset(temp, 0, sizeof(temp)); + memcpy(temp, buffer + 5, 1); + ptr->wep = atoi(temp); + + /* Set MAC address */ + memcpy(ptr->mac, buffer + 6, 17); + ptr->mac[17]='\0'; + + /* Set lenght of ssid */ + memset(temp, 0, sizeof(temp)); + memcpy(temp, buffer + 23, 3); + ptr->ssid_len = atoi(temp); + + /* Set ssid */ + memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1); + + return 1; +} diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/proto.hh new file mode 100644 index 0000000..e3e9f50 --- a/dev/null +++ b/noncore/net/wellenreiter/libwellenreiter/source/proto.hh @@ -0,0 +1,28 @@ +/* $Id$ */ + +#ifndef PROTO_HH +#define PROTO_HH + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +/* Type definitions, to be continued */ +#define NETFOUND 01 +#define NETLOST 02 +#define STARTSNIFF 98 +#define STOPSNIFF 99 + +int send_network_found (const char *, int, void *); +int get_network_found (void *, const char *); + +typedef struct { + int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ + int ssid_len; /* Length of SSID */ + int channel; /* Channel */ + int wep; /* 1 = WEP enabled ; 0 = disabled */ + char mac[64]; /* MAC address of Accesspoint */ + char bssid[128]; /* BSSID of Accesspoint */ +} wl_network_t; + +#endif /* PROTO_HH */ |