summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/cell_pdp.c
blob: 4c5321a9ac021e9fe50edb75b5adaa47c0717761 (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
#include <stdlib.h>
#include <string.h>

#include <esp_log.h>

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

void eos_cell_pdp_handler(unsigned char mtype, unsigned char *buffer, uint16_t buf_len) {
    char *apn, *user, *pass, *_buf;
    uint16_t _buf_len;

    switch (mtype) {
        case EOS_CELL_MTYPE_PDP_CONFIG:
            _buf = (char *)buffer;
            _buf_len = 0;

            apn = _buf;
            _buf_len = strnlen(_buf, buf_len);
            if (_buf_len == buf_len) break;
            _buf += _buf_len + 1;
            buf_len -= _buf_len + 1;

            user = _buf;
            _buf_len = strnlen(_buf, buf_len);
            if (_buf_len == buf_len) break;
            _buf += _buf_len + 1;
            buf_len -= _buf_len + 1;

            pass = _buf;
            _buf_len = strnlen(_buf, buf_len);
            if (_buf_len == buf_len) break;
            _buf += _buf_len + 1;
            buf_len -= _buf_len + 1;

            eos_ppp_set_apn(apn);
            eos_ppp_set_auth(user, pass);
            break;

        case EOS_CELL_MTYPE_PDP_CONNECT:
            eos_ppp_connect();
            break;

        case EOS_CELL_MTYPE_PDP_DISCONNECT:
            eos_ppp_disconnect();
            break;
    }
}