~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to tools/hciattach.c

ImportĀ upstreamĀ versionĀ 4.81

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 *  Copyright (C) 2000-2001  Qualcomm Incorporated
6
6
 *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
7
 
 *  Copyright (C) 2002-2009  Marcel Holtmann <marcel@holtmann.org>
 
7
 *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
8
8
 *
9
9
 *
10
10
 *  This program is free software; you can redistribute it and/or modify
27
27
#include <config.h>
28
28
#endif
29
29
 
 
30
#define _GNU_SOURCE
30
31
#include <stdio.h>
31
32
#include <errno.h>
32
33
#include <fcntl.h>
50
51
 
51
52
#include "hciattach.h"
52
53
 
 
54
#ifdef NEED_PPOLL
 
55
#include "ppoll.h"
 
56
#endif
 
57
 
53
58
struct uart_t {
54
59
        char *type;
55
60
        int  m_id;
58
63
        int  init_speed;
59
64
        int  speed;
60
65
        int  flags;
 
66
        int  pm;
61
67
        char *bdaddr;
62
68
        int  (*init) (int fd, struct uart_t *u, struct termios *ti);
63
69
        int  (*post) (int fd, struct uart_t *u, struct termios *ti);
64
70
};
65
71
 
66
72
#define FLOW_CTL        0x0001
 
73
#define ENABLE_PM       1
 
74
#define DISABLE_PM      0
67
75
 
68
76
static volatile sig_atomic_t __io_canceled = 0;
69
77
 
136
144
 
137
145
int set_speed(int fd, struct termios *ti, int speed)
138
146
{
139
 
        cfsetospeed(ti, uart_speed(speed));
140
 
        cfsetispeed(ti, uart_speed(speed));
141
 
        return tcsetattr(fd, TCSANOW, ti);
 
147
        if (cfsetospeed(ti, uart_speed(speed)) < 0)
 
148
                return -errno;
 
149
 
 
150
        if (cfsetispeed(ti, uart_speed(speed)) < 0)
 
151
                return -errno;
 
152
 
 
153
        if (tcsetattr(fd, TCSANOW, ti) < 0)
 
154
                return -errno;
 
155
 
 
156
        return 0;
142
157
}
143
158
 
144
 
/* 
 
159
/*
145
160
 * Read an HCI event from the given file descriptor.
146
161
 */
147
 
int read_hci_event(int fd, unsigned char* buf, int size) 
 
162
int read_hci_event(int fd, unsigned char* buf, int size)
148
163
{
149
164
        int remain, r;
150
165
        int count = 0;
172
187
        }
173
188
 
174
189
        /* Now we read the parameters. */
175
 
        if (buf[2] < (size - 3)) 
 
190
        if (buf[2] < (size - 3))
176
191
                remain = buf[2];
177
 
        else 
 
192
        else
178
193
                remain = size - 3;
179
194
 
180
195
        while ((count - 3) < remain) {
187
202
        return count;
188
203
}
189
204
 
190
 
/* 
191
 
 * Ericsson specific initialization 
 
205
/*
 
206
 * Ericsson specific initialization
192
207
 */
193
208
static int ericsson(int fd, struct uart_t *u, struct termios *ti)
194
209
{
242
257
        return 0;
243
258
}
244
259
 
245
 
/* 
246
 
 * Digianswer specific initialization 
 
260
/*
 
261
 * Digianswer specific initialization
247
262
 */
248
263
static int digi(int fd, struct uart_t *u, struct termios *ti)
249
264
{
294
309
        return texasalt_init(fd, u->speed, ti);
295
310
}
296
311
 
 
312
static int ath3k_ps(int fd, struct uart_t *u, struct termios *ti)
 
313
{
 
314
        return ath3k_init(fd, u->speed, u->init_speed, u->bdaddr, ti);
 
315
}
 
316
 
 
317
static int ath3k_pm(int fd, struct uart_t *u, struct termios *ti)
 
