Skip to content

Commit

Permalink
SNMP: Add Uptime OID, so make it easier to catch modem reboots.
Browse files Browse the repository at this point in the history
Makefile: update build arguments to remove one warning
  • Loading branch information
elafargue committed May 19, 2020
1 parent 909a522 commit 70d717d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ C_FLAGS += -DARM_MATH_CM4
C_FLAGS += -include
C_FLAGS += mbed_config.h

CXX_FLAGS += -std=gnu++98
CXX_FLAGS += -std=gnu++11
CXX_FLAGS += -fno-rtti
CXX_FLAGS += -Wvla
CXX_FLAGS += -D__MBED__=1
Expand Down
17 changes: 15 additions & 2 deletions source/SNMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ dataEntryType snmpData[] =
// SysDescr Entry
{8, {0x2b, 6, 1, 2, 1, 1, 1, 0}, ASN_OCTETSTRING, 6, {"NPR-70"}, NULL, NULL},

// SysUptime Entry (not working yet)
// {8, {0x2b, 6, 1, 2, 1, 1, 3, 0}, ASN_TIMETICKS, 0, { .intval = 0x2345 }, NULL, NULL},
// SysUptime Entry
{8, {0x2b, 6, 1, 2, 1, 1, 3, 0}, ASN_TIMETICKS, 0, {}, snmpGetUptime, NULL},

// 1.3.6.1.4.1.54539 (Wizkers)
// .100 (NPR-70)
Expand Down Expand Up @@ -78,6 +78,12 @@ void hexdump(uint8_t *buffer, uint16_t len)
printf("\r\n");
}

void snmpGetUptime(void *ptr, uint8_t *len) {
time_t seconds = time(NULL);
*(uint32_t *)ptr = (uint32_t)(seconds*100); // Time in 100th of a second
*len = 4;
}

void snmpGetVar(void *ptr, uint8_t *len, const uint32_t var) {
*(uint32_t *)ptr = (uint32_t)(var);
*len = 4;
Expand Down Expand Up @@ -625,6 +631,13 @@ int8_t parse_snmp()
return 0;
}

/**
* Initialize the SNMP stack
*/
void snmp_init() {
set_time(0);
}

/**
* Called at regular intervals and acts if the SNMP socket contains data
*/
Expand Down
3 changes: 2 additions & 1 deletion source/SNMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ typedef struct {
* Very simplistic implementation of a SNMP agent that will return basic stats
* on the modem. Read only, community is 'public'
*/
void snmp_init(uint8_t snmp_socket);
void snmp_init();
void snmp_loop(W5500_chip* W5500);
void snmpGetUptime(void *ptr, uint8_t *len);
void snmpGetTemp(void *ptr, uint8_t *len); // Get system temperature callback
void snmpGetLinkStatus(void *ptr, uint8_t *len);
void snmpGetLinkDistance(void *ptr, uint8_t *len);
Expand Down
2 changes: 2 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ int main()
G_PTT_PA_pin = &PTT_PA_pin;

reset_DHCP_table(LAN_conf_p);

snmp_init();

spi_2.format(8,0);
spi_1.format(8,0);
Expand Down

0 comments on commit 70d717d

Please sign in to comment.