/[H8]/trunk/docs/MCHPStack2.20/Source/SNMP.h
ViewVC logotype

Contents of /trunk/docs/MCHPStack2.20/Source/SNMP.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue May 1 08:17:39 2007 UTC (17 years, 1 month ago) by hedin
File MIME type: text/plain
File size: 16904 byte(s)
Removed tcpip stack 4.02 and added tcpip stack 2.20.
1 /*********************************************************************
2 *
3 * SNMP Defs for Microchip TCP/IP Stack
4 *
5 *********************************************************************
6 * FileName: SNMP.h
7 * Dependencies: StackTsk.h
8 * UDP.h
9 * Processor: PIC18
10 * Complier: MCC18 v1.00.50 or higher
11 * HITECH PICC-18 V8.10PL1 or higher
12 * Company: Microchip Technology, Inc.
13 *
14 * Software License Agreement
15 *
16 * The software supplied herewith by Microchip Technology Incorporated
17 * (the “Company”) for its PICmicro® Microcontroller is intended and
18 * supplied to you, the Company’s customer, for use solely and
19 * exclusively on Microchip PICmicro Microcontroller products. The
20 * software is owned by the Company and/or its supplier, and is
21 * protected under applicable copyright laws. All rights are reserved.
22 * Any use in violation of the foregoing restrictions may subject the
23 * user to criminal sanctions under applicable laws, as well as to
24 * civil liability for the breach of the terms and conditions of this
25 * license.
26 *
27 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
28 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
31 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33 *
34 * Author Date Comment
35 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 * Nilesh Rajbharti 1/9/03 Original (Rev 1.0)
37 ********************************************************************/
38 #ifndef SNMP_H
39 #define SNMP_H
40
41 #include "stacktsk.h"
42
43 /*
44 * This is the file that contains SNMP BIB file.
45 * File name must contain all upper case letter and must match
46 * with what was included in MPFS image.
47 */
48 #define SNMP_BIB_FILE_NAME "SNMP.BIB"
49
50
51 /*
52 * This is the maximum length for community string.
53 * Application must ensure that this length is observed.
54 * SNMP module does not check for length overflow.
55 */
56 #define SNMP_COMMUNITY_MAX_LEN (8)
57 #define NOTIFY_COMMUNITY_LEN (SNMP_COMMUNITY_MAX_LEN)
58
59 /*
60 * Change this to match your OID string length.
61 */
62 #define OID_MAX_LEN (15)
63
64
65
66 #define SNMP_START_OF_VAR (0)
67 #define SNMP_END_OF_VAR (0xff)
68 #define SNMP_INDEX_INVALID (0xff)
69
70 /*********************************************************************
71 * Function: void SNMPInit(void)
72 *
73 * PreCondition: At least one UDP socket must be available.
74 * UDPInit() is already called.
75 *
76 * Input: None
77 *
78 * Output: SNMP agent module is initialized.
79 *
80 * Side Effects: One UDP socket will be used.
81 *
82 * Overview: Initialize SNMP module internals
83 *
84 * Note: This function is called only once during lifetime
85 * of the application.
86 ********************************************************************/
87 void SNMPInit(void);
88
89 /*********************************************************************
90 * Function: BOOL SNMPTask(void)
91 *
92 * PreCondition: SNMPInit is already called.
93 *
94 * Input: None
95 *
96 * Output: TRUE if SNMP module has finished with a state
97 * FALSE if a state has not been finished.
98 *
99 *
100 * Side Effects: None
101 *
102 * Overview: Handle incoming SNMP requests as well as any
103 * outgoing SNMP responses and timeout conditions
104 *
105 * Note: None.
106 ********************************************************************/
107 BOOL SNMPTask(void);
108
109
110 /*
111 * This is the SNMP OID variable id.
112 * This id is assigned via MIB file. Only dynamic and AgentID
113 * variables can contian ID. MIB2BIB utility enforces this
114 * rules when BIB was generated.
115 */
116 typedef BYTE SNMP_ID;
117 typedef BYTE SNMP_INDEX;
118
119 typedef union _SNMP_VAL
120 {
121 DWORD dword;
122 WORD word;
123 BYTE byte;
124 BYTE v[sizeof(DWORD)];
125 } SNMP_VAL;
126
127 /*********************************************************************
128 * Function: BOOL SNMPGetVar(SNMP_ID var, SNMP_INDEX index,
129 * BYTE *ref, SNMP_VAL* val)
130 *
131 * PreCondition: None
132 *
133 * Input: var - Variable id whose value is to be returned
134 * index - Index of variable that should be
135 * transferred
136 * ref - Variable reference used to transfer
137 * multi-byte data
138 * It is always SNMP_START_OF_VAR when very
139 * first byte is requested.
140 * Otherwise, use this as a reference to
141 * keep track of multi-byte transfers.
142 * val - Pointer to up to 4 byte buffer.
143 * If var data type is BYTE, transfer data
144 * in val->byte
145 * If var data type is WORD, transfer data in
146 * val->word
147 * If var data type is DWORD, transfer data in
148 * val->dword
149 * If var data type is IP_ADDRESS, transfer data
150 * in val->v[] or val->dword
151 * If var data type is COUNTER32, TIME_TICKS or
152 * GAUGE32, transfer data in val->dword
153 * If var data type is ASCII_STRING or OCTET_STRING
154 * transfer data in val->byte using multi-byte
155 * transfer mechanism.
156 *
157 * Output: TRUE if a value exists for given variable at given
158 * index.
159 * FALSE otherwise.
160 *
161 * Side Effects: None
162 *
163 * Overview: This is a callback function called by SNMP module.
164 * SNMP user must implement this function in
165 * user application and provide appropriate data when
166 * called.
167 *
168 * Note: None
169 ********************************************************************/
170 #ifdef THIS_IS_SNMP_SERVER
171 extern BOOL SNMPGetVar(SNMP_ID var, SNMP_INDEX index,
172 BYTE *ref, SNMP_VAL* val);
173 #endif
174
175
176 /*********************************************************************
177 * Function: BOOL SNMPGetNextIndex(SNMP_ID var,
178 * SNMP_INDEX *index)
179 *
180 * PreCondition: None
181 *
182 * Input: var - Variable id whose value is to be returned
183 * idnex - Next Index of variable that should be
184 * transferred
185 *
186 * Output: TRUE if a next index value exists for given variable at given
187 * index and index parameter contains next valid index.
188 * FALSE otherwise.
189 *
190 * Side Effects: None
191 *
192 * Overview: This is a callback function called by SNMP module.
193 * SNMP user must implement this function in
194 * user application and provide appropriate data when
195 * called. This function will only be called for
196 * OID variable of type sequence.
197 *
198 * Note: None
199 ********************************************************************/
200 #ifdef THIS_IS_SNMP_SERVER
201 extern BOOL SNMPGetNextIndex(SNMP_ID var, SNMP_INDEX *index);
202 #endif
203
204
205 /*********************************************************************
206 * Function: BOOL SNMPIsValidSetLen(SNMP_ID var, BYTE len)
207 *
208 * PreCondition: None
209 *
210 * Input: var - Variable id whose value is to be set
211 * len - Length value that is to be validated.
212 *
213 * Output: TRUE if given var can be set to given len
214 * FALSE if otherwise.
215 *
216 * Side Effects: None
217 *
218 * Overview: This is a callback function called by module.
219 * User application must implement this function.
220 *
221 * Note: This function will be called for only variables
222 * that are defined as ASCII_STRING and OCTET_STRING
223 * (i.e. data length greater than 4 bytes)
224 ********************************************************************/
225 #ifdef THIS_IS_SNMP_SERVER
226 extern BOOL SNMPIsValidSetLen(SNMP_ID var, BYTE len);
227 #endif
228
229
230 /*********************************************************************
231 * Function: BOOL SNMPSetVar(SNMP_ID var, SNMP_INDEX index,
232 * BYTE ref, SNMP_VAL val)
233 *
234 * PreCondition: None
235 *
236 * Input: var - Variable id whose value is to be set
237 * ref - Variable reference used to transfer
238 * multi-byte data
239 * 0 if first byte is set
240 * otherwise nonzero value to indicate
241 * corresponding byte being set.
242 * val - Up to 4 byte data value.
243 * If var data type is BYTE, variable
244 * value is in val->byte
245 * If var data type is WORD, variable
246 * value is in val->word
247 * If var data type is DWORD, variable
248 * value is in val->dword.
249 * If var data type is IP_ADDRESS, COUNTER32,
250 * or GAUGE32, value is in val->dword
251 * If var data type is OCTET_STRING, ASCII_STRING
252 * value is in val->byte; multi-byte transfer
253 * will be performed to transfer remaining
254 * bytes of data.
255 *
256 * Output: TRUE if it is OK to set more byte(s).
257 * FALSE if otherwise.
258 *
259 * Side Effects: None
260 *
261 * Overview: This is a callback function called by module.
262 * User application must implement this function.
263 *
264 * Note: This function may get called more than once
265 * depending on number of bytes in a specific
266 * set request for given variable.
267 ********************************************************************/
268 #ifdef THIS_IS_SNMP_SERVER
269 extern BOOL SNMPSetVar(SNMP_ID var, SNMP_INDEX index,
270 BYTE ref, SNMP_VAL val);
271 #endif
272
273
274
275 /*
276 * This is the list of SNMP action a remote NMS can perform.
277 * This inforamtion is passed to application via
278 * callback SNMPValidate.
279 * Application should validate the action for given community
280 * string.
281 */
282 typedef enum _SNMP_ACTION
283 {
284 SNMP_GET = 0xa0,
285 SNMP_GET_NEXT = 0xa1,
286 SNMP_GET_RESPONSE = 0xa2,
287 SNMP_SET = 0xa3,
288 SNMP_TRAP = 0xa4,
289 SNMP_ACTION_UNKNOWN = 0
290 } SNMP_ACTION;
291
292 /*********************************************************************
293 * Function: BOOL SNMPValidate(SNMP_ACTION SNMPAction,
294 * char* community)
295 *
296 * PreCondition: SNMPInit is already called.
297 *
298 * Input: SNMPAction - SNMP_GET to fetch a variable
299 * SNMP_SET to write to a variable
300 * community - Community string as sent by NMS
301 *
302 * Output: TRUE if password matches with given community
303 * FALSE if otherwise.
304 *
305 * Side Effects: None
306 *
307 * Overview: This is a callback function called by module.
308 * User application must implement this function
309 * and verify that community matches with predefined
310 * value.
311 *
312 * Note: This validation occurs for each NMS request.
313 ********************************************************************/
314 #ifdef THIS_IS_SNMP_SERVER
315 extern BOOL SNMPValidate(SNMP_ACTION SNMPAction, char* community);
316 #endif
317
318
319
320 /*********************************************************************
321 * Function: void SNMPNotifyPrepare(IP_ADDR *remoteHost,
322 * char *community,
323 * BYTE communityLen,
324 * SNMP_ID agentIDVar,
325 * BYTE notificationCode,
326 * DWORD timestamp)
327 *
328 * PreCondition: SNMPInit is already called.
329 *
330 * Input: remoteHost - pointer to remote Host IP address
331 * community - Community string to use to notify
332 * communityLen- Community string length
333 * agentIDVar - System ID to use identify this agent
334 * notificaitonCode - Notification Code to use
335 * timestamp - Notification timestamp in 100th
336 * of second.
337 *
338 * Output: None
339 *
340 * Side Effects: None
341 *
342 * Overview: This function prepares SNMP module to send SNMP
343 * trap (notification) to remote host.
344 *
345 * Note: This is first of series of functions to complete
346 * SNMP notification.
347 ********************************************************************/
348 void SNMPNotifyPrepare(IP_ADDR *remoteHost,
349 char *community,
350 BYTE communityLen,
351 SNMP_ID agentIDVar,
352 BYTE notificationCode,
353 DWORD timestamp);
354
355
356 /*********************************************************************
357 * Function: BOOL SNMPIsNotifyReady(IP_ADDR *remoteHost)
358 *
359 * PreCondition: SNMPNotifyPrepare is already called and returned
360 * TRUE.
361 *
362 * Input: remoteHost - pointer to remote Host IP address
363 *
364 * Output: TRUE if remoteHost IP address is resolved and
365 * SNMPNotify may be called.
366 * FALSE otherwise.
367 * This would fail if there were not UDP socket
368 * to open.
369 *
370 * Side Effects: None
371 *
372 * Overview: This function resolves given remoteHost IP address
373 * into MAC address using ARP module.
374 * If remoteHost is not aviailable, this function
375 * would never return TRUE.
376 * Application must implement timeout logic to
377 * handle "remoteHost not avialable" situation.
378 *
379 * Note: None
380 ********************************************************************/
381 BOOL SNMPIsNotifyReady(IP_ADDR *remoteHost);
382
383
384 /*********************************************************************
385 * Function: BOOL SNMPNotify(SNMP_ID var,
386 * SNMP_VAL val,
387 * SNMP_INDEX index)
388 *
389 * PreCondition: SNMPIsNotified is already called and returned
390 * TRUE.
391 *
392 * Input: var - SNMP var ID that is to be used in
393 * notification
394 * val - Value of var. Only value of
395 * BYTE, WORD or DWORD can be sent.
396 * index - Index of var. If this var is a single,
397 * index would be 0, or else if this var
398 * is a sequence, index could be any
399 * value from 0 to 127.
400 *
401 * Output: TRUE if SNMP notification was successful sent.
402 * This does not guarantee that remoteHost recieved
403 * it.
404 * FALSE otherwise.
405 * This would fail under following contions:
406 * 1) Given SNMP_BIB_FILE does not exist in MPFS
407 * 2) Given var does not exist.
408 * 3) Previously given agentID does not exist
409 * 4) Data type of given var is unknown - only
410 * possible if MPFS itself was corrupted.
411 *
412 * Side Effects: None
413 *
414 * Overview: This function creates SNMP trap PDU and sends it
415 * to previously specified remoteHost.
416 *
417 * Note: None
418 ********************************************************************/
419 BOOL SNMPNotify(SNMP_ID var, SNMP_VAL val, SNMP_INDEX index);
420
421
422
423
424
425 #endif

  ViewVC Help
Powered by ViewVC 1.1.20