318
{
 
319
        return ath3k_post(fd, u->pm);
 
320
}
 
321
 
 
322
static int qualcomm(int fd, struct uart_t *u, struct termios *ti)
 
323
{
 
324
        return qualcomm_init(fd, u->speed, ti, u->bdaddr);
 
325
}
 
326
 
297
327
static int read_check(int fd, void *buf, int count)
298
328
{
299
329
        int res;
301
331
        do {
302
332
                res = read(fd, buf, count);
303
333
                if (res != -1) {
304
 
                        buf += res; 
 
334
                        buf += res;
305
335
                        count -= res;
306
336
                }
307
337
        } while (count && (errno == 0 || errno == EINTR));
315
345
/*
316
346
 * BCSP specific initialization
317
347
 */
318
 
int serial_fd;
 
348
static int serial_fd;
 
349
static int bcsp_max_retries = 10;
319
350
 
320
351
static void bcsp_tshy_sig_alarm(int sig)
321
352
{
322
 
        static int retries=0;
323
353
        unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0};
324
354
        int len;
 
355
        static int retries = 0;
325
356
 
326
 
        if (retries < 10) {
 
357
        if (retries < bcsp_max_retries) {
327
358
                retries++;
328
359
                len = write(serial_fd, &bcsp_sync_pkt, 10);
329
360
                alarm(1);
337
368
 
338
369
static void bcsp_tconf_sig_alarm(int sig)
339
370
{
340
 
        static int retries=0;
341
371
        unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0};
342
372
        int len;
 
373
        static int retries = 0;
343
374
 
344
 
        if (retries < 10){
 
375
        if (retries < bcsp_max_retries){
345
376
                retries++;
346
377
                len = write(serial_fd, &bcsp_conf_pkt, 10);
347
378
                alarm(1);
476
507
        return 0;
477
508
}
478
509
 
479
 
/* 
480
 
 * CSR specific initialization 
 
510
/*
 
511
 * CSR specific initialization
481
512
 * Inspired strongly by code in OpenBT and experimentations with Brainboxes
482
513
 * Pcmcia card.
483
514
 * Jean Tourrilhes <jt@hpl.hp.com> - 14.11.01
540
571
                        return -1;
541
572
                }
542
573
 
543
 
        /* Event code 0xFF is for vendor-specific events, which is 
 
574
        /* Event code 0xFF is for vendor-specific events, which is
544
575
         * what we're looking for. */
545
576
        } while (resp[1] != 0xFF);
546
577
 
556
587
        }
557
588
#endif
558
589
        /* Display that to user */
559
 
        fprintf(stderr, "CSR build ID 0x%02X-0x%02X\n", 
 
590
        fprintf(stderr, "CSR build ID 0x%02X-0x%02X\n",
560
591
                resp[15] & 0xFF, resp[14] & 0xFF);
561
592
 
562
593
        /* Try to read the current speed of the CSR chip */
584
615
                        return -1;
585
616
                }
586
617
 
587
 
        /* Event code 0xFF is for vendor-specific events, which is 
 
618
        /* Event code 0xFF is for vendor-specific events, which is
588
619
         * what we're looking for. */
589
620
        } while (resp[1] != 0xFF);
590
621
 
598
629
#endif
599
630
 
600
631
        if (u->speed > 1500000) {
601
 
                fprintf(stderr, "Speed %d too high. Remaining at %d baud\n", 
 
632
                fprintf(stderr, "Speed %d too high. Remaining at %d baud\n",
602
633
                        u->speed, u->init_speed);
603
634
                u->speed = u->init_speed;
604
635
        } else if (u->speed != 57600 && uart_speed(u->speed) == B57600) {
648
679
        return 0;
649
680
}
650
681
 
651
 
/* 
652
 
 * Silicon Wave specific initialization 
 
682
/*
 
683
 * Silicon Wave specific initialization
653
684
 * Thomas Moser <thomas.moser@tmoser.ch>
654
685
 */
655
686
static int swave(int fd, struct uart_t *u, struct termios *ti)
665
696
        // Subcommand", e.g. "soft reset" to make the changes effective.
666
697
 
667
698
        cmd[0] = HCI_COMMAND_PKT;       // it's a command packet
668
 
        cmd[1] = 0x0B;                  // OCF 0x0B     = param access set      
 
699
        cmd[1] = 0x0B;                  // OCF 0x0B     = param access set
669
700
        cmd[2] = 0xfc;                  // OGF bx111111 = vendor specific
670
701
        cmd[3] = 0x06;                  // 6 bytes of data following
671
702
        cmd[4] = 0x01;                  // param sub command
699
730
                return -1;
700
731
        }
701
732
 
702
 
        // We should wait for a "GET Event" to confirm the success of 
703
 
        // the baud rate setting. Wait some time before reading. Better:  
704
 
        // read with timeout, parse data 
 
733
        // We should wait for a "GET Event" to confirm the success of
 
734
        // the baud rate setting. Wait some time before reading. Better:
 
735
        // read with timeout, parse data
705
736
        // until correct answer, else error handling ... todo ...
706
737
 
707
738
        nanosleep(&tm, NULL);
745
776
        // now the uart baud rate on the silicon wave module is set and effective.
746
777
        // change our own baud rate as well. Then there is a reset event comming in
747
778
        // on the *new* baud rate. This is *undocumented*! The packet looks like this:
748
 
        // 04 FF 01 0B (which would make that a confirmation of 0x0B = "Param 
 
779
        // 04 FF 01 0B (which would make that a confirmation of 0x0B = "Param
749
780
        // subcommand class". So: change to new baud rate, read with timeout, parse
750
781
        // data, error handling. BTW: all param access in Silicon Wave is done this way.
751
782
        // Maybe this code would belong in a seperate file, or at least code reuse...
1000
1031
}
1001
1032
 
