-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | 103 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh | 14 |
2 files changed, 107 insertions, 10 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc index 0d0f075..dcdc16b 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |||
@@ -10,7 +10,7 @@ | |||
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 | unsigned int add_field(char *buffer, const char *string, int len) |
14 | { | 14 | { |
15 | char newlen[5]; | 15 | char newlen[5]; |
16 | 16 | ||
@@ -26,7 +26,7 @@ int add_field(char *buffer, const char *string, int len) | |||
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 | unsigned int get_field(const char *buffer, char *out, int maxlen) |
30 | { | 30 | { |
31 | char len[5]; | 31 | char len[5]; |
32 | 32 | ||
@@ -45,6 +45,97 @@ int get_field(const char *buffer, char *out, int maxlen) | |||
45 | return (atoi(len) + 3); | 45 | return (atoi(len) + 3); |
46 | } | 46 | } |
47 | 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 len) | ||
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, len); | ||
133 | len += get_field(buffer + len, out, len - 1); | ||
134 | |||
135 | return error; | ||
136 | } | ||
137 | |||
138 | |||
48 | /* Send found network to UI */ | 139 | /* Send found network to UI */ |
49 | int send_network_found (const char *guihost, int guiport, void *structure) | 140 | int send_network_found (const char *guihost, int guiport, void *structure) |
50 | { | 141 | { |
@@ -57,23 +148,23 @@ int send_network_found (const char *guihost, int guiport, void *structure) | |||
57 | memset(buffer,0,sizeof(buffer)); | 148 | memset(buffer,0,sizeof(buffer)); |
58 | /* Type = Found new net (without length field) */ | 149 | /* Type = Found new net (without length field) */ |
59 | memset(temp, 0, sizeof(temp)); | 150 | memset(temp, 0, sizeof(temp)); |
60 | snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); | 151 | snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND); |
61 | memcpy(buffer, temp, 2); | 152 | memcpy(buffer, temp, 2); |
62 | len += 2; | 153 | len += 2; |
63 | 154 | ||
64 | /* Set Net-type */ | 155 | /* Set Net-type */ |
65 | memset(temp, 0, sizeof(temp)); | 156 | memset(temp, 0, sizeof(temp)); |
66 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); | 157 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type); |
67 | len += add_field(buffer + len, temp, 1); | 158 | len += add_field(buffer + len, temp, 1); |
68 | 159 | ||
69 | /* Set channel */ | 160 | /* Set channel */ |
70 | memset(temp, 0, sizeof(temp)); | 161 | memset(temp, 0, sizeof(temp)); |
71 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); | 162 | snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel); |
72 | len += add_field(buffer + len, temp, 2); | 163 | len += add_field(buffer + len, temp, 2); |
73 | 164 | ||
74 | /* Set WEP y/n */ | 165 | /* Set WEP y/n */ |
75 | memset(temp, 0, sizeof(temp)); | 166 | memset(temp, 0, sizeof(temp)); |
76 | snprintf(temp, sizeof(temp), "%d", ptr->wep); | 167 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep); |
77 | len += add_field(buffer + len, temp, 1); | 168 | len += add_field(buffer + len, temp, 1); |
78 | 169 | ||
79 | /* Set Mac */ | 170 | /* Set Mac */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh index 46ef8e5..63ac53b 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh | |||
@@ -8,13 +8,19 @@ | |||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | 9 | ||
10 | /* Type definitions, to be continued */ | 10 | /* Type definitions, to be continued */ |
11 | #define NETFOUND 01 | 11 | #define NETFOUND 01 |
12 | #define NETLOST 02 | 12 | #define NETLOST 02 |
13 | #define CMD_FAIL 50 | ||
14 | #define CMD_OK 51 | ||
13 | #define STARTSNIFF 98 | 15 | #define STARTSNIFF 98 |
14 | #define STOPSNIFF 99 | 16 | #define STOPSNIFF 99 |
15 | 17 | ||
16 | int add_field(char *, const char *, int); | 18 | unsigned int add_field(char *, const char *, int); |
17 | int get_field(const char *, char *, int); | 19 | unsigned int get_field(const char *, char *, int); |
20 | int send_ok(const char *, int, int); | ||
21 | int get_ok(const char *); | ||
22 | int send_fail(const char *, int, int, const char *); | ||
23 | int get_fail(char *, const char *, size_t); | ||
18 | int send_network_found (const char *, int, void *); | 24 | int send_network_found (const char *, int, void *); |
19 | int get_network_found (void *, const char *); | 25 | int get_network_found (void *, const char *); |
20 | 26 | ||