-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhex_import.c
68 lines (54 loc) · 1.17 KB
/
hex_import.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "diag_input.h"
#include "bit_func.h"
#include "assert.h"
#include <osmocom/core/utils.h>
int main(int argc, char *argv[])
{
uint8_t msg[4096];
int len = 0;
char diag_hex[4096];
char *ptr = NULL;
unsigned unused1, unused2;
if (argc < 3) {
printf("Not enough arguments\n");
printf("Usage: %s <session_info id> <cell_info id>\n", argv[0]);
fflush(stdout);
return -1;
}
diag_init(atoi(argv[1]), atoi(argv[2]), NULL, NULL, 0);
printf("PARSER_OK\n");
fflush(stdout);
for (;;) {
/* Get one line from stdin */
ptr = fgets(diag_hex, sizeof(diag_hex), stdin);
if (!ptr) {
break;
}
/* Skip empty lines */
len = strlen(diag_hex);
if (len == 0 || (diag_hex[0] == '\n')) {
continue;
}
/* Cut trailing \n */
if (diag_hex[len-1] == '\r') {
len--;
}
if (diag_hex[len-1] == '\n') {
len--;
}
diag_hex[len] = 0;
/* Prepare data buffer */
memset(msg, 0x2b, sizeof(msg));
/* Parse hex into binary */
len = osmo_hexparse(diag_hex, msg, sizeof(msg));
assert(len >= 0);
if (len > 0) {
handle_diag(msg, len);
}
}
diag_destroy(&unused1, &unused2);
return 0;
}