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 <stdio.h>
00036 #include <io.h>
00037 #include <sys/types.h>
00038 #include <ctype.h>
00039 #include <errno.h>
00040
00041 #include <arpa/inet.h>
00042 #include <net/route.h>
00043 #include <pro/dhcp.h>
00044
00045 #include <sys/version.h>
00046 #include <sys/timer.h>
00047
00048 #include <pro/snmp_config.h>
00049 #include <pro/snmp_mib.h>
00050 #include <pro/snmp_api.h>
00051 #include <pro/snmp_agent.h>
00052 #include "mib2sys.h"
00053 #include "mib2if.h"
00054
00060 static char *version = "0.2.0";
00061
00064 #define MYMAC 0x00, 0x06, 0x98, 0x33, 0x44, 0x00
00065
00068 #define MYIP "192.168.192.100"
00069
00072 #define MYMASK "255.255.255.0"
00073
00078 #define MYGATE "192.168.192.1"
00079
00081 #define MYUART DEV_DEBUG_NAME
00082
00084 #define MYDEV DEV_DEBUG
00085
00087 #define MYBAUD 115200
00088
00089
00090 #if defined(__IMAGECRAFT__)
00091 #if defined(__AVR__)
00092 #define COMPILERNAME "ICCAVR"
00093 #else
00094 #define COMPILERNAME "ICC"
00095 #endif
00096 #elif defined(__GNUC__)
00097 #if defined(__AVR__)
00098 #define COMPILERNAME "AVRGCC"
00099 #elif defined(__arm__)
00100 #define COMPILERNAME "ARMGCC"
00101 #else
00102 #define COMPILERNAME "GCC"
00103 #endif
00104 #else
00105 #define COMPILERNAME "Compiler unknown"
00106 #endif
00107
00108
00109 #define UART_OK 0x0001
00110 #define STDOUT_OK 0x0002
00111 #define STDERR_OK 0x0004
00112 #define BAUDRATE_OK 0x0008
00113 #define LANDEV_OK 0x0010
00114 #define NETIF_OK 0x0020
00115 #define NETROUTE_OK 0x0040
00116 #define TIMED_OK 0x0080
00117
00118 int main(void)
00119 {
00120 UDPSOCKET *sock;
00121 OID view_all[] = { SNMP_OID_INTERNET };
00122 int view_idx;
00123 u_long baud = MYBAUD;
00124 u_char mac[6] = { MYMAC };
00125 int rc = 0;
00126
00127
00128
00129
00130
00131 if (NutRegisterDevice(&MYDEV, 0, 0) == 0) {
00132 rc |= UART_OK;
00133 if (freopen(MYUART, "w", stdout)) {
00134 rc |= STDOUT_OK;
00135 if (_ioctl(_fileno(stdout), UART_SETSPEED, &baud) == 0) {
00136 rc |= BAUDRATE_OK;
00137 }
00138 }
00139 if (freopen(MYUART, "w", stderr)) {
00140 rc |= STDERR_OK;
00141 }
00142 }
00143
00144
00145
00146
00147 if (rc & STDOUT_OK) {
00148 printf("\n\nSNMP Agent %s\nNut/OS %s\n", version, NutVersionString());
00149 puts("Compiled by " COMPILERNAME);
00150 puts("Configure network");
00151 }
00152
00153
00154
00155
00156 if (NutRegisterDevice(&DEV_ETHER, 0x8300, 5) == 0) {
00157 rc |= LANDEV_OK;
00158 if (NutDhcpIfConfig("eth0", 0, 60000) == 0) {
00159 rc |= NETIF_OK;
00160 } else if (NutDhcpIfConfig("eth0", mac, 60000) == 0) {
00161 rc |= NETIF_OK;
00162 } else if (NutNetIfConfig("eth0", mac, inet_addr(MYIP), inet_addr(MYMASK)) == 0) {
00163 rc |= NETIF_OK;
00164 #ifdef MYGATE
00165 if (NutIpRouteAdd(0, 0, inet_addr(MYGATE), &DEV_ETHER) == 0) {
00166 rc |= NETROUTE_OK;
00167 }
00168 #endif
00169 }
00170 }
00171
00172 sock = NutUdpCreateSocket(SNMP_PORT);
00173
00174 {
00175 u_short max_ms = SNMP_MAX_MSG_SIZE * 2;
00176 NutUdpSetSockOpt(sock, SO_RCVBUF, &max_ms, sizeof(max_ms));
00177 }
00178
00179
00180 if (MibRegisterSysVars()) {
00181 printf("Failed to register MibSys\n");
00182 for (;;)
00183 NutSleep(1000);
00184 }
00185
00186 if (MibRegisterIfVars()) {
00187 printf("Failed to register MibIf\n");
00188 for (;;)
00189 NutSleep(1000);
00190 }
00191
00192
00193 if ((view_idx = SnmpViewCreate("all", view_all, sizeof(view_all), SNMP_VIEW_INCLUDED)) <= 0) {
00194 printf("Failed to create view\n");
00195 for (;;)
00196 NutSleep(1000);
00197 }
00198
00199 if (SnmpCommunityCreate("public", view_idx, view_idx) || SnmpCommunityCreate("private", view_idx, view_idx)) {
00200 printf("Failed to create communities\n");
00201 for (;;)
00202 NutSleep(1000);
00203 }
00204
00205
00206 SnmpAgent(sock);
00207
00208
00209 NutUdpDestroySocket(sock);
00210 for (;;) {
00211 NutSleep(100);
00212 printf("Hello ");
00213 }
00214 return 0;
00215 }