FreeCalypso > hg > freecalypso-tools
annotate loadtools/tpinterfb.c @ 802:1c599681fd60
pcm-sms-decode & sms-pdu-decode: revamp bad char decoding
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 25 Mar 2021 02:58:30 +0000 |
parents | 8d7dcfd9df53 |
children |
rev | line source |
---|---|
649
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains functions for binary (as opposed to our usual ASCII) |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * interfacing to loadagent. |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/time.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/errno.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
695
8d7dcfd9df53
loadtools: missing #include <unistd.h> in tpinterf modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
649
diff
changeset
|
13 #include <unistd.h> |
649
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int errno; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int target_fd; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 collect_binblock_from_target(buf, expect_len, timeout) |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u_char *buf; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned expect_len; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fd_set fds; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct timeval tv; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned rcvd; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 int cc; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 for (rcvd = 0; rcvd < expect_len; ) { |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 FD_ZERO(&fds); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 FD_SET(target_fd, &fds); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 tv.tv_sec = timeout; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 tv.tv_usec = 0; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 cc = select(target_fd+1, &fds, NULL, NULL, &tv); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (cc < 0) { |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (errno == EINTR) |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 continue; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 perror("select"); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return(-1); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (cc < 1) { |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 "error: timeout waiting for binary block\n"); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return(-1); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 cc = read(target_fd, buf + rcvd, expect_len - rcvd); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (cc <= 0) { |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 perror("read after successful select"); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(-1); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 rcvd += cc; |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(0); |
141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |