Skip to content

Commit

Permalink
ports/esp32/network_ppp: Get config of esp ppp interfaces via ipconfig.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Dörre <felix@dogcraft.de>
  • Loading branch information
felixdoerre committed Mar 28, 2024
1 parent 5537036 commit 92f35c0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ports/esp32/network_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ static mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ppp_ifconfig_obj, 1, 2, ppp_ifconfig);

static mp_obj_t ppp_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {

if (kwargs->used == 0) {
ppp_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
struct netif *netif = ppp_netif(self->pcb);
// Get config value
if (n_args != 1) {
mp_raise_TypeError(MP_ERROR_TEXT("must query one param"));
}

switch (mp_obj_str_get_qstr(args[0])) {
case MP_QSTR_addr4: {
mp_obj_t tuple[2] = {
netutils_format_ipv4_addr((uint8_t *)&netif->ip_addr, NETUTILS_BIG),
netutils_format_ipv4_addr((uint8_t *)&netif->netmask, NETUTILS_BIG),
};
return mp_obj_new_tuple(2, tuple);
}
case MP_QSTR_gw4: {
return netutils_format_ipv4_addr((uint8_t *)&netif->gw, NETUTILS_BIG);
}
default: {
mp_raise_ValueError(MP_ERROR_TEXT("unexpected key"));
break;
}
}
return mp_const_none;
} else {
mp_raise_TypeError(MP_ERROR_TEXT("setting properties not supported"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(ppp_ipconfig_obj, 1, ppp_ipconfig);

static mp_obj_t ppp_status(mp_obj_t self_in) {
return mp_const_none;
}
Expand Down Expand Up @@ -328,6 +362,7 @@ static const mp_rom_map_elem_t ppp_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&ppp_status_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&ppp_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&ppp_ifconfig_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&ppp_ipconfig_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&ppp_delete_obj) },
{ MP_ROM_QSTR(MP_QSTR_AUTH_NONE), MP_ROM_INT(PPPAUTHTYPE_NONE) },
{ MP_ROM_QSTR(MP_QSTR_AUTH_PAP), MP_ROM_INT(PPPAUTHTYPE_PAP) },
Expand Down

0 comments on commit 92f35c0

Please sign in to comment.