aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/ipaccess/ipaccess-firmware.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-12-24 11:26:30 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2009-12-24 11:28:29 +0100
commit426da090dbfc61776ea20d57468e9509fa136339 (patch)
tree232e493e9b16eeb1958b56624c8f530eff580e6b /openbsc/src/ipaccess/ipaccess-firmware.c
parent9094cbaf9c90dc86283eb66fdc75222ae10e7ec3 (diff)
[ipaccess] Move ipaccess utilities into a dedicated subdirectory
Diffstat (limited to 'openbsc/src/ipaccess/ipaccess-firmware.c')
-rw-r--r--openbsc/src/ipaccess/ipaccess-firmware.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/openbsc/src/ipaccess/ipaccess-firmware.c b/openbsc/src/ipaccess/ipaccess-firmware.c
new file mode 100644
index 000000000..4349f99da
--- /dev/null
+++ b/openbsc/src/ipaccess/ipaccess-firmware.c
@@ -0,0 +1,101 @@
+/* Routines for parsing an ipacces SDP firmware file */
+
+/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * 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 <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>
+
+
+struct sdp_firmware {
+ char magic[4];
+ char more_magic[4];
+ unsigned int header_length;
+ unsigned int file_length;
+ char sw_part[20];
+ char text1[122];
+ u_int8_t no_idea_1[4];
+ char text2[64];
+ char time[8];
+ u_int8_t no_idea_2[4];
+ char date[8];
+ u_int8_t no_idea_3[6];
+ /* stuff i don't know */
+} __attribute__((packed));
+
+/* more magic, the second "int" in the header */
+static char more_magic[] = { 0x10, 0x02, 0x00, 0x0 };
+
+
+static void analyze_file(int fd)
+{
+ struct sdp_firmware *firmware_header;
+ char buf[4096];
+ int rc;
+
+ rc = read(fd, buf, sizeof(*firmware_header));
+ if (rc < 0) {
+ perror("can not read header");
+ return;
+ }
+
+ firmware_header = (struct sdp_firmware *) &buf[0];
+ if (strncmp(firmware_header->magic, " SDP", 4) != 0) {
+ fprintf(stderr, "Wrong magic.\n");
+ return;
+ }
+
+ if (memcmp(firmware_header->more_magic, more_magic, 4) != 0) {
+ fprintf(stderr, "Wrong more magic.\n");
+ return;
+ }
+
+ printf("Printing header information:\n");
+ printf("header_length: %u\n", ntohl(firmware_header->header_length));
+ printf("file_length: %u\n", ntohl(firmware_header->file_length));
+ printf("sw_part: %.20s\n", firmware_header->sw_part);
+ printf("text1: %.122s\n", firmware_header->text1);
+ printf("text2: %.64s\n", firmware_header->text2);
+ printf("time: %.8s\n", firmware_header->time);
+ printf("date: %.8s\n", firmware_header->date);
+}
+
+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;
+}