FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fdcmd.c @ 891:f3fba126778a
gsm-fw/comlib/cl_imei.c: implemented reading of Pirelli's factory IMEI record
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 29 Jun 2015 21:58:15 +0000 |
parents | 69e8ae2b5ba2 |
children |
rev | line source |
---|---|
286
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * File descriptor debug commands |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "etm.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "ffs.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "tmffs2.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "limits.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "localtypes.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "localstruct.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "cmdtab.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "exitcodes.h" |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 cmd_fd_open(argc, argv) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 char **argv; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 int rc, fd; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
286
diff
changeset
|
24 rc = fd_open(argv[1], strtoul(argv[2], 0, 16), &fd); |
286
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 if (rc) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return(rc); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 printf("%d\n", fd); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 return(0); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 cmd_fd_read(argc, argv) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 char **argv; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 u_char databuf[MAX_READ_DATA]; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 int rc, sz, off, l; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 rc = fd_read(strtoul(argv[1], 0, 0), databuf, strtoul(argv[2], 0, 0), |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 &sz); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (rc) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 return(rc); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 printf("%d bytes read\n", sz); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 for (off = 0; off < sz; off += 16) { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 l = sz - off; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (l > 16) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 l = 16; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 hexdump_line(off, databuf + off, l); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return(0); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 cmd_fd_close(argc, argv) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 char **argv; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 return fd_close(strtoul(argv[1], 0, 0)); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 struct cmdtab fd_cmds[] = { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 {"close", 1, 1, cmd_fd_close}, |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 {"open", 2, 2, cmd_fd_open}, |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 {"read", 2, 2, cmd_fd_read}, |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 {0, 0, 0, 0} |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 }; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 cmd_fd(argc, argv) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 char **argv; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 struct cmdtab *tp; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 int extargs; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 for (tp = fd_cmds; tp->cmd; tp++) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 if (!strcmp(tp->cmd, argv[1])) |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 break; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (!tp->func) { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 fprintf(stderr, "error: no such fd command\n"); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 return(ERROR_USAGE); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 extargs = argc - 2; |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 if (extargs > tp->maxargs) { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 fprintf(stderr, "error: too many arguments\n"); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 return(ERROR_USAGE); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 if (extargs < tp->minargs) { |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 fprintf(stderr, "error: too few arguments\n"); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 return(ERROR_USAGE); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 } |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 return tp->func(argc - 1, argv + 1); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 } |