-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc index 67dfc02..0d0f075 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |||
@@ -1,131 +1,130 @@ | |||
1 | /* | 1 | /* |
2 | * Communication protocol | 2 | * Communication protocol |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "wl_types.hh" | 7 | #include "wl_types.hh" |
8 | #include "wl_proto.hh" | 8 | #include "wl_proto.hh" |
9 | #include "wl_log.hh" | 9 | #include "wl_log.hh" |
10 | #include "wl_sock.hh" | 10 | #include "wl_sock.hh" |
11 | 11 | ||
12 | /* Adds a field to the buffer */ | 12 | /* Adds a field to the buffer */ |
13 | int add_field(char *buffer, const char *string, int len) | 13 | int add_field(char *buffer, const char *string, int len) |
14 | { | 14 | { |
15 | char newlen[5]; | 15 | char newlen[5]; |
16 | 16 | ||
17 | /* 3 Byte = Length */ | 17 | /* 3 Byte = Length */ |
18 | memset(newlen, 0, sizeof(newlen)); | 18 | memset(newlen, 0, sizeof(newlen)); |
19 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); | 19 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); |
20 | memcpy(buffer, newlen, 3); | 20 | memcpy(buffer, newlen, 3); |
21 | 21 | ||
22 | /* Length bytes = Value */ | 22 | /* Length bytes = Value */ |
23 | memcpy(buffer + 3, string, atoi(newlen)); | 23 | memcpy(buffer + 3, string, atoi(newlen)); |
24 | 24 | ||
25 | /* Return length of attached field */ | 25 | /* Return length of attached field */ |
26 | return (atoi(newlen) + 3); | 26 | return (atoi(newlen) + 3); |
27 | } | 27 | } |
28 | 28 | ||
29 | int get_field(const char *buffer, char *out, int maxlen) | 29 | int get_field(const char *buffer, char *out, int maxlen) |
30 | { | 30 | { |
31 | char len[5]; | 31 | char len[5]; |
32 | 32 | ||
33 | /* Get length of value */ | 33 | /* Get length of value */ |
34 | memset(len, 0, sizeof(len)); | 34 | memset(len, 0, sizeof(len)); |
35 | memcpy(len, buffer, 3); | 35 | memcpy(len, buffer, 3); |
36 | 36 | ||
37 | /* Copy buffer to out pointer */ | 37 | /* Copy buffer to out pointer */ |
38 | memset(out, 0, maxlen); | 38 | memset(out, 0, maxlen); |
39 | if(atoi(len) > maxlen -1) | 39 | if(atoi(len) > maxlen -1) |
40 | memcpy(out, buffer + 3, maxlen - 1); | 40 | memcpy(out, buffer + 3, maxlen - 1); |
41 | else | 41 | else |
42 | memcpy(out, buffer + 3, atoi(len)); | 42 | memcpy(out, buffer + 3, atoi(len)); |
43 | 43 | ||
44 | /* Return length of whole field (including 3 byte length) */ | 44 | /* Return length of whole field (including 3 byte length) */ |
45 | return (atoi(len) + 3); | 45 | return (atoi(len) + 3); |
46 | } | 46 | } |
47 | 47 | ||
48 | /* Send found network to UI */ | 48 | /* Send found network to UI */ |
49 | int send_network_found (const char *guihost, int guiport, void *structure) | 49 | int send_network_found (const char *guihost, int guiport, void *structure) |
50 | { | 50 | { |
51 | wl_network_t *ptr; | 51 | wl_network_t *ptr; |
52 | char buffer[2048], temp[5]; | 52 | char buffer[2048], temp[5]; |
53 | unsigned int len = 0; | 53 | unsigned int len = 0; |
54 | 54 | ||
55 | ptr = (wl_network_t *)structure; | 55 | ptr = (wl_network_t *)structure; |
56 | 56 | ||
57 | memcpy(buffer, 0, sizeof(buffer)); | 57 | memset(buffer,0,sizeof(buffer)); |
58 | |||
59 | /* Type = Found new net (without length field) */ | 58 | /* Type = Found new net (without length field) */ |
60 | memset(temp, 0, sizeof(temp)); | 59 | memset(temp, 0, sizeof(temp)); |
61 | snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); | 60 | snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); |
62 | memcpy(buffer, temp, 2); | 61 | memcpy(buffer, temp, 2); |
63 | len += 2; | 62 | len += 2; |
64 | 63 | ||
65 | /* Set Net-type */ | 64 | /* Set Net-type */ |
66 | memset(temp, 0, sizeof(temp)); | 65 | memset(temp, 0, sizeof(temp)); |
67 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); | 66 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); |
68 | len += add_field(buffer + len, temp, 1); | 67 | len += add_field(buffer + len, temp, 1); |
69 | 68 | ||
70 | /* Set channel */ | 69 | /* Set channel */ |
71 | memset(temp, 0, sizeof(temp)); | 70 | memset(temp, 0, sizeof(temp)); |
72 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); | 71 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); |
73 | len += add_field(buffer + len, temp, 2); | 72 | len += add_field(buffer + len, temp, 2); |
74 | 73 | ||
75 | /* Set WEP y/n */ | 74 | /* Set WEP y/n */ |
76 | memset(temp, 0, sizeof(temp)); | 75 | memset(temp, 0, sizeof(temp)); |
77 | snprintf(temp, sizeof(temp), "%d", ptr->wep); | 76 | snprintf(temp, sizeof(temp), "%d", ptr->wep); |
78 | len += add_field(buffer + len, temp, 1); | 77 | len += add_field(buffer + len, temp, 1); |
79 | 78 | ||
80 | /* Set Mac */ | 79 | /* Set Mac */ |
81 | len += add_field(buffer + len, ptr->mac, 17); | 80 | len += add_field(buffer + len, ptr->mac, 17); |
82 | 81 | ||
83 | /* Set ssid */ | 82 | /* Set ssid */ |
84 | if(len + ptr->ssid_len < sizeof(buffer) - 1) | 83 | if(len + ptr->ssid_len < sizeof(buffer) - 1) |
85 | len += add_field(buffer + len, ptr->bssid, ptr->ssid_len); | 84 | len += add_field(buffer + len, ptr->bssid, ptr->ssid_len); |
86 | else | 85 | else |
87 | len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1); | 86 | len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1); |
88 | 87 | ||
89 | /* Send prepared buffer to UI */ | 88 | /* Send prepared buffer to UI */ |
90 | #ifdef DEBUG | 89 | #ifdef DEBUG |
91 | wl_loginfo("Sending network to UI: '%s'", buffer); | 90 | wl_loginfo("Sending network to UI: '%s'", buffer); |
92 | #endif | 91 | #endif |
93 | 92 | ||
94 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | 93 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); |
95 | } | 94 | } |
96 | 95 | ||
97 | /* Fill buffer into structur */ | 96 | /* Fill buffer into structur */ |
98 | int get_network_found (void *structure, const char *buffer) | 97 | int get_network_found (void *structure, const char *buffer) |
99 | { | 98 | { |
100 | wl_network_t *ptr; | 99 | wl_network_t *ptr; |
101 | char temp[5]; | 100 | char temp[5]; |
102 | unsigned int len = 0; | 101 | unsigned int len = 0; |
103 | 102 | ||
104 | ptr = (wl_network_t *)structure; | 103 | ptr = (wl_network_t *)structure; |
105 | 104 | ||
106 | /* packet type already determined, skip check */ | 105 | /* packet type already determined, skip check */ |
107 | len += 2; | 106 | len += 2; |
108 | 107 | ||
109 | /* Get net type (accesspoint || ad-hoc || ...) */ | 108 | /* Get net type (accesspoint || ad-hoc || ...) */ |
110 | memset(temp, 0, sizeof(temp)); | 109 | memset(temp, 0, sizeof(temp)); |
111 | len += get_field(buffer + len, temp, sizeof(temp)); | 110 | len += get_field(buffer + len, temp, sizeof(temp)); |
112 | ptr->net_type = atoi(temp); | 111 | ptr->net_type = atoi(temp); |
113 | 112 | ||
114 | /* Get channel */ | 113 | /* Get channel */ |
115 | memset(temp, 0, sizeof(temp)); | 114 | memset(temp, 0, sizeof(temp)); |
116 | len += get_field(buffer + len, temp, sizeof(temp)); | 115 | len += get_field(buffer + len, temp, sizeof(temp)); |
117 | ptr->channel = atoi(temp); | 116 | ptr->channel = atoi(temp); |
118 | 117 | ||
119 | /* Set WEP y/n */ | 118 | /* Set WEP y/n */ |
120 | memset(temp, 0, sizeof(temp)); | 119 | memset(temp, 0, sizeof(temp)); |
121 | len += get_field(buffer + len, temp, sizeof(temp)); | 120 | len += get_field(buffer + len, temp, sizeof(temp)); |
122 | ptr->wep = atoi(temp); | 121 | ptr->wep = atoi(temp); |
123 | 122 | ||
124 | /* Set MAC address */ | 123 | /* Set MAC address */ |
125 | len += get_field(buffer + len, ptr->mac, sizeof(ptr->mac)); | 124 | len += get_field(buffer + len, ptr->mac, sizeof(ptr->mac)); |
126 | 125 | ||
127 | /* Set BSSID */ | 126 | /* Set BSSID */ |
128 | len += get_field(buffer + len, ptr->bssid, sizeof(ptr->bssid)); | 127 | len += get_field(buffer + len, ptr->bssid, sizeof(ptr->bssid)); |
129 | 128 | ||
130 | return 1; | 129 | return 1; |
131 | } | 130 | } |