7 // =============================================================================
11 static bool do_firmware_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
13 const struct swi_attr *sa;
17 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
18 printf("must be logged\n");
34 static bool do_firmware_upgrade (int nb, const char **com UNUSED, struct ngadmin *nga) {
36 const struct swi_attr *sa;
41 printf("Usage: firmware upgrade <file>\n");
45 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
46 printf("must be logged\n");
51 printf("not implemented yet\n");
62 // =============================================================================
66 static bool do_list (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
69 const struct swi_attr *sa;
72 sa=ngadmin_getSwitchTab(nga, &n);
73 displaySwitchTab(sa, n);
82 // =============================================================================
86 static bool do_login (int nb, const char **com, struct ngadmin *nga) {
92 printf("Usage: login <num>\n");
97 i=strtol(com[0], NULL, 0);
98 i=ngadmin_login(nga, i);
108 // =============================================================================
112 static bool do_name_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
114 const struct swi_attr *sa;
117 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
118 printf("must be logged\n");
131 static bool do_name_set (int nb, const char **com, struct ngadmin *nga) {
134 const struct swi_attr *sa;
138 printf("Usage: name set <value>\n");
142 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
143 printf("must be logged\n");
147 i=ngadmin_setName(nga, com[0]);
157 static bool do_name_clear (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
160 const struct swi_attr *sa;
163 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
164 printf("must be logged\n");
168 i=ngadmin_setName(nga, NULL);
178 // =============================================================================
182 static bool do_password_change (int nb, const char **com, struct ngadmin *nga) {
185 const struct swi_attr *sa;
189 printf("Usage: password set <value>\n");
193 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
194 printf("must be logged\n");
198 i=ngadmin_changePassword(nga, com[0]);
208 static bool do_password_set (int nb, const char **com, struct ngadmin *nga) {
214 printf("Usage: password set <value>\n");
218 i=ngadmin_setPassword(nga, com[0]);
228 // =============================================================================
232 static bool do_ports_state (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
235 const struct swi_attr *sa;
236 unsigned char *ports=NULL;
240 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
241 printf("must be logged\n");
247 ports=malloc(sa->ports*sizeof(unsigned char));
248 if ( (i=ngadmin_getPortsStatus(nga, ports))<0 ) {
254 for (i=0; i<sa->ports; i++) {
255 printf("port %i: ", i+1);
256 switch ( ports[i] ) {
257 case 0: printf("down"); break;
258 case SPEED_10: printf("up, 10M"); break;
259 case SPEED_100: printf("up, 100M"); break;
260 case SPEED_1000: printf("up, 1000M"); break;
261 default: printf("unknown (%i)", ports[i]);
276 static bool do_ports_stats_reset (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
281 if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
282 printf("must be logged\n");
286 i=ngadmin_resetPortsStatistics(nga);
296 static bool do_ports_stats_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
299 const struct swi_attr *sa;
301 struct port_stats *ps=NULL;
304 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
305 printf("must be logged\n");
310 ps=calloc(sa->ports, sizeof(struct port_stats));
311 if ( (i=ngadmin_getPortsStatistics(nga, ps))<0 ) {
317 printf("Port\tReceived\tSent\t\tCRC errors\n");
318 for (i=0; i<sa->ports; ++i) {
319 printf("%i\t%8llu\t%8llu\t%8llu\n", i+1, ps[i].recv, ps[i].sent, ps[i].crc);
332 // =============================================================================
336 static bool do_quit (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga UNUSED) {
346 // =============================================================================
350 static bool do_scan (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
353 const struct swi_attr *sa;
356 if ( (i=ngadmin_scan(nga))<0 ) {
361 sa=ngadmin_getSwitchTab(nga, &nb);
362 displaySwitchTab(sa, nb);
371 // =============================================================================
375 static bool do_stormfilt_enable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
378 const struct swi_attr *sa;
381 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
382 printf("must be logged\n");
386 i=ngadmin_setStormFilterState(nga, 1);
396 static bool do_stormfilt_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
399 const struct swi_attr *sa;
402 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
403 printf("must be logged\n");
407 i=ngadmin_setStormFilterState(nga, 0);
417 static bool do_stormfilt_reset (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
420 const struct swi_attr *sa;
424 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
425 printf("must be logged\n");
431 ports=malloc(sa->ports*sizeof(int));
432 for (i=0; i<sa->ports; ++i) {
433 ports[i]=BITRATE_NOLIMIT;
436 i=ngadmin_setStormFilterValues(nga, ports);
449 static bool do_stormfilt_set (int nb, const char **com, struct ngadmin *nga) {
451 int i, p, *ports=NULL;
452 const struct swi_attr *sa;
457 printf("Usage: stormfilt set <port1> <speed1> [<port2> <speed2> ...]\n");
463 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
464 printf("must be logged\n");
470 ports=malloc(sa->ports*sizeof(int));
471 for (i=0; i<sa->ports; ++i) {
472 ports[i]=BITRATE_UNSPEC;
475 for (i=0; i<nb; i+=2) {
476 if ( (p=strtol(com[i], NULL, 0))<1 || p>sa->ports ) continue;
477 ports[p-1]=parseBitrate(com[i+1]);
481 i=ngadmin_setStormFilterValues(nga, ports);
494 static bool do_stormfilt_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
496 int i, s, ret=true, *ports=NULL;
497 const struct swi_attr *sa;
500 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
501 printf("must be logged\n");
506 if ( (i=ngadmin_getStormFilterState(nga, &s))!=ERR_OK ) {
514 printf("storm filter is disabled\n");
518 printf("storm filter is enabled\n");
520 ports=malloc(sa->ports*sizeof(int));
521 if ( (i=ngadmin_getStormFilterValues(nga, ports))!=ERR_OK ) {
527 for (i=0; i<sa->ports; ++i) {
528 printf("port %i: ", i+1);
529 printBitrate(ports[i]);
541 // =============================================================================
547 COM_TERM(show, do_firmware_show, false)
548 COM_TERM(upgrade, do_firmware_upgrade, true)
551 COM_TERM(list, do_list, false)
553 COM_TERM(login, do_login, true)
556 COM_TERM(show, do_name_show, false)
557 COM_TERM(set, do_name_set, true)
558 COM_TERM(clear, do_name_clear, false)
562 COM_TERM(change, do_password_change, true)
563 COM_TERM(set, do_password_set, true)
567 COM_TERM(state, do_ports_state, false)
569 COM_TERM(reset, do_ports_stats_reset, false)
570 COM_TERM(show, do_ports_stats_show, false)
574 COM_TERM(quit, do_quit, false)
576 COM_TERM(scan, do_scan, false)
579 COM_TERM(enable, do_stormfilt_enable, false)
580 COM_TERM(disable, do_stormfilt_disable, false)
581 COM_TERM(reset, do_stormfilt_reset, false)
582 COM_TERM(set, do_stormfilt_set, true)
583 COM_TERM(show, do_stormfilt_show, false)