From 65d67dc222c8508c0e98ef37b2ef17aea1eee73f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 23 Dec 2009 12:52:30 +0100 Subject: [PATCH] [ipaccess] Start adding a tool that analyzes the ipaccess header So far I have not much idea about the format. It is starting with the magic byte and the header is spanning until the next occurence of the " SDP" marker. --- openbsc/src/Makefile.am | 4 +- .../src/ipaccess-firmware/ipaccess-firmware.c | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 openbsc/src/ipaccess-firmware/ipaccess-firmware.c diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am index de413d5ed..3f98bdad9 100644 --- a/openbsc/src/Makefile.am +++ b/openbsc/src/Makefile.am @@ -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 + isdnsync bsc_mgcp ipaccess_firmware noinst_LIBRARIES = libbsc.a libmsc.a libvty.a libsccp.a noinst_HEADERS = vty/cardshell.h @@ -38,3 +38,5 @@ 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-firmware/ipaccess-firmware.c diff --git a/openbsc/src/ipaccess-firmware/ipaccess-firmware.c b/openbsc/src/ipaccess-firmware/ipaccess-firmware.c new file mode 100644 index 000000000..0f9362941 --- /dev/null +++ b/openbsc/src/ipaccess-firmware/ipaccess-firmware.c @@ -0,0 +1,67 @@ +/* Routines for parsing an ipacces SDP firmware file */ + +/* (C) 2009 by Holger Hans Peter Freyther + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include + + + +static void analyze_file(int fd) +{ + char buf[4096]; + int rc; + + rc = read(fd, buf, 4); + if (rc <= 0) { + fprintf(stderr, "Not enough space for the header.\n"); + return; + } + + if (strcmp(buf, " SDP") != 0) { + fprintf(stderr, "Wrong magic number at the beginning of the file.\n"); + return; + } + + printf("Printing header information:\n"); +} + +int main(int argc, char** argv) +{ + int i, fd; + + for (i = 1; i < argc; ++i) { + printf("Opening possible firmware '%s'\n", argv[i]); + fd = open(argv[i], O_RDONLY); + if (!fd) { + perror("nada"); + continue; + } + + analyze_file(fd); + } + + return EXIT_SUCCESS; +}