FreeCalypso > hg > gsm-net-reveng
annotate trau-ul-prep/binreader.c @ 57:fe3cdbbc96f9
d144: new program atrau-parse
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 17:45:29 +0000 |
parents | 4ab8762be333 |
children |
rev | line source |
---|---|
19
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement our binfile_read_frame() function. |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "binreader.h" |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 int binfile_read_frame(FILE *binf, uint8_t *frame) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 int cc, morelen; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 cc = fread(frame, 1, 1, binf); |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 if (cc != 1) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 return 0; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (frame[0] == 0xBF) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 morelen = 1; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 else if ((frame[0] & 0xF0) == 0xC0) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 morelen = 30; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 else if ((frame[0] & 0xF0) == 0xD0) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 morelen = 32; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 else |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return -1; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cc = fread(frame+1, 1, morelen, binf); |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (cc == morelen) |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return 1; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 else |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return -2; |
4ab8762be333
trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |