int aim_main(int argc, char* argv[]) { /* * Fixme -- this is just a hacked placeholder for * a more fully-functional tool. */ uint32_t pa; int size; uint8_t* va = NULL; #define USAGE() \ do { \ fprintf(stderr, "usage: mtool dump PHYSADDR BYTES\n"); \ fprintf(stderr, "usage: mtool odump PHYSADDR [json]\n"); \ return 1; \ } while(0) if(argc < 3) { USAGE(); } if(sscanf(argv[2], "0x%x", &pa) != 1) { USAGE(); } if(!strcmp(argv[1], "dump")) { if(argv[3] == NULL || sscanf(argv[3], "%d", &size) != 1) { USAGE(); } va = onlp_mmap(pa, size, "mtool"); if(va) { aim_printf(&aim_pvs_stdout, "%{data}\n", va, size); } } else if(!strcmp(argv[1], "odump")) { size = 1024*512; /* arbitrary */ va = onlp_mmap(pa, size, "mtool"); if(va) { onlp_onie_info_t info; if(onlp_onie_decode(&info, va, size) == 0) { if(argv[3] && !strcmp(argv[3], "json")) { onlp_onie_show_json(&info, &aim_pvs_stdout); } else { onlp_onie_show(&info, &aim_pvs_stdout); } onlp_onie_info_free(&info); } else { int dsize = 128; aim_printf(&aim_pvs_stdout, "Here are the first %d bytes:\n%{data}\n", dsize, va, dsize); } } } else { USAGE(); } if(va) { munmap(va, size); } return 0; }
int onlpdump_main(int argc, char* argv[]) { int show = 0; uint32_t showflags = 0; int help = 0; int c; int rv = -1; int j = 0; int o = 0; int m = 0; int i = 0; int p = 0; int x = 0; const char* O = NULL; const char* t = NULL; while( (c = getopt(argc, argv, "srehdojmipxt:O:")) != -1) { switch(c) { case 's': show=1; break; case 'r': show=1; showflags |= ONLP_OID_SHOW_F_RECURSE; break; case 'e': show=1; showflags |= ONLP_OID_SHOW_F_EXTENDED; break; case 'd': show=0; break; case 'h': help=1; rv = 0; break; case 'j': j=1; break; case 'o': o=1; break; case 'x': x=1; break; case 'm': m=1; break; case 'i': i=1; break; case 'p': p=1; show=-1; break; case 't': t = optarg; break; case 'O': O = optarg; break; default: help=1; rv = 1; break; } } if(help) { printf("Usage: %s [OPTIONS]\n", argv[0]); printf(" -d Use dump(). This is the default.\n"); printf(" -s Use show() instead of dump().\n"); printf(" -r Recursive show(). Implies -s\n"); printf(" -e Extended show(). Implies -s\n"); printf(" -o Dump ONIE data only.\n"); printf(" -x Dump Platform Info only.\n"); printf(" -j Dump ONIE data in JSON format.\n"); printf(" -m Run platform manager.\n"); printf(" -i Iterate OIDs.\n"); printf(" -p Show SFP presence.\n"); printf(" -t <file> Decode TlvInfo data.\n"); printf(" -O <oid> Dump OID.\n"); return rv; } if(t){ int rv; onlp_onie_info_t onie; rv = onlp_onie_decode_file(&onie, t); if(rv >= 0) { onlp_onie_show(&onie, &aim_pvs_stdout); onlp_onie_info_free(&onie); return 0; } else { aim_printf(&aim_pvs_stdout, "Decode failed."); return 1; } } onlp_init(); if(O) { int oid; if(sscanf(O, "0x%x", &oid) == 1) { onlp_oid_dump(oid, &aim_pvs_stdout, ONLP_OID_DUMP_F_RECURSE | ONLP_OID_DUMP_F_EVEN_IF_ABSENT); } return 0; } if(i) { iterate_oids__(); return 0; } if(o || x) { onlp_sys_info_t si; if(onlp_sys_info_get(&si) < 0) { fprintf(stderr, "onlp_sys_info_get() failed."); return 1; } if(o) { if(j) { onlp_onie_show_json(&si.onie_info, &aim_pvs_stdout); } else { onlp_onie_show(&si.onie_info, &aim_pvs_stdout); } } if(x) { if(j) { onlp_platform_info_show_json(&si.platform_info, &aim_pvs_stdout); } else { onlp_platform_info_show(&si.platform_info, &aim_pvs_stdout); } } onlp_sys_info_free(&si); return 0; } if(show >= 0) { if(show == 0) { /* Default to full dump */ onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_F_RECURSE | ONLP_OID_DUMP_F_EVEN_IF_ABSENT); } else { onlp_platform_show(&aim_pvs_stdout, showflags); } } if(m) { printf("Running the platform manager for 600 seconds...\n"); onlp_sys_platform_manage_start(); sleep(600); printf("Stopping the platform manager.\n"); onlp_sys_platform_manage_stop(); } if(p) { onlp_sfp_bitmap_t presence; onlp_sfp_bitmap_t_init(&presence); int rv = onlp_sfp_presence_bitmap_get(&presence); aim_printf(&aim_pvs_stdout, "Presence: "); if(rv < 0) { aim_printf(&aim_pvs_stdout, "Error %{onlp_status}\n", rv); } else { aim_printf(&aim_pvs_stdout, "%{aim_bitmap}\n", &presence); } } return 0; }
int onlpdump_main(int argc, char* argv[]) { int show = 0; uint32_t showflags = 0; int help = 0; int c; int rv = -1; int j = 0; int o = 0; int m = 0; int i = 0; while( (c = getopt(argc, argv, "srehdojmi")) != -1) { switch(c) { case 's': show=1; break; case 'r': show=1; showflags |= ONLP_OID_SHOW_F_RECURSE; break; case 'e': show=1; showflags |= ONLP_OID_SHOW_F_EXTENDED; break; case 'd': show=0; break; case 'h': help=1; rv = 0; break; case 'j': j=1; break; case 'o': o=1; break; case 'm': m=1; break; case 'i': i=1; break; default: help=1; rv = 1; break; } } if(help) { printf("Usage: %s [OPTIONS]\n", argv[0]); printf(" -d Use dump(). This is the default.\n"); printf(" -s Use show() instead of dump().\n"); printf(" -r Recursive show(). Implies -s\n"); printf(" -e Extended show(). Implies -s\n"); printf(" -o Dump ONIE data only.\n"); printf(" -j Dump ONIE data in JSON format.\n"); printf(" -m Run platform manager.\n"); printf(" -i Iterate OIDs.\n"); return rv; } onlp_init(); if(i) { iterate_oids__(); return 0; } if(o) { onlp_sys_info_t si; if(onlp_sys_info_get(&si) < 0) { fprintf(stderr, "onlp_sys_info_get() failed."); return 1; } if(j) { onlp_onie_show_json(&si.onie_info, &aim_pvs_stdout); } else { onlp_onie_show(&si.onie_info, &aim_pvs_stdout); } onlp_sys_info_free(&si); return 0; } if(show == 0) { /* Default to full dump */ onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_F_RECURSE | ONLP_OID_DUMP_F_EVEN_IF_ABSENT); } else { onlp_platform_show(&aim_pvs_stdout, showflags); } if(m) { printf("Running the platform manager for 600 seconds...\n"); onlp_sys_platform_manage_start(); sleep(600); printf("Stopping the platform manager.\n"); onlp_sys_platform_manage_stop(); } return 0; }