1002
1033
struct uart_t uart[] = {
1003
 
        { "any",        0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, NULL     },
1004
 
        { "ericsson",   0x0000, 0x0000, HCI_UART_H4,   57600,  115200, FLOW_CTL, NULL, ericsson },
1005
 
        { "digi",       0x0000, 0x0000, HCI_UART_H4,   9600,   115200, FLOW_CTL, NULL, digi     },
1006
 
 
1007
 
        { "bcsp",       0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1034
        { "any",        0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1035
                                FLOW_CTL, DISABLE_PM, NULL, NULL     },
 
1036
 
 
1037
        { "ericsson",   0x0000, 0x0000, HCI_UART_H4,   57600,  115200,
 
1038
                                FLOW_CTL, DISABLE_PM, NULL, ericsson },
 
1039
 
 
1040
        { "digi",       0x0000, 0x0000, HCI_UART_H4,   9600,   115200,
 
1041
                                FLOW_CTL, DISABLE_PM, NULL, digi     },
 
1042
 
 
1043
        { "bcsp",       0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200,
 
1044
                                0, DISABLE_PM, NULL, bcsp     },
1008
1045
 
1009
1046
        /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */
1010
 
        { "xircom",     0x0105, 0x080a, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, NULL     },
 
1047
        { "xircom",     0x0105, 0x080a, HCI_UART_H4,   115200, 115200,
 
1048
                                FLOW_CTL, DISABLE_PM,  NULL, NULL     },
1011
1049
 
1012
1050
        /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */
1013
 
        { "csr",        0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, csr      },
 
1051
        { "csr",        0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1052
                                FLOW_CTL, DISABLE_PM, NULL, csr      },
1014
1053
 
1015
1054
        /* BrainBoxes PCMCIA card (BL620) */
1016
 
        { "bboxes",     0x0160, 0x0002, HCI_UART_H4,   115200, 460800, FLOW_CTL, NULL, csr      },
 
1055
        { "bboxes",     0x0160, 0x0002, HCI_UART_H4,   115200, 460800,
 
1056
                                FLOW_CTL, DISABLE_PM, NULL, csr      },
1017
1057
 
1018
1058
        /* Silicon Wave kits */
1019
 
        { "swave",      0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, swave    },
 
1059
        { "swave",      0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1060
                                FLOW_CTL, DISABLE_PM, NULL, swave    },
1020
1061
 
1021
1062
        /* Texas Instruments Bluelink (BRF) modules */
1022
 
        { "texas",      0x0000, 0x0000, HCI_UART_LL,   115200, 115200, FLOW_CTL, NULL, texas,    texas2 },
1023
 
        { "texasalt",   0x0000, 0x0000, HCI_UART_LL,   115200, 115200, FLOW_CTL, NULL, texasalt, NULL   },
 
1063
        { "texas",      0x0000, 0x0000, HCI_UART_LL,   115200, 115200,
 
1064
                                FLOW_CTL, DISABLE_PM, NULL, texas,    texas2 },
 
1065
 
 
1066
        { "texasalt",   0x0000, 0x0000, HCI_UART_LL,   115200, 115200,
 
1067
                                FLOW_CTL, DISABLE_PM, NULL, texasalt, NULL   },
1024
1068
 
1025
1069
        /* ST Microelectronics minikits based on STLC2410/STLC2415 */
1026
 
        { "st",         0x0000, 0x0000, HCI_UART_H4,    57600, 115200, FLOW_CTL, NULL, st       },
 
1070
        { "st",         0x0000, 0x0000, HCI_UART_H4,    57600, 115200,
 
1071
                                FLOW_CTL, DISABLE_PM,  NULL, st       },
1027
1072
 
1028
1073
        /* ST Microelectronics minikits based on STLC2500 */
1029
 
        { "stlc2500",   0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, "00:80:E1:00:AB:BA", stlc2500 },
 
1074
        { "stlc2500",   0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
 
1075
                        FLOW_CTL, DISABLE_PM, "00:80:E1:00:AB:BA", stlc2500 },
1030
1076
 
1031
1077
        /* Philips generic Ericsson IP core based */
1032
 
        { "philips",    0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, NULL     },
 
1078
        { "philips",    0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1079
                                FLOW_CTL, DISABLE_PM, NULL, NULL     },
1033
1080
 
1034
1081
        /* Philips BGB2xx Module */
1035
 
        { "bgb2xx",    0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, "BD:B2:10:00:AB:BA", bgb2xx },
 
1082
        { "bgb2xx",    0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1083
                        FLOW_CTL, DISABLE_PM, "BD:B2:10:00:AB:BA", bgb2xx },
1036
1084
 
1037
1085
        /* Sphinx Electronics PICO Card */
1038
 
        { "picocard",   0x025e, 0x1000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, NULL     },
 
1086
        { "picocard",   0x025e, 0x1000, HCI_UART_H4, 115200, 115200,
 
1087
                                FLOW_CTL, DISABLE_PM, NULL, NULL     },
1039
1088
 
1040
1089
        /* Inventel BlueBird Module */
1041
 
        { "inventel",   0x0000, 0x0000, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, NULL     },
 
1090
        { "inventel",   0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
 
1091
                                FLOW_CTL, DISABLE_PM, NULL, NULL     },
1042
1092
 
1043
1093
        /* COM One Platinium Bluetooth PC Card */
1044
 
        { "comone",     0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1094
        { "comone",     0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200,
 
1095
                                0, DISABLE_PM,  NULL, bcsp     },
1045
1096
 
1046
1097
        /* TDK Bluetooth PC Card and IBM Bluetooth PC Card II */
1047
 
        { "tdk",        0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1098
        { "tdk",        0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200,
 
1099
                                0, DISABLE_PM, NULL, bcsp     },
1048
1100
 
1049
1101
        /* Socket Bluetooth CF Card (Rev G) */
1050
 
        { "socket",     0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0,        NULL, bcsp     },
 
1102
        { "socket",     0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400,
 
1103
                                0, DISABLE_PM, NULL, bcsp     },
1051
1104
 
1052
1105
        /* 3Com Bluetooth Card (Version 3.0) */
1053
 
        { "3com",       0x0101, 0x0041, HCI_UART_H4,   115200, 115200, FLOW_CTL, NULL, csr      },
 
1106
        { "3com",       0x0101, 0x0041, HCI_UART_H4,   115200, 115200,
 
1107
                                FLOW_CTL, DISABLE_PM, NULL, csr      },
1054
1108
 
1055
1109
        /* AmbiCom BT2000C Bluetooth PC/CF Card */
1056
 
        { "bt2000c",    0x022d, 0x2000, HCI_UART_H4,    57600, 460800, FLOW_CTL, NULL, csr      },
 
1110
        { "bt2000c",    0x022d, 0x2000, HCI_UART_H4,    57600, 460800,
 
1111
                                FLOW_CTL, DISABLE_PM, NULL, csr      },
1057
1112
 
1058
1113
        /* Zoom Bluetooth PCMCIA Card */
1059
 
        { "zoom",       0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1114
        { "zoom",       0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200,
 
1115
                                0, DISABLE_PM, NULL, bcsp     },
1060
1116
 
1061
1117
        /* Sitecom CN-504 PCMCIA Card */
1062
 
        { "sitecom",    0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1118
        { "sitecom",    0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200,
 
1119
                                0, DISABLE_PM, NULL, bcsp     },
1063
1120
 
1064
1121
        /* Billionton PCBTC1 PCMCIA Card */
1065
 
        { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0,        NULL, bcsp     },
 
1122
        { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200,
 
1123
                                0, DISABLE_PM, NULL, bcsp     },
1066
1124
 
1067
1125
        /* Broadcom BCM2035 */
1068
 
        { "bcm2035",    0x0A5C, 0x2035, HCI_UART_H4,   115200, 460800, FLOW_CTL, NULL, bcm2035  },
 
1126
        { "bcm2035",    0x0A5C, 0x2035, HCI_UART_H4,   115200, 460800,
 
1127
                                FLOW_CTL, DISABLE_PM, NULL, bcm2035  },
 
1128
 
 
1129
        { "ath3k",    0x0000, 0x0000, HCI_UART_ATH3K, 115200, 115200,
 
1130
                        FLOW_CTL, DISABLE_PM, NULL, ath3k_ps, ath3k_pm  },
 
1131
 
 
1132
        /* QUALCOMM BTS */
 
1133
        { "qualcomm",   0x0000, 0x0000, HCI_UART_H4,   115200, 115200,
 
1134
                        FLOW_CTL, DISABLE_PM, NULL, qualcomm, NULL },
1069
1135
 
1070
1136
        { NULL, 0 }
1071
1137
};
1091
1157
}
1092
1158
 
1093
1159
/* Initialize UART driver */
1094
 
static int init_uart(char *dev, struct uart_t *u, int send_break)
 
1160
static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
1095
1161
{
1096
1162
        struct termios ti;
1097
1163
        int fd, i;
 
1164
        unsigned long flags = 0;
 
1165
 
 
1166
        if (raw)
 
1167
                flags |= 1 << HCI_UART_RAW_DEVICE;
1098
1168
 
1099
1169
        fd = open(dev, O_RDWR | O_NOCTTY);
1100
1170
        if (fd < 0) {
1153
1223
                return -1;
1154
1224
        }
1155
1225
 
 
1226
        if (flags && ioctl(fd, HCIUARTSETFLAGS, flags) < 0) {
 
1227
                perror("Can't set UART flags");
 
1228
                return -1;
 
1229
        }
 
1230
 
1156
1231
        if (ioctl(fd, HCIUARTSETPROTO, u->proto) < 0) {
1157
1232
                perror("Can't set device");
1158
1233
                return -1;
1168
1243
{
1169
1244
        printf("hciattach - HCI UART driver initialization utility\n");
1170
1245
        printf("Usage:\n");
1171
 
        printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
 
1246
        printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
1172
1247
        printf("\thciattach -l\n");
1173
1248
}
1174
1249
 
1175
1250
int main(int argc, char *argv[])
1176
1251
{
1177
1252
        struct uart_t *u = NULL;
1178
 
        int detach, printpid, opt, i, n, ld, err;
 
1253
        int detach, printpid, raw, opt, i, n, ld, err;
1179
1254
        int to = 10;
1180
1255
        int init_speed = 0;
1181
1256
        int send_break = 0;
1182
1257
        pid_t pid;
1183
1258
        struct sigaction sa;
1184
1259
        struct pollfd p;
 
1260
        sigset_t sigs;
1185
1261
        char dev[PATH_MAX];
1186
1262
 
1187
1263
        detach = 1;
1188
1264
        printpid = 0;
 
1265
        raw = 0;
1189
1266
 
1190
 
        while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
 
1267
        while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
1191
1268
                switch(opt) {
1192
1269
                case 'b':
1193
1270
                        send_break = 1;
1216
1293
                        }
1217
1294
                        exit(0);
1218
1295
 
 
1296
                case 'r':
 
1297
                        raw = 1;
 
1298
                        break;
 
1299
 
1219
1300
                default:
1220
1301
                        usage();
1221
1302
                        exit(1);
1254
1335
                                fprintf(stderr, "Unknown device type or id\n");
1255
1336
                                exit(1);
1256
1337
                        }
1257
 
                        
 
1338
 
1258
1339
                        break;
1259
1340
 
1260
1341
                case 2:
1269
1350
                        break;
1270
1351
 
1271
1352
                case 4:
 
1353
                        if (!strcmp("sleep", argv[optind]))
 
1354
                                u->pm = ENABLE_PM;
 
1355
                        else
 
1356
                                u->pm = DISABLE_PM;
 
1357
                        break;
 
1358
 
 
1359
                case 5:
1272
1360
                        u->bdaddr = argv[optind];
1273
1361
                        break;
1274
1362
                }
1291
1379
 
1292
1380
        /* 10 seconds should be enough for initialization */
1293
1381
        alarm(to);
 
1382
        bcsp_max_retries = to;
1294
1383
 
1295
 
        n = init_uart(dev, u, send_break);
 
1384
        n = init_uart(dev, u, send_break, raw);
1296
1385
        if (n < 0) {
1297
 
                perror("Can't initialize device"); 
 
1386
                perror("Can't initialize device");
1298
1387
                exit(1);
1299
1388
        }
1300
1389
 
 
1390
        printf("Device setup complete\n");
 
1391
 
1301
1392
        alarm(0);
1302
1393
 
1303
1394
        memset(&sa, 0, sizeof(sa));
1328
1419
        p.fd = n;
1329
1420
        p.events = POLLERR | POLLHUP;
1330
1421
 
 
1422
        sigfillset(&sigs);
 
1423
        sigdelset(&sigs, SIGCHLD);
 
1424
        sigdelset(&sigs, SIGPIPE);
 
1425
        sigdelset(&sigs, SIGTERM);
 
1426
        sigdelset(&sigs, SIGINT);
 
1427
        sigdelset(&sigs, SIGHUP);
 
1428
 
1331
1429
        while (!__io_canceled) {
1332
1430
                p.revents = 0;
1333
 
                err = poll(&p, 1, 500);
 
1431
                err = ppoll(&p, 1, NULL, &sigs);
1334
1432
                if (err < 0 && errno == EINTR)
1335
1433
                        continue;
1336
1434
                if (err)