[layer23] Fixed emergency call setup
[osmocom-bb.git] / src / host / osmocon / osmocon.c
index 58fa0cd..024697d 100644 (file)
@@ -131,6 +131,7 @@ struct dnload {
        enum dnload_mode mode;
        struct bsc_fd serial_fd;
        char *filename;
+       char *chainload_filename;
 
        int expect_hdlc;
 
@@ -462,7 +463,7 @@ static void hexdump(const uint8_t *data, unsigned int len)
 
 static int romload_prepare_block(void)
 {
-       int rc, i;
+       int i;
 
        int block_checksum = 5;
        int remaining_bytes;
@@ -533,7 +534,7 @@ static int romload_prepare_block(void)
 
        dnload.block_number++;
        dnload.serial_fd.when = BSC_FD_READ | BSC_FD_WRITE;
-       return rc;
+       return 0;
 }
 
 static int mtk_prepare_block(void)
@@ -795,9 +796,9 @@ static void hdlc_tool_cb(uint8_t dlci, struct msgb *msg)
 
        if(srv) {
                struct tool_connection *con;
-               u_int16_t *len;
+               uint16_t *len;
 
-               len = (u_int16_t *) msgb_push(msg, 2);
+               len = (uint16_t *) msgb_push(msg, 2);
                *len = htons(msg->len - sizeof(*len));
 
                llist_for_each_entry(con, &srv->connections, entry) {
@@ -875,6 +876,20 @@ static int handle_read(void)
                dnload.state = WAITING_PROMPT1;
                dnload.write_ptr = dnload.data;
                dnload.expect_hdlc = 1;
+
+               /* check for romloader chainloading mode used as a workaround
+                * for the magic on the C139/C140 and J100i */
+               if (dnload.chainload_filename != NULL) {
+                       printf("Enabled Compal ramloader -> Calypso romloader"
+                               " chainloading mode\n");
+                       bufptr = buffer;
+                       dnload.filename = dnload.chainload_filename;
+                       dnload.mode = MODE_ROMLOAD;
+                       serial_set_baudrate(ROMLOAD_INIT_BAUDRATE);
+                       tick_timer.cb = &beacon_timer_cb;
+                       tick_timer.data = &tick_timer;
+                       bsc_schedule_timer(&tick_timer, 0, BEACON_INTERVAL);
+               }
        } else if (!memcmp(buffer, phone_nack, sizeof(phone_nack))) {
                printf("Received DOWNLOAD NACK from phone, something went"
                        " wrong :(\n");
@@ -1224,10 +1239,12 @@ static int parse_mode(const char *arg)
 }
 
 #define HELP_TEXT \
-       "[ -v | -h ] [ -d [t][r] ] [ -p /dev/ttyXXXX ] [ -s /tmp/osmocom_l2 ]\n" \
-       "\t\t[ -l /tmp/osmocom_loader ]\n" \
-       "\t\t[ -m {c123,c123xor,c140,c140xor,c155,romload,mtk} ]\n" \
-       "\t\t file.bin\n\n" \
+       "[ -v | -h ] [ -d [t][r] ] [ -p /dev/ttyXXXX ]\n" \
+       "\t\t [ -s /tmp/osmocom_l2 ]\n" \
+       "\t\t [ -l /tmp/osmocom_loader ]\n" \
+       "\t\t [ -m {c123,c123xor,c140,c140xor,c155,romload,mtk} ]\n" \
+       "\t\t [ -c /to-be-chainloaded-file.bin ]\n" \
+       "\t\t  file.bin\n\n" \
        "* Open serial port /dev/ttyXXXX (connected to your phone)\n" \
        "* Perform handshaking with the ramloader in the phone\n" \
        "* Download file.bin to the attached phone (base address 0x00800100)\n"
@@ -1248,8 +1265,8 @@ static int version(const char *name)
 static int un_tool_read(struct bsc_fd *fd, unsigned int flags)
 {
        int rc, c;
-       u_int16_t length = 0xffff;
-       u_int8_t buf[4096];
+       uint16_t length = 0xffff;
+       uint8_t buf[4096];
        struct tool_connection *con = (struct tool_connection *)fd->data;
 
        c = 0;
@@ -1269,7 +1286,7 @@ static int un_tool_read(struct bsc_fd *fd, unsigned int flags)
                c += rc;
        }
 
-       length = ntohs(*(u_int16_t*)buf);
+       length = ntohs(*(uint16_t*)buf);
 
        c = 0;
        while(c < length) {
@@ -1428,14 +1445,15 @@ void parse_debug(const char *str)
 int main(int argc, char **argv)
 {
        int opt, flags;
-       uint32_t tmp_load_address = 0;
+       uint32_t tmp_load_address = ROMLOAD_ADDRESS;
        const char *serial_dev = "/dev/ttyUSB1";
        const char *layer2_un_path = "/tmp/osmocom_l2";
        const char *loader_un_path = "/tmp/osmocom_loader";
 
        dnload.mode = MODE_C123;
+       dnload.chainload_filename = NULL;
 
-       while ((opt = getopt(argc, argv, "d:hl:p:m:s:v")) != -1) {
+       while ((opt = getopt(argc, argv, "d:hl:p:m:c:s:v")) != -1) {
                switch (opt) {
                case 'p':
                        serial_dev = optarg;
@@ -1457,6 +1475,9 @@ int main(int argc, char **argv)
                case 'd':
                        parse_debug(optarg);
                        break;
+               case 'c':
+                       dnload.chainload_filename = optarg;
+                       break;
                case 'h':
                default:
                        usage(argv[0]);