Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <dev/board.h>
00034
00035 #include <sys/types.h>
00036 #include <ctype.h>
00037 #include <errno.h>
00038
00039 #include <arpa/inet.h>
00040 #include <net/route.h>
00041 #include <pro/dhcp.h>
00042
00043 #include <sys/version.h>
00044 #include <sys/timer.h>
00045
00046 #include <pro/snmp_config.h>
00047 #include <pro/snmp_mib.h>
00048 #include <pro/snmp_api.h>
00049 #include <pro/snmp_agent.h>
00050
00051 #include <stdio.h>
00052 #include <io.h>
00053
00054 #include "mib2sys.h"
00055 #include "mib2if.h"
00056
00062 static char *version = "0.2.0";
00063
00066 #define MYMAC 0x00, 0x06, 0x98, 0x33, 0x44, 0x00
00067
00070 #define MYIP "192.168.192.100"
00071
00074 #define MYMASK "255.255.255.0"
00075
00080 #define MYGATE "192.168.192.1"
00081
00083 #define MYUART DEV_CONSOLE_NAME
00084
00086 #define MYDEV DEV_CONSOLE
00087
00089 #define MYBAUD 115200
00090
00091
00092 #if defined(__IMAGECRAFT__)
00093 #if defined(__AVR__)
00094 #define COMPILERNAME "ICCAVR"
00095 #else
00096 #define COMPILERNAME "ICC"
00097 #endif
00098 #elif defined(__GNUC__)
00099 #if defined(__AVR__)
00100 #define COMPILERNAME "AVRGCC"
00101 #elif defined(__arm__)
00102 #define COMPILERNAME "ARMGCC"
00103 #else
00104 #define COMPILERNAME "GCC"
00105 #endif
00106 #else
00107 #define COMPILERNAME "Compiler unknown"
00108 #endif
00109
00110
00111 #define UART_OK 0x0001
00112 #define STDOUT_OK 0x0002
00113 #define STDERR_OK 0x0004
00114 #define BAUDRATE_OK 0x0008
00115 #define LANDEV_OK 0x0010
00116 #define NETIF_OK 0x0020
00117 #define NETROUTE_OK 0x0040
00118 #define TIMED_OK 0x0080
00119
00120 int main(void)
00121 {
00122 UDPSOCKET *sock;
00123 OID view_all[] = { SNMP_OID_INTERNET };
00124 int view_idx;
00125 uint32_t baud = MYBAUD;
00126 uint8_t mac[6] = { MYMAC };
00127 int rc = 0;
00128
00129
00130
00131
00132
00133 if (NutRegisterDevice(&MYDEV, 0, 0) == 0) {
00134 rc |= UART_OK;
00135 if (freopen(MYUART, "w", stdout)) {
00136 rc |= STDOUT_OK;
00137 if (_ioctl(_fileno(stdout), UART_SETSPEED, &baud) == 0) {
00138 rc |= BAUDRATE_OK;
00139 }
00140 }
00141 if (freopen(MYUART, "w", stderr)) {
00142 rc |= STDERR_OK;
00143 }
00144 }
00145
00146
00147
00148
00149 if (rc & STDOUT_OK) {
00150 printf("\n\nSNMP Agent %s\nNut/OS %s\n", version, NutVersionString());
00151 puts("Compiled by " COMPILERNAME);
00152 puts("Configure network");
00153 }
00154
00155
00156
00157
00158 #ifdef DEV_ETHER
00159 if (NutRegisterDevice(&DEV_ETHER, 0x8300, 5) == 0) {
00160 rc |= LANDEV_OK;
00161 if (NutDhcpIfConfig("eth0", 0, 60000) == 0) {
00162 rc |= NETIF_OK;
00163 } else if (NutDhcpIfConfig("eth0", mac, 60000) == 0) {
00164 rc |= NETIF_OK;
00165 } else if (NutNetIfConfig("eth0", mac, inet_addr(MYIP), inet_addr(MYMASK)) == 0) {
00166 rc |= NETIF_OK;
00167 #ifdef MYGATE
00168 if (NutIpRouteAdd(0, 0, inet_addr(MYGATE), &DEV_ETHER) == 0) {
00169 rc |= NETROUTE_OK;
00170 }
00171 #endif
00172 }
00173 }
00174
00175 sock = NutUdpCreateSocket(SNMP_PORT);
00176
00177 {
00178 uint16_t max_ms = SNMP_MAX_MSG_SIZE * 2;
00179 NutUdpSetSockOpt(sock, SO_RCVBUF, &max_ms, sizeof(max_ms));
00180 }
00181
00182
00183 if (MibRegisterSysVars()) {
00184 printf("Failed to register MibSys\n");
00185 for (;;)
00186 NutSleep(1000);
00187 }
00188
00189 if (MibRegisterIfVars()) {
00190 printf("Failed to register MibIf\n");
00191 for (;;)
00192 NutSleep(1000);
00193 }
00194
00195
00196 if ((view_idx = SnmpViewCreate("all", view_all, sizeof(view_all), SNMP_VIEW_INCLUDED)) <= 0) {
00197 printf("Failed to create view\n");
00198 for (;;)
00199 NutSleep(1000);
00200 }
00201
00202 if (SnmpCommunityCreate("public", view_idx, view_idx) || SnmpCommunityCreate("private", view_idx, view_idx)) {
00203 printf("Failed to create communities\n");
00204 for (;;)
00205 NutSleep(1000);
00206 }
00207
00208
00209 SnmpAgent(sock);
00210
00211
00212 NutUdpDestroySocket(sock);
00213 #endif
00214
00215 for (;;) {
00216 NutSleep(100);
00217 printf("Hello ");
00218 }
00219 return 0;
00220 }