Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SPI testing utility (using spidev driver) |
| 3 | * |
| 4 | * Copyright (c) 2007 MontaVista Software, Inc. |
| 5 | * Copyright (c) 2007 Anton Vorontsov <avorontsov@ru.mvista.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License. |
| 10 | * |
| 11 | * Cross-compile with cross-gcc -I/path/to/cross-kernel/include |
| 12 | */ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | #include <unistd.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
Adrian Remonda | b78ce7e | 2015-03-10 16:12:30 -0400 | [diff] [blame] | 18 | #include <string.h> |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 19 | #include <getopt.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <sys/ioctl.h> |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 22 | #include <sys/stat.h> |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | #include <linux/spi/spidev.h> |
| 25 | |
| 26 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 27 | |
| 28 | static void pabort(const char *s) |
| 29 | { |
| 30 | perror(s); |
| 31 | abort(); |
| 32 | } |
| 33 | |
WANG Cong | cd58310 | 2007-10-16 01:27:47 -0700 | [diff] [blame] | 34 | static const char *device = "/dev/spidev1.1"; |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 35 | static uint32_t mode; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 36 | static uint8_t bits = 8; |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 37 | static char *input_file; |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 38 | static char *output_file; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 39 | static uint32_t speed = 500000; |
| 40 | static uint16_t delay; |
Adrian Remonda | 31a5c5a | 2015-03-10 16:12:31 -0400 | [diff] [blame] | 41 | static int verbose; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 42 | |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 43 | uint8_t default_tx[] = { |
| 44 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
| 45 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, |
| 46 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
| 47 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
| 48 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
| 49 | 0xF0, 0x0D, |
| 50 | }; |
| 51 | |
| 52 | uint8_t default_rx[ARRAY_SIZE(default_tx)] = {0, }; |
| 53 | char *input_tx; |
| 54 | |
Adrian Remonda | b78ce7e | 2015-03-10 16:12:30 -0400 | [diff] [blame] | 55 | static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) |
| 56 | { |
| 57 | int i = 0; |
| 58 | const unsigned char *address = src; |
| 59 | const unsigned char *line = address; |
| 60 | unsigned char c; |
| 61 | |
| 62 | printf("%s | ", prefix); |
| 63 | while (length-- > 0) { |
| 64 | printf("%02X ", *address++); |
| 65 | if (!(++i % line_size) || (length == 0 && i % line_size)) { |
| 66 | if (length == 0) { |
| 67 | while (i++ % line_size) |
| 68 | printf("__ "); |
| 69 | } |
| 70 | printf(" | "); /* right close */ |
| 71 | while (line < address) { |
| 72 | c = *line++; |
| 73 | printf("%c", (c < 33 || c == 255) ? 0x2E : c); |
| 74 | } |
| 75 | printf("\n"); |
| 76 | if (length > 0) |
| 77 | printf("%s | ", prefix); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 82 | /* |
| 83 | * Unescape - process hexadecimal escape character |
| 84 | * converts shell input "\x23" -> 0x23 |
| 85 | */ |
Andrew Morton | 07eec62 | 2015-04-16 12:49:29 -0700 | [diff] [blame] | 86 | static int unescape(char *_dst, char *_src, size_t len) |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 87 | { |
| 88 | int ret = 0; |
Joshua Clayton | a20874f | 2015-11-18 14:30:41 -0800 | [diff] [blame^] | 89 | int match; |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 90 | char *src = _src; |
| 91 | char *dst = _dst; |
| 92 | unsigned int ch; |
| 93 | |
| 94 | while (*src) { |
| 95 | if (*src == '\\' && *(src+1) == 'x') { |
Joshua Clayton | a20874f | 2015-11-18 14:30:41 -0800 | [diff] [blame^] | 96 | match = sscanf(src + 2, "%2x", &ch); |
| 97 | if (!match) |
| 98 | pabort("malformed input string"); |
| 99 | |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 100 | src += 4; |
| 101 | *dst++ = (unsigned char)ch; |
| 102 | } else { |
| 103 | *dst++ = *src++; |
| 104 | } |
| 105 | ret++; |
| 106 | } |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 111 | { |
| 112 | int ret; |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 113 | int out_fd; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 114 | struct spi_ioc_transfer tr = { |
| 115 | .tx_buf = (unsigned long)tx, |
| 116 | .rx_buf = (unsigned long)rx, |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 117 | .len = len, |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 118 | .delay_usecs = delay, |
| 119 | .speed_hz = speed, |
| 120 | .bits_per_word = bits, |
| 121 | }; |
| 122 | |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 123 | if (mode & SPI_TX_QUAD) |
| 124 | tr.tx_nbits = 4; |
| 125 | else if (mode & SPI_TX_DUAL) |
| 126 | tr.tx_nbits = 2; |
| 127 | if (mode & SPI_RX_QUAD) |
| 128 | tr.rx_nbits = 4; |
| 129 | else if (mode & SPI_RX_DUAL) |
| 130 | tr.rx_nbits = 2; |
| 131 | if (!(mode & SPI_LOOP)) { |
| 132 | if (mode & (SPI_TX_QUAD | SPI_TX_DUAL)) |
| 133 | tr.rx_buf = 0; |
| 134 | else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL)) |
| 135 | tr.tx_buf = 0; |
| 136 | } |
| 137 | |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 138 | ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); |
Hector Palacios | 95b1ed2 | 2010-04-29 15:02:28 -0700 | [diff] [blame] | 139 | if (ret < 1) |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 140 | pabort("can't send spi message"); |
| 141 | |
Adrian Remonda | 31a5c5a | 2015-03-10 16:12:31 -0400 | [diff] [blame] | 142 | if (verbose) |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 143 | hex_dump(tx, len, 32, "TX"); |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 144 | |
| 145 | if (output_file) { |
| 146 | out_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 147 | if (out_fd < 0) |
| 148 | pabort("could not open output file"); |
| 149 | |
| 150 | ret = write(out_fd, rx, len); |
| 151 | if (ret != len) |
| 152 | pabort("not all bytes written to utput file"); |
| 153 | |
| 154 | close(out_fd); |
| 155 | } |
| 156 | |
| 157 | if (verbose || !output_file) |
| 158 | hex_dump(rx, len, 32, "RX"); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 161 | static void print_usage(const char *prog) |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 162 | { |
| 163 | printf("Usage: %s [-DsbdlHOLC3]\n", prog); |
| 164 | puts(" -D --device device to use (default /dev/spidev1.1)\n" |
| 165 | " -s --speed max speed (Hz)\n" |
| 166 | " -d --delay delay (usec)\n" |
| 167 | " -b --bpw bits per word \n" |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 168 | " -i --input input data from a file (e.g. \"test.bin\")\n" |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 169 | " -o --output output data to a file (e.g. \"results.bin\")\n" |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 170 | " -l --loop loopback\n" |
| 171 | " -H --cpha clock phase\n" |
| 172 | " -O --cpol clock polarity\n" |
| 173 | " -L --lsb least significant bit first\n" |
| 174 | " -C --cs-high chip select active high\n" |
Geert Uytterhoeven | 925d16a | 2014-02-20 16:01:43 +0100 | [diff] [blame] | 175 | " -3 --3wire SI/SO signals shared\n" |
Adrian Remonda | 31a5c5a | 2015-03-10 16:12:31 -0400 | [diff] [blame] | 176 | " -v --verbose Verbose (show tx buffer)\n" |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 177 | " -p Send data (e.g. \"1234\\xde\\xad\")\n" |
Geert Uytterhoeven | 925d16a | 2014-02-20 16:01:43 +0100 | [diff] [blame] | 178 | " -N --no-cs no chip select\n" |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 179 | " -R --ready slave pulls low to pause\n" |
| 180 | " -2 --dual dual transfer\n" |
| 181 | " -4 --quad quad transfer\n"); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 182 | exit(1); |
| 183 | } |
| 184 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 185 | static void parse_opts(int argc, char *argv[]) |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 186 | { |
| 187 | while (1) { |
WANG Cong | cd58310 | 2007-10-16 01:27:47 -0700 | [diff] [blame] | 188 | static const struct option lopts[] = { |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 189 | { "device", 1, 0, 'D' }, |
| 190 | { "speed", 1, 0, 's' }, |
| 191 | { "delay", 1, 0, 'd' }, |
| 192 | { "bpw", 1, 0, 'b' }, |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 193 | { "input", 1, 0, 'i' }, |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 194 | { "output", 1, 0, 'o' }, |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 195 | { "loop", 0, 0, 'l' }, |
| 196 | { "cpha", 0, 0, 'H' }, |
| 197 | { "cpol", 0, 0, 'O' }, |
| 198 | { "lsb", 0, 0, 'L' }, |
| 199 | { "cs-high", 0, 0, 'C' }, |
| 200 | { "3wire", 0, 0, '3' }, |
David Brownell | b55f627 | 2009-06-30 11:41:26 -0700 | [diff] [blame] | 201 | { "no-cs", 0, 0, 'N' }, |
| 202 | { "ready", 0, 0, 'R' }, |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 203 | { "dual", 0, 0, '2' }, |
Adrian Remonda | 31a5c5a | 2015-03-10 16:12:31 -0400 | [diff] [blame] | 204 | { "verbose", 0, 0, 'v' }, |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 205 | { "quad", 0, 0, '4' }, |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 206 | { NULL, 0, 0, 0 }, |
| 207 | }; |
| 208 | int c; |
| 209 | |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 210 | c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3NR24p:v", |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 211 | lopts, NULL); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 212 | |
| 213 | if (c == -1) |
| 214 | break; |
| 215 | |
| 216 | switch (c) { |
| 217 | case 'D': |
| 218 | device = optarg; |
| 219 | break; |
| 220 | case 's': |
| 221 | speed = atoi(optarg); |
| 222 | break; |
| 223 | case 'd': |
| 224 | delay = atoi(optarg); |
| 225 | break; |
| 226 | case 'b': |
| 227 | bits = atoi(optarg); |
| 228 | break; |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 229 | case 'i': |
| 230 | input_file = optarg; |
| 231 | break; |
Joshua Clayton | 983b27886 | 2015-11-18 14:30:40 -0800 | [diff] [blame] | 232 | case 'o': |
| 233 | output_file = optarg; |
| 234 | break; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 235 | case 'l': |
| 236 | mode |= SPI_LOOP; |
| 237 | break; |
| 238 | case 'H': |
| 239 | mode |= SPI_CPHA; |
| 240 | break; |
| 241 | case 'O': |
| 242 | mode |= SPI_CPOL; |
| 243 | break; |
| 244 | case 'L': |
| 245 | mode |= SPI_LSB_FIRST; |
| 246 | break; |
| 247 | case 'C': |
| 248 | mode |= SPI_CS_HIGH; |
| 249 | break; |
| 250 | case '3': |
| 251 | mode |= SPI_3WIRE; |
| 252 | break; |
David Brownell | b55f627 | 2009-06-30 11:41:26 -0700 | [diff] [blame] | 253 | case 'N': |
| 254 | mode |= SPI_NO_CS; |
| 255 | break; |
Adrian Remonda | 31a5c5a | 2015-03-10 16:12:31 -0400 | [diff] [blame] | 256 | case 'v': |
| 257 | verbose = 1; |
| 258 | break; |
David Brownell | b55f627 | 2009-06-30 11:41:26 -0700 | [diff] [blame] | 259 | case 'R': |
| 260 | mode |= SPI_READY; |
| 261 | break; |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 262 | case 'p': |
| 263 | input_tx = optarg; |
| 264 | break; |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 265 | case '2': |
| 266 | mode |= SPI_TX_DUAL; |
| 267 | break; |
| 268 | case '4': |
| 269 | mode |= SPI_TX_QUAD; |
| 270 | break; |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 271 | default: |
| 272 | print_usage(argv[0]); |
| 273 | break; |
| 274 | } |
| 275 | } |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 276 | if (mode & SPI_LOOP) { |
| 277 | if (mode & SPI_TX_DUAL) |
| 278 | mode |= SPI_RX_DUAL; |
| 279 | if (mode & SPI_TX_QUAD) |
| 280 | mode |= SPI_RX_QUAD; |
| 281 | } |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Joshua Clayton | 5c437a4 | 2015-11-18 14:30:38 -0800 | [diff] [blame] | 284 | static void transfer_escaped_string(int fd, char *str) |
| 285 | { |
| 286 | size_t size = strlen(str + 1); |
| 287 | uint8_t *tx; |
| 288 | uint8_t *rx; |
| 289 | |
| 290 | tx = malloc(size); |
| 291 | if (!tx) |
| 292 | pabort("can't allocate tx buffer"); |
| 293 | |
| 294 | rx = malloc(size); |
| 295 | if (!rx) |
| 296 | pabort("can't allocate rx buffer"); |
| 297 | |
| 298 | size = unescape((char *)tx, str, size); |
| 299 | transfer(fd, tx, rx, size); |
| 300 | free(rx); |
| 301 | free(tx); |
| 302 | } |
| 303 | |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 304 | static void transfer_file(int fd, char *filename) |
| 305 | { |
| 306 | ssize_t bytes; |
| 307 | struct stat sb; |
| 308 | int tx_fd; |
| 309 | uint8_t *tx; |
| 310 | uint8_t *rx; |
| 311 | |
| 312 | if (stat(filename, &sb) == -1) |
| 313 | pabort("can't stat input file"); |
| 314 | |
| 315 | tx_fd = open(filename, O_RDONLY); |
| 316 | if (fd < 0) |
| 317 | pabort("can't open input file"); |
| 318 | |
| 319 | tx = malloc(sb.st_size); |
| 320 | if (!tx) |
| 321 | pabort("can't allocate tx buffer"); |
| 322 | |
| 323 | rx = malloc(sb.st_size); |
| 324 | if (!rx) |
| 325 | pabort("can't allocate rx buffer"); |
| 326 | |
| 327 | bytes = read(tx_fd, tx, sb.st_size); |
| 328 | if (bytes != sb.st_size) |
| 329 | pabort("failed to read input file"); |
| 330 | |
| 331 | transfer(fd, tx, rx, sb.st_size); |
| 332 | free(rx); |
| 333 | free(tx); |
| 334 | close(tx_fd); |
| 335 | } |
| 336 | |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 337 | int main(int argc, char *argv[]) |
| 338 | { |
| 339 | int ret = 0; |
| 340 | int fd; |
| 341 | |
| 342 | parse_opts(argc, argv); |
| 343 | |
| 344 | fd = open(device, O_RDWR); |
| 345 | if (fd < 0) |
| 346 | pabort("can't open device"); |
| 347 | |
| 348 | /* |
| 349 | * spi mode |
| 350 | */ |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 351 | ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 352 | if (ret == -1) |
| 353 | pabort("can't set spi mode"); |
| 354 | |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 355 | ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 356 | if (ret == -1) |
| 357 | pabort("can't get spi mode"); |
| 358 | |
| 359 | /* |
| 360 | * bits per word |
| 361 | */ |
| 362 | ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); |
| 363 | if (ret == -1) |
| 364 | pabort("can't set bits per word"); |
| 365 | |
| 366 | ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); |
| 367 | if (ret == -1) |
| 368 | pabort("can't get bits per word"); |
| 369 | |
| 370 | /* |
| 371 | * max speed hz |
| 372 | */ |
| 373 | ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); |
| 374 | if (ret == -1) |
| 375 | pabort("can't set max speed hz"); |
| 376 | |
| 377 | ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); |
| 378 | if (ret == -1) |
| 379 | pabort("can't get max speed hz"); |
| 380 | |
Geert Uytterhoeven | c2e78c3 | 2014-02-25 11:40:18 +0100 | [diff] [blame] | 381 | printf("spi mode: 0x%x\n", mode); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 382 | printf("bits per word: %d\n", bits); |
| 383 | printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); |
| 384 | |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 385 | if (input_tx && input_file) |
| 386 | pabort("only one of -p and --input may be selected"); |
| 387 | |
Joshua Clayton | 5c437a4 | 2015-11-18 14:30:38 -0800 | [diff] [blame] | 388 | if (input_tx) |
| 389 | transfer_escaped_string(fd, input_tx); |
Joshua Clayton | 7af475a | 2015-11-18 14:30:39 -0800 | [diff] [blame] | 390 | else if (input_file) |
| 391 | transfer_file(fd, input_file); |
Joshua Clayton | 5c437a4 | 2015-11-18 14:30:38 -0800 | [diff] [blame] | 392 | else |
Adrian Remonda | 3006191 | 2015-03-10 16:12:32 -0400 | [diff] [blame] | 393 | transfer(fd, default_tx, default_rx, sizeof(default_tx)); |
Anton Vorontsov | 22b238b | 2007-07-31 00:38:44 -0700 | [diff] [blame] | 394 | |
| 395 | close(fd); |
| 396 | |
| 397 | return ret; |
| 398 | } |