[ipaccess] Move firmware analysis into the ipaccess-config utility
* This turns ipaccess-firmware.c into a plain helper, fix the ipaccess name...
This commit is contained in:
parent
1f71d9c4c0
commit
dade8980e3
|
@ -2,7 +2,7 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
|
|||
AM_CFLAGS=-Wall
|
||||
|
||||
sbin_PROGRAMS = bsc_hack bs11_config ipaccess-find ipaccess-config \
|
||||
isdnsync bsc_mgcp ipaccess-firmware ipaccess-proxy
|
||||
isdnsync bsc_mgcp ipaccess-proxy
|
||||
noinst_LIBRARIES = libbsc.a libmsc.a libvty.a libsccp.a
|
||||
noinst_HEADERS = vty/cardshell.h
|
||||
|
||||
|
@ -31,7 +31,7 @@ bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c msgb.c debug.c \
|
|||
|
||||
ipaccess_find_SOURCES = ipaccess/ipaccess-find.c select.c timer.c
|
||||
|
||||
ipaccess_config_SOURCES = ipaccess/ipaccess-config.c
|
||||
ipaccess_config_SOURCES = ipaccess/ipaccess-config.c ipaccess/ipaccess-firmware.c
|
||||
ipaccess_config_LDADD = libbsc.a libmsc.a libbsc.a libvty.a -ldl -ldbi $(LIBCRYPT)
|
||||
|
||||
isdnsync_SOURCES = isdnsync.c
|
||||
|
@ -39,6 +39,4 @@ isdnsync_SOURCES = isdnsync.c
|
|||
bsc_mgcp_SOURCES = bsc_mgcp.c msgb.c talloc.c debug.c select.c timer.c telnet_interface.c
|
||||
bsc_mgcp_LDADD = libvty.a
|
||||
|
||||
ipaccess_firmware_SOURCES = ipaccess/ipaccess-firmware.c talloc.c
|
||||
|
||||
ipaccess_proxy_SOURCES = ipaccess/ipaccess-proxy.c msgb.c select.c talloc.c debug.c timer.c
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
@ -41,6 +43,7 @@
|
|||
#include <openbsc/abis_nm.h>
|
||||
#include <openbsc/signal.h>
|
||||
#include <openbsc/debug.h>
|
||||
#include <openbsc/talloc.h>
|
||||
|
||||
static struct gsm_network *gsmnet;
|
||||
|
||||
|
@ -385,6 +388,65 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void analyze_firmware(const char *filename)
|
||||
{
|
||||
struct stat stat;
|
||||
struct sdp_header *header;
|
||||
struct sdp_header_item *sub_entry;
|
||||
struct llist_head *entry;
|
||||
int fd;
|
||||
void *tall_firm_ctx = 0;
|
||||
|
||||
entry = talloc_zero(tall_firm_ctx, struct llist_head);
|
||||
INIT_LLIST_HEAD(entry);
|
||||
|
||||
printf("Opening possible firmware '%s'\n", filename);
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (!fd) {
|
||||
perror("nada");
|
||||
return;
|
||||
}
|
||||
|
||||
/* verify the file */
|
||||
if (fstat(fd, &stat) == -1) {
|
||||
perror("Can not stat the file");
|
||||
return;
|
||||
}
|
||||
|
||||
ipaccess_analyze_file(fd, stat.st_size, 0, entry);
|
||||
|
||||
llist_for_each_entry(header, entry, entry) {
|
||||
printf("Printing header information:\n");
|
||||
printf("more_more_magic: 0x%x\n", ntohs(header->firmware_info.more_more_magic));
|
||||
printf("header_length: %u\n", ntohl(header->firmware_info.header_length));
|
||||
printf("file_length: %u\n", ntohl(header->firmware_info.file_length));
|
||||
printf("sw_part: %.20s\n", header->firmware_info.sw_part);
|
||||
printf("text1: %.64s\n", header->firmware_info.text1);
|
||||
printf("time: %.12s\n", header->firmware_info.time);
|
||||
printf("date: %.14s\n", header->firmware_info.date);
|
||||
printf("text2: %.10s\n", header->firmware_info.text2);
|
||||
printf("version: %.20s\n", header->firmware_info.version);
|
||||
printf("subitems...\n");
|
||||
|
||||
llist_for_each_entry(sub_entry, &header->header_list, entry) {
|
||||
printf("\tsomething1: %u\n", sub_entry->header_entry.something1);
|
||||
printf("\ttext1: %.64s\n", sub_entry->header_entry.text1);
|
||||
printf("\ttime: %.12s\n", sub_entry->header_entry.time);
|
||||
printf("\tdate: %.14s\n", sub_entry->header_entry.date);
|
||||
printf("\ttext2: %.10s\n", sub_entry->header_entry.text2);
|
||||
printf("\tversion: %.20s\n", sub_entry->header_entry.version);
|
||||
printf("\tlength: %u\n", ntohl(sub_entry->header_entry.length));
|
||||
printf("\taddr1: 0x%x\n", ntohl(sub_entry->header_entry.addr1));
|
||||
printf("\taddr2: 0x%x\n", ntohl(sub_entry->header_entry.addr2));
|
||||
printf("\tstart: 0x%x\n", ntohl(sub_entry->header_entry.start));
|
||||
printf("\n\n");
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
talloc_free(tall_firm_ctx);
|
||||
}
|
||||
|
||||
static void print_usage(void)
|
||||
{
|
||||
printf("Usage: ipaccess-config\n");
|
||||
|
@ -400,6 +462,7 @@ static void print_help(void)
|
|||
printf(" -h --help this text\n");
|
||||
printf(" -s --stream-id ID\n");
|
||||
printf(" -d --software firmware\n");
|
||||
printf(" -f --firmware firmware Provide firmware information\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -431,9 +494,10 @@ int main(int argc, char **argv)
|
|||
{ "listen", 1, 0, 'l' },
|
||||
{ "stream-id", 1, 0, 's' },
|
||||
{ "software", 1, 0, 'd' },
|
||||
{ "firmware", 1, 0, 'f' },
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "u:o:rn:l:hs:d:", long_options,
|
||||
c = getopt_long(argc, argv, "u:o:rn:l:hs:d:f:", long_options,
|
||||
&option_index);
|
||||
|
||||
if (c == -1)
|
||||
|
@ -467,6 +531,9 @@ int main(int argc, char **argv)
|
|||
case 'd':
|
||||
software = strdup(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
analyze_firmware(optarg);
|
||||
exit(0);
|
||||
case 'h':
|
||||
print_usage();
|
||||
print_help();
|
||||
|
|
|
@ -23,14 +23,10 @@
|
|||
#include <openbsc/ipaccess.h>
|
||||
#include <openbsc/talloc.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PART_LENGTH 138
|
||||
|
||||
|
@ -40,10 +36,7 @@ static_assert(sizeof(struct sdp_firmware) == 160, _right_header_length);
|
|||
/* more magic, the second "int" in the header */
|
||||
static char more_magic[] = { 0x10, 0x02 };
|
||||
|
||||
/* talloc context */
|
||||
void *tall_firm_ctx;
|
||||
|
||||
int ipacces_analyze_file(int fd, const unsigned int st_size, const unsigned int base_offset, struct llist_head *list)
|
||||
int ipaccess_analyze_file(int fd, const unsigned int st_size, const unsigned int base_offset, struct llist_head *list)
|
||||
{
|
||||
struct sdp_firmware *firmware_header = 0;
|
||||
struct sdp_header *header;
|
||||
|
@ -122,72 +115,9 @@ int ipacces_analyze_file(int fd, const unsigned int st_size, const unsigned int
|
|||
header_entry->header_entry = entry;
|
||||
llist_add(&header_entry->entry, &header->header_list);
|
||||
|
||||
ipacces_analyze_file(fd, ntohl(entry.length), offset, list);
|
||||
ipaccess_analyze_file(fd, ntohl(entry.length), offset, list);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int i, fd;
|
||||
struct stat stat;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
struct sdp_header *header;
|
||||
struct sdp_header_item *sub_entry;
|
||||
struct llist_head *entry;
|
||||
|
||||
entry = talloc_zero(tall_firm_ctx, struct llist_head);
|
||||
INIT_LLIST_HEAD(entry);
|
||||
|
||||
printf("Opening possible firmware '%s'\n", argv[i]);
|
||||
fd = open(argv[i], O_RDONLY);
|
||||
if (!fd) {
|
||||
perror("nada");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* verify the file */
|
||||
if (fstat(fd, &stat) == -1) {
|
||||
perror("Can not stat the file");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ipacces_analyze_file(fd, stat.st_size, 0, entry);
|
||||
|
||||
llist_for_each_entry(header, entry, entry) {
|
||||
printf("Printing header information:\n");
|
||||
printf("more_more_magic: 0x%x\n", ntohs(header->firmware_info.more_more_magic));
|
||||
printf("header_length: %u\n", ntohl(header->firmware_info.header_length));
|
||||
printf("file_length: %u\n", ntohl(header->firmware_info.file_length));
|
||||
printf("sw_part: %.20s\n", header->firmware_info.sw_part);
|
||||
printf("text1: %.64s\n", header->firmware_info.text1);
|
||||
printf("time: %.12s\n", header->firmware_info.time);
|
||||
printf("date: %.14s\n", header->firmware_info.date);
|
||||
printf("text2: %.10s\n", header->firmware_info.text2);
|
||||
printf("version: %.20s\n", header->firmware_info.version);
|
||||
printf("subitems...\n");
|
||||
|
||||
llist_for_each_entry(sub_entry, &header->header_list, entry) {
|
||||
printf("\tsomething1: %u\n", sub_entry->header_entry.something1);
|
||||
printf("\ttext1: %.64s\n", sub_entry->header_entry.text1);
|
||||
printf("\ttime: %.12s\n", sub_entry->header_entry.time);
|
||||
printf("\tdate: %.14s\n", sub_entry->header_entry.date);
|
||||
printf("\ttext2: %.10s\n", sub_entry->header_entry.text2);
|
||||
printf("\tversion: %.20s\n", sub_entry->header_entry.version);
|
||||
printf("\tlength: %u\n", ntohl(sub_entry->header_entry.length));
|
||||
printf("\taddr1: 0x%x\n", ntohl(sub_entry->header_entry.addr1));
|
||||
printf("\taddr2: 0x%x\n", ntohl(sub_entry->header_entry.addr2));
|
||||
printf("\tstart: 0x%x\n", ntohl(sub_entry->header_entry.start));
|
||||
printf("\n\n");
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
talloc_free(entry);
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue