Skip to content

Commit 51c5bd7

Browse files
committed
Add mirroring web-calls
1 parent 2008d49 commit 51c5bd7

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

httpd/httpd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ void httpd_appcall(void)
441441
send_counters(q[19]-'0');
442442
} else if (is_word(q, "/eee.json")) {
443443
send_eee();
444+
} else if (is_word(q, "/mirror.json")) {
445+
send_mirror();
444446
} else {
445447
send_not_found();
446448
}

httpd/page_impl.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,45 @@ void send_counters(char port)
217217
}
218218

219219

220-
void send_eee()
220+
void send_mirror(void)
221+
{
222+
print_string("send_eee called\n");
223+
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
224+
print_string("sending EEE status\n");
225+
226+
reg_read_m(RTL837x_MIRROR_CTRL);
227+
uint8_t mPort = sfr_data[3];
228+
if (mPort & 1) {
229+
slen += strtox(outbuf + slen, "{\"enabled\":1,\"mPort\":");
230+
} else {
231+
slen += strtox(outbuf + slen, "{\"enabled\":0,\"mPort\":");
232+
}
233+
if (!isRTL8373)
234+
itoa_html(log_to_phys_port[mPort >> 1]);
235+
else
236+
itoa_html((mPort >> 1) + 1);
237+
238+
reg_read_m(RTL837x_MIRROR_CONF);
239+
uint16_t m = sfr_data[0];
240+
m = (m << 8) | sfr_data[1];
241+
slen += strtox(outbuf + slen, ",\"mirror_rx\":\"");
242+
for (uint8_t i = 0; i < 16; i++) {
243+
bool_to_html(m & 0x8000);
244+
m <<= 1;
245+
}
246+
m = sfr_data[2];
247+
m = (m << 8) | sfr_data[3];
248+
slen += strtox(outbuf + slen, "\",\"mirror_tx\":\"");
249+
for (uint8_t i = 0; i < 16; i++) {
250+
bool_to_html(m & 0x8000);
251+
m <<= 1;
252+
}
253+
char_to_html('\"');
254+
char_to_html('}');
255+
}
256+
257+
258+
void send_eee(void)
221259
{
222260
print_string("send_eee called\nsending EEE status\n");
223261
slen = strtox(outbuf, HTTP_RESPONCE_JSON);

httpd/page_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ void send_status(void);
66
void send_vlan(register uint16_t vlan);
77
void send_basic_info(void);
88
void send_eee(void);
9+
void send_mirror(void);
910

1011
#endif

tools/httpd_sim.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ void send_eee(int s)
146146
char *header = "HTTP/1.1 200 OK\r\n"
147147
"Content-Type: application/json; charset=UTF-8\r\n\r\n";
148148

149-
time_t now = time(NULL);
150-
now = last_called ? last_called + 1 : now; // Make sure we don't divide by 0 for rates
151-
152149
ports = json_object_new_array_ext(PORTS);
153150
for (int i = 1; i <= PORTS; i++) {
154151
v = json_object_new_object();
@@ -166,13 +163,41 @@ void send_eee(int s)
166163
json_object_object_add(v, "active", json_object_new_int((i % 2) ? 1 : 0));
167164
json_object_array_add(ports, v);
168165
}
169-
last_called = now;
170166

171167
write(s, header, strlen(header));
172168

173169
jstring = json_object_to_json_string_ext(ports, JSON_C_TO_STRING_PLAIN);
174170
write(s, jstring, strlen(jstring));
175-
json_object_put(v);
171+
json_object_put(ports);
172+
}
173+
174+
175+
void send_mirror(int s)
176+
{
177+
uint16_t mirror_tx, mirror_rx = 0;
178+
char mirror_tx_buf[20];
179+
char mirror_rx_buf[20];
180+
struct json_object *mirror;
181+
const char *jstring;
182+
char *header = "HTTP/1.1 200 OK\r\n"
183+
"Content-Type: application/json; charset=UTF-8\r\n\r\n";
184+
185+
mirror = json_object_new_object();
186+
json_object_object_add(mirror, "mPort", json_object_new_int(1));
187+
json_object_object_add(mirror, "enabled", json_object_new_int(1));
188+
189+
mirror_tx = 0b000110;
190+
mirror_rx = 0b000010;
191+
sprintf(mirror_tx_buf, "%016b", mirror_tx);
192+
sprintf(mirror_rx_buf, "%016b", mirror_rx);
193+
json_object_object_add(mirror, "mirror_tx", json_object_new_string(mirror_tx_buf));
194+
json_object_object_add(mirror, "mirror_rx", json_object_new_string(mirror_rx_buf));
195+
196+
write(s, header, strlen(header));
197+
198+
jstring = json_object_to_json_string_ext(mirror, JSON_C_TO_STRING_PLAIN);
199+
write(s, jstring, strlen(jstring));
200+
json_object_put(mirror);
176201
}
177202

178203

@@ -303,6 +328,11 @@ void launch(struct Server *server)
303328
send_basic_info(new_socket);
304329
goto done;
305330
}
331+
if (!strncmp(&buffer[4], "/mirror.json", 12)) {
332+
printf("Mirror request\n");
333+
send_mirror(new_socket);
334+
goto done;
335+
}
306336
if (!strncmp(&buffer[4], "/vlan.json?vid=", 15)) {
307337
int vlan = atoi(&buffer[19]);
308338
printf("VLAN request for %d\n", vlan);

0 commit comments

Comments
 (0)