author | mickeyl <mickeyl> | 2003-03-30 01:51:14 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-30 01:51:14 (UTC) |
commit | d11a0154e2d9732854c9a3d598857bc20f359849 (patch) (unidiff) | |
tree | af0e0273d01f4f6c64c9f230f22bb91a7a8a21d8 /noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |
parent | 99899abc80a8aa05044eeecd8a061b0a8efaa713 (diff) | |
download | opie-d11a0154e2d9732854c9a3d598857bc20f359849.zip opie-d11a0154e2d9732854c9a3d598857bc20f359849.tar.gz opie-d11a0154e2d9732854c9a3d598857bc20f359849.tar.bz2 |
- the network work for libopie2 pays off...
- good bye to wellenreiterd, t'was fun but always too unstable and too hard to maintain
- good bye to libwellenreiter
Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc deleted file mode 100644 index 6c3846f..0000000 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | /* | ||
2 | * Communication protocol | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "wl_types.hh" | ||
8 | #include "wl_proto.hh" | ||
9 | #include "wl_log.hh" | ||
10 | #include "wl_sock.hh" | ||
11 | |||
12 | /* Adds a field to the buffer */ | ||
13 | unsigned int add_field(char *buffer, const char *string, int len) | ||
14 | { | ||
15 | char newlen[5]; | ||
16 | |||
17 | /* 3 Byte = Length */ | ||
18 | memset(newlen, 0, sizeof(newlen)); | ||
19 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); | ||
20 | memcpy(buffer, newlen, 3); | ||
21 | |||
22 | /* Length bytes = Value */ | ||
23 | memcpy(buffer + 3, string, atoi(newlen)); | ||
24 | |||
25 | /* Return length of attached field */ | ||
26 | return (atoi(newlen) + 3); | ||
27 | } | ||
28 | |||
29 | unsigned int get_field(const char *buffer, char *out, int maxlen) | ||
30 | { | ||
31 | char len[5]; | ||
32 | |||
33 | /* Get length of value */ | ||
34 | memset(len, 0, sizeof(len)); | ||
35 | memcpy(len, buffer, 3); | ||
36 | |||
37 | /* Copy buffer to out pointer */ | ||
38 | memset(out, 0, maxlen); | ||
39 | if(atoi(len) > maxlen -1) | ||
40 | memcpy(out, buffer + 3, maxlen - 1); | ||
41 | else | ||
42 | memcpy(out, buffer + 3, atoi(len)); | ||
43 | |||
44 | /* Return length of whole field (including 3 byte length) */ | ||
45 | return (atoi(len) + 3); | ||
46 | } | ||
47 | |||
48 | /* Send ok message */ | ||
49 | int send_ok(const char *guihost, int guiport, int code) | ||
50 | { | ||
51 | unsigned int len = 0; | ||
52 | char buffer[128], temp[5]; | ||
53 | |||
54 | memset(buffer, 0, sizeof(buffer)); | ||
55 | |||
56 | memset(temp, 0, sizeof(temp)); | ||
57 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_OK); | ||
58 | memcpy(buffer, temp, 2); | ||
59 | len += 2; | ||
60 | |||
61 | memset(temp, 0, sizeof(temp)); | ||
62 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); | ||
63 | len += add_field(buffer + len, temp, 2); | ||
64 | |||
65 | /* Send prepared buffer to UI */ | ||
66 | #ifdef DEBUG | ||
67 | wl_loginfo("Sent ok to UI: '%s'", buffer); | ||
68 | #endif | ||
69 | |||
70 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | ||
71 | } | ||
72 | |||
73 | /* Send fail message */ | ||
74 | int send_fail(const char *guihost, int guiport, | ||
75 | int code, const char *errstr) | ||
76 | { | ||
77 | unsigned int len = 0; | ||
78 | char buffer[128], temp[5]; | ||
79 | |||
80 | memset(buffer, 0, sizeof(buffer)); | ||
81 | |||
82 | memset(temp, 0, sizeof(temp)); | ||
83 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_FAIL); | ||
84 | memcpy(buffer, temp, 2); | ||
85 | len += 2; | ||
86 | |||
87 | memset(temp, 0, sizeof(temp)); | ||
88 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); | ||
89 | len += add_field(buffer + len, temp, 2); | ||
90 | |||
91 | len += add_field(buffer + len, errstr, strlen(errstr)); | ||
92 | |||
93 | /* Send prepared buffer to UI */ | ||
94 | #ifdef DEBUG | ||
95 | wl_loginfo("Send CMD_FAIL to UI: '%s'", buffer); | ||
96 | #endif | ||
97 | |||
98 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | ||
99 | } | ||
100 | |||
101 | int get_ok(const char *buffer) | ||
102 | { | ||
103 | char temp[5]; | ||
104 | unsigned int len = 0; | ||
105 | |||
106 | /* packet type already determined, skip check */ | ||
107 | len += 2; | ||
108 | |||
109 | /* what is ok for? */ | ||
110 | memset(temp, 0, sizeof(temp)); | ||
111 | len += get_field(buffer + len, temp, sizeof(temp)); | ||
112 | |||
113 | return atoi(temp); | ||
114 | } | ||
115 | |||
116 | /* put failmessage into buffer */ | ||
117 | int get_fail(char *out, const char *buffer, size_t bufflen) | ||
118 | { | ||
119 | char temp[5]; | ||
120 | int error=0; | ||
121 | unsigned int len = 0; | ||
122 | |||
123 | /* packet type already determined, skip check */ | ||
124 | len += 2; | ||
125 | |||
126 | /* what is fail for? */ | ||
127 | memset(temp, 0, sizeof(temp)); | ||
128 | len += get_field(buffer + len, temp, sizeof(temp)); | ||
129 | error=atoi(temp); | ||
130 | |||
131 | /* get errorstring and fill into buffer */ | ||
132 | memset(out, 0, bufflen); | ||
133 | len += get_field(buffer + len, out, bufflen - 1); | ||
134 | |||
135 | return error; | ||
136 | } | ||
137 | |||
138 | |||
139 | /* Send found network to UI */ | ||
140 | int send_network_found (const char *guihost, int guiport, void *structure) | ||
141 | { | ||
142 | wl_network_t *ptr; | ||
143 | char buffer[2048], temp[5]; | ||
144 | unsigned int len = 0; | ||
145 | |||
146 | ptr = (wl_network_t *)structure; | ||
147 | |||
148 | memset(buffer,0,sizeof(buffer)); | ||
149 | /* Type = Found new net (without length field) */ | ||
150 | memset(temp, 0, sizeof(temp)); | ||
151 | snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND); | ||
152 | memcpy(buffer, temp, 2); | ||
153 | len += 2; | ||
154 | |||
155 | /* Set Net-type */ | ||
156 | memset(temp, 0, sizeof(temp)); | ||
157 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type); | ||
158 | len += add_field(buffer + len, temp, 1); | ||
159 | |||
160 | /* Set channel */ | ||
161 | memset(temp, 0, sizeof(temp)); | ||
162 | snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel); | ||
163 | len += add_field(buffer + len, temp, 2); | ||
164 | |||
165 | /* Set WEP y/n */ | ||
166 | memset(temp, 0, sizeof(temp)); | ||
167 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep); | ||
168 | len += add_field(buffer + len, temp, 1); | ||
169 | |||
170 | /* Set Mac */ | ||
171 | len += add_field(buffer + len, ptr->mac, 17); | ||
172 | |||
173 | /* Set ssid */ | ||
174 | if(len + ptr->ssid_len < sizeof(buffer) - 1) | ||
175 | len += add_field(buffer + len, ptr->bssid, ptr->ssid_len); | ||
176 | else | ||
177 | len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1); | ||
178 | |||
179 | /* Send prepared buffer to UI */ | ||
180 | #ifdef DEBUG | ||
181 | wl_loginfo("Sending network to UI: '%s'", buffer); | ||
182 | #endif | ||
183 | |||
184 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | ||
185 | } | ||
186 | |||
187 | /* Fill buffer into structur */ | ||
188 | int get_network_found (void *structure, const char *buffer) | ||
189 | { | ||
190 | wl_network_t *ptr; | ||
191 | char temp[5]; | ||
192 | unsigned int len = 0; | ||
193 | |||
194 | ptr = (wl_network_t *)structure; | ||
195 | |||
196 | /* packet type already determined, skip check */ | ||
197 | len += 2; | ||
198 | |||
199 | /* Get net type (accesspoint || ad-hoc || ...) */ | ||
200 | memset(temp, 0, sizeof(temp)); | ||
201 | len += get_field(buffer + len, temp, sizeof(temp)); | ||
202 | ptr->net_type = atoi(temp); | ||
203 | |||
204 | /* Get channel */ | ||
205 | memset(temp, 0, sizeof(temp)); | ||
206 | len += get_field(buffer + len, temp, sizeof(temp)); | ||
207 | ptr->channel = atoi(temp); | ||
208 | |||
209 | /* Set WEP y/n */ | ||
210 | memset(temp, 0, sizeof(temp)); | ||
211 | len += get_field(buffer + len, temp, sizeof(temp)); | ||
212 | ptr->wep = atoi(temp); | ||
213 | |||
214 | /* Set MAC address */ | ||
215 | len += get_field(buffer + len, ptr->mac, sizeof(ptr->mac)); | ||
216 | |||
217 | /* Set BSSID */ | ||
218 | len += get_field(buffer + len, ptr->bssid, sizeof(ptr->bssid)); | ||
219 | |||
220 | return 1; | ||
221 | } | ||