summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/cell_pdp.c
blob: 9ff3ed783d8a32c755c15fd87e37ea6e7f295639 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdlib.h>
#include <string.h>

#include <esp_log.h>

#include "eos.h"
#include "net.h"
#include "cell.h"

void eos_cell_pdp_handler(unsigned char _mtype, EOSMessage *msg, uint16_t len) {
    unsigned char mtype;
    unsigned char *buffer = msg->buffer;

    if (len < 1) return;

    mtype = buffer[0] & ~EOS_CELL_MTYPE_MASK;

    switch (mtype) {
        case EOS_CELL_MTYPE_PDP_SET_APN:
        case EOS_CELL_MTYPE_PDP_SET_USR:
        case EOS_CELL_MTYPE_PDP_SET_PWD: {
            char arg[EOS_CELL_PDP_SIZE_ARG + 1];

            buffer++;
            len--;

            if (len > EOS_CELL_PDP_SIZE_ARG) break;

            memcpy(arg, buffer, len);
            arg[len] = '\0';

            switch (mtype) {
                case EOS_CELL_MTYPE_PDP_SET_APN: {
                    eos_ppp_set_apn(arg);
                    break;

                }
                case EOS_CELL_MTYPE_PDP_SET_USR: {
                    eos_ppp_set_usr(arg);
                    break;

                }
                case EOS_CELL_MTYPE_PDP_SET_PWD: {
                    eos_ppp_set_pwd(arg);
                    break;
                }
            }
            break;
        }

        case EOS_CELL_MTYPE_PDP_GET_APN:
        case EOS_CELL_MTYPE_PDP_GET_USR:
        case EOS_CELL_MTYPE_PDP_GET_PWD: {
            char arg[EOS_CELL_PDP_SIZE_ARG + 1];

            if (!(eos_msg_flags(msg) & EOS_MSG_FLAG_RPLY_REQ)) break;
            if (msg->size < EOS_CELL_PDP_SIZE_ARG + 1) break;

            buffer[0] = EOS_CELL_MTYPE_PDP | mtype;
            switch (mtype) {
                case EOS_CELL_MTYPE_PDP_GET_APN: {
                    eos_ppp_get_apn(arg);
                    break;

                }
                case EOS_CELL_MTYPE_PDP_GET_USR: {
                    eos_ppp_get_usr(arg);
                    break;

                }
                case EOS_CELL_MTYPE_PDP_GET_PWD: {
                    eos_ppp_get_pwd(arg);
                    break;
                }
            }
            memcpy(buffer + 1, arg, strlen(arg));

            eos_net_reply(EOS_NET_MTYPE_CELL, msg, strlen(arg) + 1);
            break;
        }

        case EOS_CELL_MTYPE_PDP_CONNECT: {
            eos_ppp_connect();
            break;
        }

        case EOS_CELL_MTYPE_PDP_DISCONNECT: {
            eos_ppp_disconnect();
            break;
        }
    }
}