summaryrefslogtreecommitdiff
path: root/fw/fe310/phone/cell.c
blob: 47ce8e57254836495117ff176ed180f1c44589d1 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <eos.h>
#include <dev/net.h>
#include <net/cell.h>

#include "app/log.h"
#include "cell.h"

void cell_init(void) {
    eos_cell_set_handler(EOS_CELL_MTYPE_DEV, cell_msg_handler);
}

void cell_msg_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
    switch (type) {
        case EOS_CELL_MTYPE_STATUS: {
            uint8_t status, connected;
            int rv;

            rv = eos_cell_status_parse(buffer, len, &status, &connected);
            if (rv) {
                APP_LOG(APP_LOG_ERR, "BAD STATUS ERR:%d\n", rv);
                return;
            }
            APP_LOG(APP_LOG_DEBUG, "MODEM STATUS: ");
            switch (status) {
                case EOS_CELL_STATUS_RESET: {
                    APP_LOG(APP_LOG_DEBUG, "RESET\n");
                    break;
                }

                case EOS_CELL_STATUS_IDLE: {
                    APP_LOG(APP_LOG_DEBUG, "IDLE\n");
                    break;
                }

                case EOS_CELL_STATUS_RELAY: {
                    APP_LOG(APP_LOG_DEBUG, "RELAY\n");
                    break;
                }

                case EOS_CELL_STATUS_PPP: {
                    APP_LOG(APP_LOG_DEBUG, "PPP, ");
                    if (connected) {
                        APP_LOG(APP_LOG_DEBUG, "CONNECTED\n");
                    } else {
                        APP_LOG(APP_LOG_DEBUG, "NOT CONNECTED\n");
                    }
                    break;
                }

                default: {
                    APP_LOG(APP_LOG_DEBUG, "BAD STATUS\n");
                    break;
                }
            }
            break;
        }
    }
    eos_net_free(buffer, 0);
}