Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <osmocom/core/bits.h>
- #include <osmocom/core/crc32gen.h>
- /* x24 + x23 + x21 + x20 + x19 + x17 + x16 + x15 + x13 + x8 + x7 + x5 + x4 + x2 + 1 */
- static const struct osmo_crc32gen_code fcs = {
- .bits = 24,
- .poly = 0xbba1b5,
- .init = 0xffffff,
- .remainder = 0xffffff,
- };
- static int
- rlp_process_frame(pbit_t *frame)
- {
- ubit_t fbits[240];
- int crc;
- /* Decode to bits */
- osmo_pbit2ubit_ext(fbits, 0, frame, 0, 240, 1);
- /* Check CRC */
- crc = osmo_crc32gen_check_bits(&fcs, fbits, 216, fbits+216);
- if (crc)
- return -1;
- /* Frame type */
- if (!memcmp(&fbits[3], "\x01\x01\x01\x01\x01\x01", 6))
- {
- const char *m_names[32] = {
- [ 0] = "UI",
- [ 3] = "DM",
- [ 7] = "SABM",
- [ 8] = "DISC",
- [12] = "UA",
- [15] = "NULL",
- [17] = "REMAP",
- [23] = "XID",
- [29] = "TEST",
- };
- int M;
- M = (frame[1] & 0x7c) >> 2;
- printf(" U : %s\n",
- m_names[M]
- );
- if (M == 23) {
- int i;
- for (i=0; i<30; i++)
- printf("%02x", frame[i]);
- printf("\n");
- }
- }
- else if (!memcmp(&fbits[3], "\x00\x01\x01\x01\x01\x01", 6))
- {
- const char *s_names[4] = { "RR", "RNR", "REJ", "SREJ" };
- int nr;
- nr = (frame[1] >> 5) | ((frame[2] & 0x3f) << 3);
- printf(" S : %4s - N(R) = %3d\n",
- s_names[(frame[0] & 0x06) >> 1],
- nr
- );
- }
- else
- {
- const char *s_names[4] = { "RR", "RNR", "REJ", "SREJ" };
- int ns, nr;
- ns = frame[0] | ((frame[1] & 1) << 8);
- nr = (frame[1] >> 5) | ((frame[2] & 0x3f) << 3);
- printf("I+S : %4s - N(R) = %3d N(S) = %3d\n",
- s_names[(frame[0] & 0x06) >> 1],
- nr, ns
- );
- {
- int i;
- printf("data: ");
- for (i=3; i<27; i++)
- printf("%02x", frame[i]);
- printf("\n");
- }
- }
- return 0;
- }
- int main(int argc, char *argv[])
- {
- FILE *fh;
- pbit_t frame[30];
- fh = fopen(argv[1], "rb");
- if (!fh)
- return -1;
- while (!feof(fh)) {
- fread(frame, 30, 1, fh);
- rlp_process_frame(frame);
- }
- fclose(fh);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement