|
@@ -10,7 +10,7 @@
|
|
|
*******************************************************************************
|
|
|
*/
|
|
|
|
|
|
-#include "stm32f4xx.h"
|
|
|
+#include "stm32f4xx.h"
|
|
|
#include "snmp_api.h"
|
|
|
#include "trap_api.h"
|
|
|
#include "settings_api.h"
|
|
@@ -66,148 +66,149 @@ QueueHandle_t SNMP_TrapQueue;
|
|
|
|
|
|
/**
|
|
|
* @brief Инициализация параметров SNMP
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_Init(void)
|
|
|
{
|
|
|
- //snmp_mib *my_snmp_mibs[] = { &mib2, &private_mib };
|
|
|
- //SETTINGS_SetSnmpDef();
|
|
|
- SNMP_AgentInit();
|
|
|
- lwip_privmib_init();
|
|
|
- //snmp_set_mibs(my_snmp_mibs, LWIP_ARRAYSIZE(my_snmp_mibs));
|
|
|
+ //snmp_mib *my_snmp_mibs[] = { &mib2, &private_mib };
|
|
|
+ //SETTINGS_SetSnmpDef();
|
|
|
+ SNMP_AgentInit();
|
|
|
+ lwip_privmib_init();
|
|
|
+ //snmp_set_mibs(my_snmp_mibs, LWIP_ARRAYSIZE(my_snmp_mibs));
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @brief Системный тик SNMP. Таск должен вызываться с частотой 100Гц.
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SysUpTimeTask(void *arg)
|
|
|
{
|
|
|
- TickType_t xLastWakeTime;
|
|
|
- const TickType_t xFrequency = 10;
|
|
|
-
|
|
|
- xLastWakeTime = xTaskGetTickCount();
|
|
|
-
|
|
|
- while(1)
|
|
|
- {
|
|
|
- vTaskDelayUntil( &xLastWakeTime, xFrequency );
|
|
|
- //snmp_inc_sysuptime();
|
|
|
- }
|
|
|
+ TickType_t xLastWakeTime;
|
|
|
+ const TickType_t xFrequency = 10;
|
|
|
+
|
|
|
+ xLastWakeTime = xTaskGetTickCount();
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+ vTaskDelayUntil( &xLastWakeTime, xFrequency );
|
|
|
+ //snmp_inc_sysuptime();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Тестовый таск для проверки отправки трапов
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void snmp_trap_tread(void *arg)
|
|
|
{
|
|
|
- uint8_t trapName;
|
|
|
-
|
|
|
- while(1)
|
|
|
- {
|
|
|
- if (xQueueReceive(SNMP_TrapQueue, &trapName, 0) == pdTRUE)
|
|
|
- {
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP);
|
|
|
- SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
-
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP2);
|
|
|
- SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
-
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP3);
|
|
|
- SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
-
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP4);
|
|
|
- SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
-
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP5);
|
|
|
- SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
- }
|
|
|
- vTaskDelay(10);
|
|
|
- }
|
|
|
+ uint8_t trapName;
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+ if (xQueueReceive(SNMP_TrapQueue, &trapName, 0) == pdTRUE) {
|
|
|
+#ifdef HARDWARE_BT6709
|
|
|
+ if(sSettings.sFlagNotification[trapName])
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP);
|
|
|
+ SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
+
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP2);
|
|
|
+ SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP3);
|
|
|
+ SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
+
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP4);
|
|
|
+ SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
+
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP5);
|
|
|
+ SNMP_SendVarbindTrap(&traps[trapName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vTaskDelay(10);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Инициализация SNMP агента
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_AgentInit(void)
|
|
|
{
|
|
|
- SNMP_SetObjDescr();
|
|
|
-
|
|
|
- SNMP_SetReadCommunity(sSettings.sSnmp.readCommunity);
|
|
|
- SNMP_SetWriteCommunity(sSettings.sSnmp.writeCommunity);
|
|
|
- SNMP_SetSysContact(&sSettings.sSnmp.sysContact);
|
|
|
- SNMP_SetSysName(&sSettings.sSnmp.sysName);
|
|
|
- SNMP_SetSysLocation(&sSettings.sSnmp.sysLocation);
|
|
|
- SNMP_SetManagerIP(sSettings.sSnmp.managerIP); //SNMP_SetManagerIP("192.168.14.37");
|
|
|
- SNMP_SetObjID();
|
|
|
- SNMP_SetTrapOnOff(1);
|
|
|
-
|
|
|
- SNMP_InitTrapsBase();
|
|
|
-
|
|
|
- snmp_init();
|
|
|
- udp_init();
|
|
|
-
|
|
|
- SNMP_TrapQueue = xQueueCreate(SNMP_TRAP_QUEUE_SIZE, sizeof(uint8_t));
|
|
|
+ SNMP_SetObjDescr();
|
|
|
+
|
|
|
+ SNMP_SetReadCommunity(sSettings.sSnmp.readCommunity);
|
|
|
+ SNMP_SetWriteCommunity(sSettings.sSnmp.writeCommunity);
|
|
|
+ SNMP_SetSysContact(&sSettings.sSnmp.sysContact);
|
|
|
+ SNMP_SetSysName(&sSettings.sSnmp.sysName);
|
|
|
+ SNMP_SetSysLocation(&sSettings.sSnmp.sysLocation);
|
|
|
+ SNMP_SetManagerIP(sSettings.sSnmp.managerIP); //SNMP_SetManagerIP("192.168.14.37");
|
|
|
+ SNMP_SetObjID();
|
|
|
+ SNMP_SetTrapOnOff(1);
|
|
|
+
|
|
|
+ SNMP_InitTrapsBase();
|
|
|
+
|
|
|
+ snmp_init();
|
|
|
+ udp_init();
|
|
|
+
|
|
|
+ SNMP_TrapQueue = xQueueCreate(SNMP_TRAP_QUEUE_SIZE, sizeof(uint8_t));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @brief Пользовательская функция для отправки трапа из массива traps[]
|
|
|
+ * @brief Пользовательская функция для отправки трапа из массива traps[]
|
|
|
* Трап помещается в очередь. Работа с очередью происходит по принципу
|
|
|
- * FIFO буфера.
|
|
|
+ * FIFO буфера.
|
|
|
* Если в настройках трапа отправка отключена, то трап игнорируется.
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SendUserTrap(uint8_t trapName)
|
|
|
{
|
|
|
- uint16_t availableSpace;
|
|
|
- uint8_t dummyTrap;
|
|
|
-
|
|
|
- if (traps[trapName].trapEnable)
|
|
|
- {
|
|
|
- availableSpace = uxQueueSpacesAvailable(SNMP_TrapQueue);
|
|
|
-
|
|
|
- if (availableSpace == 0)
|
|
|
- xQueueReceive(SNMP_TrapQueue, &dummyTrap, 0);
|
|
|
-
|
|
|
- xQueueSend(SNMP_TrapQueue, &trapName, 0);
|
|
|
- }
|
|
|
+ uint16_t availableSpace;
|
|
|
+ uint8_t dummyTrap;
|
|
|
+
|
|
|
+ if (traps[trapName].trapEnable) {
|
|
|
+ availableSpace = uxQueueSpacesAvailable(SNMP_TrapQueue);
|
|
|
+
|
|
|
+ if (availableSpace == 0) {
|
|
|
+ xQueueReceive(SNMP_TrapQueue, &dummyTrap, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ xQueueSend(SNMP_TrapQueue, &trapName, 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP Descriptor
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
// TODO
|
|
|
void SNMP_SetObjDescr(void)
|
|
|
{
|
|
|
-
|
|
|
- memset(sSettings.sSnmp.sysDesc.description, 0, sizeof(sSettings.sSnmp.sysDesc.description));
|
|
|
-
|
|
|
- strcpy(sSettings.sSnmp.sysDesc.description, HW_REV);
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, VERSION);
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
- sSettings.sSnmp.sysContact.contact[sSettings.sSnmp.sysContact.len] = 0;
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, sSettings.sSnmp.sysContact.contact);
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, sSettings.sInfo.serialNumber);
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, UPS.model);
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
- strcat(sSettings.sSnmp.sysDesc.description, UPS.serial);
|
|
|
-
|
|
|
- sSettings.sSnmp.sysDesc.len = strlen(sSettings.sSnmp.sysDesc.description);
|
|
|
- snmp_mib2_set_sysdescr((u8_t*)sSettings.sSnmp.sysDesc.description, &sSettings.sSnmp.sysDesc.len);
|
|
|
+
|
|
|
+ memset(sSettings.sSnmp.sysDesc.description, 0, sizeof(sSettings.sSnmp.sysDesc.description));
|
|
|
+
|
|
|
+ strcpy(sSettings.sSnmp.sysDesc.description, HW_REV);
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, VERSION);
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
+ sSettings.sSnmp.sysContact.contact[sSettings.sSnmp.sysContact.len] = 0;
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, sSettings.sSnmp.sysContact.contact);
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, sSettings.sInfo.serialNumber);
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, UPS.model);
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, " ");
|
|
|
+ strcat(sSettings.sSnmp.sysDesc.description, UPS.serial);
|
|
|
+
|
|
|
+ sSettings.sSnmp.sysDesc.len = strlen(sSettings.sSnmp.sysDesc.description);
|
|
|
+ snmp_mib2_set_sysdescr((u8_t *)sSettings.sSnmp.sysDesc.description, &sSettings.sSnmp.sysDesc.len);
|
|
|
}
|
|
|
|
|
|
void SNMP_SettingsSave(void)
|
|
|
{
|
|
|
- SETTINGS_Save();
|
|
|
- log_event_data(LOG_SETTING_SAVE, "Администратор (SNMP)");
|
|
|
- SNMP_SetObjDescr();
|
|
|
+ SETTINGS_Save();
|
|
|
+ log_event_data(LOG_SETTING_SAVE, "Администратор (SNMP)");
|
|
|
+ SNMP_SetObjDescr();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -215,8 +216,8 @@ void SNMP_SettingsSave(void)
|
|
|
*/
|
|
|
void SNMP_SetReadCommunity(char *comm)
|
|
|
{
|
|
|
- //strcpy(sSettings.sSnmp.readCommunity, comm);
|
|
|
- snmp_set_community(comm);
|
|
|
+ //strcpy(sSettings.sSnmp.readCommunity, comm);
|
|
|
+ snmp_set_community(comm);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -224,75 +225,75 @@ void SNMP_SetReadCommunity(char *comm)
|
|
|
*/
|
|
|
void SNMP_SetWriteCommunity(char *comm)
|
|
|
{
|
|
|
- //strcpy(sSettings.sSnmp.writeCommunity, comm);
|
|
|
- snmp_set_community_write(comm);
|
|
|
+ //strcpy(sSettings.sSnmp.writeCommunity, comm);
|
|
|
+ snmp_set_community_write(comm);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP SysContact
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetSysContact(SNMP_SYS_CONTACT_t *con)
|
|
|
{
|
|
|
- snmp_mib2_set_syscontact((u8_t*)con->contact, &con->len, (sizeof(con->contact)-1));
|
|
|
+ snmp_mib2_set_syscontact((u8_t *)con->contact, &con->len, (sizeof(con->contact) - 1));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP SysName
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetSysName(SNMP_SYS_NAME_t *name)
|
|
|
{
|
|
|
- snmp_mib2_set_sysname((u8_t*)name->name, &name->len, (sizeof(name->name)-1));
|
|
|
+ snmp_mib2_set_sysname((u8_t *)name->name, &name->len, (sizeof(name->name) - 1));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP SysLocation
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetSysLocation(SNMP_SYS_LOCATION_t *loc)
|
|
|
{
|
|
|
- snmp_mib2_set_syslocation((u8_t*)loc->location, &loc->len, (sizeof(loc->location)-1));
|
|
|
+ snmp_mib2_set_syslocation((u8_t *)loc->location, &loc->len, (sizeof(loc->location) - 1));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP SysManagerIP
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetManagerIP(char *ip)
|
|
|
{
|
|
|
- static ip_addr_t trap_addr;
|
|
|
-
|
|
|
- ipaddr_aton(ip, &trap_addr);
|
|
|
- // snmp_trap_dst_ip_set(0, &trap_addr);
|
|
|
- snmp_trap_pduv2_dst_ip_set(0, &trap_addr);
|
|
|
+ static ip_addr_t trap_addr;
|
|
|
+
|
|
|
+ ipaddr_aton(ip, &trap_addr);
|
|
|
+ // snmp_trap_dst_ip_set(0, &trap_addr);
|
|
|
+ snmp_trap_pduv2_dst_ip_set(0, &trap_addr);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Установить SNMP Object ID
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetObjID(void)
|
|
|
{
|
|
|
#ifdef HARDWARE_BT6703
|
|
|
- static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 6}};
|
|
|
+ static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 6}};
|
|
|
#elif HARDWARE_BT6707
|
|
|
- static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 7}};
|
|
|
+ static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 7}};
|
|
|
#elif HARDWARE_BT6709
|
|
|
- static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 8}};
|
|
|
+ static struct snmp_obj_id my_object_id = {9, {1, 3, 6, 1, 4, 1, 41752, 911, 8}};
|
|
|
#endif
|
|
|
-
|
|
|
- snmp_set_device_enterprise_oid(&my_object_id);
|
|
|
+
|
|
|
+ snmp_set_device_enterprise_oid(&my_object_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Вкл/выкл трапы
|
|
|
- * @retval
|
|
|
+ * @retval
|
|
|
*/
|
|
|
void SNMP_SetTrapOnOff(uint8_t state)
|
|
|
{
|
|
|
- //snmp_trap_dst_enable(0, (u8_t)state);
|
|
|
- snmp_trap_pduv2_dst_enable(0, (u8_t)state);
|
|
|
+ //snmp_trap_dst_enable(0, (u8_t)state);
|
|
|
+ snmp_trap_pduv2_dst_enable(0, (u8_t)state);
|
|
|
}
|
|
|
|
|
|
|