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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "lwip/opt.h"
00046
00047 #if LWIP_SNMP
00048
00049 #include "lwip/udp.h"
00050 #include "lwip/netif.h"
00051 #include "lwip/snmp.h"
00052 #include "lwip/snmp_asn1.h"
00053 #include "lwip/snmp_msg.h"
00054
00055 struct snmp_trap_dst
00056 {
00057
00058 struct ip_addr dip;
00059
00060 u8_t enable;
00061 };
00062 struct snmp_trap_dst trap_dst[SNMP_TRAP_DESTINATIONS];
00063
00064
00065 struct snmp_msg_trap trap_msg;
00066
00067 static u16_t snmp_resp_header_sum(struct snmp_msg_pstat *m_stat, u16_t vb_len);
00068 static u16_t snmp_trap_header_sum(struct snmp_msg_trap *m_trap, u16_t vb_len);
00069 static u16_t snmp_varbind_list_sum(struct snmp_varbind_root *root);
00070
00071 static u16_t snmp_resp_header_enc(struct snmp_msg_pstat *m_stat, struct pbuf *p);
00072 static u16_t snmp_trap_header_enc(struct snmp_msg_trap *m_trap, struct pbuf *p);
00073 static u16_t snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs);
00074
00075
00076
00077
00078
00079
00080 void
00081 snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
00082 {
00083 if (dst_idx < SNMP_TRAP_DESTINATIONS)
00084 {
00085 trap_dst[dst_idx].enable = enable;
00086 }
00087 }
00088
00089
00090
00091
00092
00093
00094 void
00095 snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst)
00096 {
00097 if (dst_idx < SNMP_TRAP_DESTINATIONS)
00098 {
00099 trap_dst[dst_idx].dip.addr = htonl(dst->addr);
00100 }
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 err_t
00113 snmp_send_response(struct snmp_msg_pstat *m_stat)
00114 {
00115 struct snmp_varbind_root emptyvb = {NULL, NULL, 0, 0, 0};
00116 struct pbuf *p;
00117 u16_t tot_len;
00118 err_t err;
00119
00120
00121 tot_len = snmp_varbind_list_sum(&m_stat->outvb);
00122 tot_len = snmp_resp_header_sum(m_stat, tot_len);
00123
00124
00125 p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
00126 if (p == NULL)
00127 {
00128 LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() tooBig\n"));
00129
00130
00131 m_stat->error_status = SNMP_ES_TOOBIG;
00132 m_stat->error_index = 0;
00133
00134 tot_len = snmp_varbind_list_sum(&emptyvb);
00135 tot_len = snmp_resp_header_sum(m_stat, tot_len);
00136
00137 p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
00138 }
00139 if (p != NULL)
00140 {
00141
00142 u16_t ofs;
00143
00144 LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() p != NULL\n"));
00145
00146
00147 ofs = snmp_resp_header_enc(m_stat, p);
00148 if (m_stat->error_status == SNMP_ES_TOOBIG)
00149 {
00150 snmp_varbind_list_enc(&emptyvb, p, ofs);
00151 }
00152 else
00153 {
00154 snmp_varbind_list_enc(&m_stat->outvb, p, ofs);
00155 }
00156
00157 switch (m_stat->error_status)
00158 {
00159 case SNMP_ES_TOOBIG:
00160 snmp_inc_snmpouttoobigs();
00161 break;
00162 case SNMP_ES_NOSUCHNAME:
00163 snmp_inc_snmpoutnosuchnames();
00164 break;
00165 case SNMP_ES_BADVALUE:
00166 snmp_inc_snmpoutbadvalues();
00167 break;
00168 case SNMP_ES_GENERROR:
00169 snmp_inc_snmpoutgenerrs();
00170 break;
00171 }
00172 snmp_inc_snmpoutgetresponses();
00173 snmp_inc_snmpoutpkts();
00174
00175
00176
00177 udp_connect(m_stat->pcb, &m_stat->sip, m_stat->sp);
00178 err = udp_send(m_stat->pcb, p);
00179 if (err == ERR_MEM)
00180 {
00181
00182 err = ERR_MEM;
00183 }
00184 else
00185 {
00186 err = ERR_OK;
00187 }
00188
00189 udp_disconnect(m_stat->pcb);
00190
00191 pbuf_free(p);
00192 LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() done\n"));
00193 return err;
00194 }
00195 else
00196 {
00197
00198
00199 return ERR_MEM;
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 err_t
00220 snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap)
00221 {
00222 struct snmp_trap_dst *td;
00223 struct netif *dst_if;
00224 struct ip_addr dst_ip;
00225 struct pbuf *p;
00226 u16_t i,tot_len;
00227
00228 for (i=0, td = &trap_dst[0]; i<SNMP_TRAP_DESTINATIONS; i++, td++)
00229 {
00230 if ((td->enable != 0) && (td->dip.addr != 0))
00231 {
00232
00233 trap_msg.dip.addr = td->dip.addr;
00234
00235 dst_if = ip_route(&td->dip);
00236 dst_ip.addr = ntohl(dst_if->ip_addr.addr);
00237 trap_msg.sip_raw[0] = dst_ip.addr >> 24;
00238 trap_msg.sip_raw[1] = dst_ip.addr >> 16;
00239 trap_msg.sip_raw[2] = dst_ip.addr >> 8;
00240 trap_msg.sip_raw[3] = dst_ip.addr;
00241 trap_msg.gen_trap = generic_trap;
00242 trap_msg.spc_trap = specific_trap;
00243 if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC)
00244 {
00245
00246 trap_msg.enterprise = eoid;
00247 }
00248 else
00249 {
00250
00251 snmp_get_snmpgrpid_ptr(&trap_msg.enterprise);
00252 }
00253 snmp_get_sysuptime(&trap_msg.ts);
00254
00255
00256 tot_len = snmp_varbind_list_sum(&trap_msg.outvb);
00257 tot_len = snmp_trap_header_sum(&trap_msg, tot_len);
00258
00259
00260 p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
00261 if (p != NULL)
00262 {
00263 u16_t ofs;
00264
00265
00266 ofs = snmp_trap_header_enc(&trap_msg, p);
00267 snmp_varbind_list_enc(&trap_msg.outvb, p, ofs);
00268
00269 snmp_inc_snmpouttraps();
00270 snmp_inc_snmpoutpkts();
00271
00272
00273 udp_connect(trap_msg.pcb, &trap_msg.dip, SNMP_TRAP_PORT);
00274 udp_send(trap_msg.pcb, p);
00275
00276 udp_disconnect(trap_msg.pcb);
00277
00278 pbuf_free(p);
00279 }
00280 else
00281 {
00282 return ERR_MEM;
00283 }
00284 }
00285 }
00286 return ERR_OK;
00287 }
00288
00289 void
00290 snmp_coldstart_trap(void)
00291 {
00292 trap_msg.outvb.head = NULL;
00293 trap_msg.outvb.tail = NULL;
00294 trap_msg.outvb.count = 0;
00295 snmp_send_trap(SNMP_GENTRAP_COLDSTART, NULL, 0);
00296 }
00297
00298 void
00299 snmp_authfail_trap(void)
00300 {
00301 u8_t enable;
00302 snmp_get_snmpenableauthentraps(&enable);
00303 if (enable == 1)
00304 {
00305 trap_msg.outvb.head = NULL;
00306 trap_msg.outvb.tail = NULL;
00307 trap_msg.outvb.count = 0;
00308 snmp_send_trap(SNMP_GENTRAP_AUTHFAIL, NULL, 0);
00309 }
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 static u16_t
00321 snmp_resp_header_sum(struct snmp_msg_pstat *m_stat, u16_t vb_len)
00322 {
00323 u16_t tot_len;
00324 struct snmp_resp_header_lengths *rhl;
00325
00326 rhl = &m_stat->rhl;
00327 tot_len = vb_len;
00328 snmp_asn1_enc_s32t_cnt(m_stat->error_index, &rhl->erridxlen);
00329 snmp_asn1_enc_length_cnt(rhl->erridxlen, &rhl->erridxlenlen);
00330 tot_len += 1 + rhl->erridxlenlen + rhl->erridxlen;
00331
00332 snmp_asn1_enc_s32t_cnt(m_stat->error_status, &rhl->errstatlen);
00333 snmp_asn1_enc_length_cnt(rhl->errstatlen, &rhl->errstatlenlen);
00334 tot_len += 1 + rhl->errstatlenlen + rhl->errstatlen;
00335
00336 snmp_asn1_enc_s32t_cnt(m_stat->rid, &rhl->ridlen);
00337 snmp_asn1_enc_length_cnt(rhl->ridlen, &rhl->ridlenlen);
00338 tot_len += 1 + rhl->ridlenlen + rhl->ridlen;
00339
00340 rhl->pdulen = tot_len;
00341 snmp_asn1_enc_length_cnt(rhl->pdulen, &rhl->pdulenlen);
00342 tot_len += 1 + rhl->pdulenlen;
00343
00344 rhl->comlen = m_stat->com_strlen;
00345 snmp_asn1_enc_length_cnt(rhl->comlen, &rhl->comlenlen);
00346 tot_len += 1 + rhl->comlenlen + rhl->comlen;
00347
00348 snmp_asn1_enc_s32t_cnt(snmp_version, &rhl->verlen);
00349 snmp_asn1_enc_length_cnt(rhl->verlen, &rhl->verlenlen);
00350 tot_len += 1 + rhl->verlen + rhl->verlenlen;
00351
00352 rhl->seqlen = tot_len;
00353 snmp_asn1_enc_length_cnt(rhl->seqlen, &rhl->seqlenlen);
00354 tot_len += 1 + rhl->seqlenlen;
00355
00356 return tot_len;
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 static u16_t
00368 snmp_trap_header_sum(struct snmp_msg_trap *m_trap, u16_t vb_len)
00369 {
00370 u16_t tot_len;
00371 struct snmp_trap_header_lengths *thl;
00372
00373 thl = &m_trap->thl;
00374 tot_len = vb_len;
00375
00376 snmp_asn1_enc_u32t_cnt(m_trap->ts, &thl->tslen);
00377 snmp_asn1_enc_length_cnt(thl->tslen, &thl->tslenlen);
00378 tot_len += 1 + thl->tslen + thl->tslenlen;
00379
00380 snmp_asn1_enc_s32t_cnt(m_trap->spc_trap, &thl->strplen);
00381 snmp_asn1_enc_length_cnt(thl->strplen, &thl->strplenlen);
00382 tot_len += 1 + thl->strplen + thl->strplenlen;
00383
00384 snmp_asn1_enc_s32t_cnt(m_trap->gen_trap, &thl->gtrplen);
00385 snmp_asn1_enc_length_cnt(thl->gtrplen, &thl->gtrplenlen);
00386 tot_len += 1 + thl->gtrplen + thl->gtrplenlen;
00387
00388 thl->aaddrlen = 4;
00389 snmp_asn1_enc_length_cnt(thl->aaddrlen, &thl->aaddrlenlen);
00390 tot_len += 1 + thl->aaddrlen + thl->aaddrlenlen;
00391
00392 snmp_asn1_enc_oid_cnt(m_trap->enterprise->len, &m_trap->enterprise->id[0], &thl->eidlen);
00393 snmp_asn1_enc_length_cnt(thl->eidlen, &thl->eidlenlen);
00394 tot_len += 1 + thl->eidlen + thl->eidlenlen;
00395
00396 thl->pdulen = tot_len;
00397 snmp_asn1_enc_length_cnt(thl->pdulen, &thl->pdulenlen);
00398 tot_len += 1 + thl->pdulenlen;
00399
00400 thl->comlen = sizeof(snmp_publiccommunity) - 1;
00401 snmp_asn1_enc_length_cnt(thl->comlen, &thl->comlenlen);
00402 tot_len += 1 + thl->comlenlen + thl->comlen;
00403
00404 snmp_asn1_enc_s32t_cnt(snmp_version, &thl->verlen);
00405 snmp_asn1_enc_length_cnt(thl->verlen, &thl->verlenlen);
00406 tot_len += 1 + thl->verlen + thl->verlenlen;
00407
00408 thl->seqlen = tot_len;
00409 snmp_asn1_enc_length_cnt(thl->seqlen, &thl->seqlenlen);
00410 tot_len += 1 + thl->seqlenlen;
00411
00412 return tot_len;
00413 }
00414
00415
00416
00417
00418
00419
00420
00421
00422 static u16_t
00423 snmp_varbind_list_sum(struct snmp_varbind_root *root)
00424 {
00425 struct snmp_varbind *vb;
00426 u32_t *uint_ptr;
00427 s32_t *sint_ptr;
00428 u16_t tot_len;
00429
00430 tot_len = 0;
00431 vb = root->tail;
00432 while ( vb != NULL )
00433 {
00434
00435 switch (vb->value_type)
00436 {
00437 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
00438 sint_ptr = vb->value;
00439 snmp_asn1_enc_s32t_cnt(*sint_ptr, &vb->vlen);
00440 break;
00441 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
00442 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
00443 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
00444 uint_ptr = vb->value;
00445 snmp_asn1_enc_u32t_cnt(*uint_ptr, &vb->vlen);
00446 break;
00447 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
00448 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
00449 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
00450 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
00451 vb->vlen = vb->value_len;
00452 break;
00453 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
00454 sint_ptr = vb->value;
00455 snmp_asn1_enc_oid_cnt(vb->value_len / sizeof(s32_t), sint_ptr, &vb->vlen);
00456 break;
00457 default:
00458
00459 vb->vlen = 0;
00460 break;
00461 };
00462
00463 snmp_asn1_enc_length_cnt(vb->vlen, &vb->vlenlen);
00464 snmp_asn1_enc_oid_cnt(vb->ident_len, vb->ident, &vb->olen);
00465 snmp_asn1_enc_length_cnt(vb->olen, &vb->olenlen);
00466
00467 vb->seqlen = 1 + vb->vlenlen + vb->vlen;
00468 vb->seqlen += 1 + vb->olenlen + vb->olen;
00469 snmp_asn1_enc_length_cnt(vb->seqlen, &vb->seqlenlen);
00470
00471
00472 tot_len += 1 + vb->seqlenlen + vb->seqlen;
00473
00474 vb = vb->prev;
00475 }
00476
00477
00478 root->seqlen = tot_len;
00479 snmp_asn1_enc_length_cnt(root->seqlen, &root->seqlenlen);
00480 tot_len += 1 + root->seqlenlen;
00481
00482 return tot_len;
00483 }
00484
00485
00486
00487
00488 static u16_t
00489 snmp_resp_header_enc(struct snmp_msg_pstat *m_stat, struct pbuf *p)
00490 {
00491 u16_t ofs;
00492
00493 ofs = 0;
00494 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
00495 ofs += 1;
00496 snmp_asn1_enc_length(p, ofs, m_stat->rhl.seqlen);
00497 ofs += m_stat->rhl.seqlenlen;
00498
00499 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00500 ofs += 1;
00501 snmp_asn1_enc_length(p, ofs, m_stat->rhl.verlen);
00502 ofs += m_stat->rhl.verlenlen;
00503 snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.verlen, snmp_version);
00504 ofs += m_stat->rhl.verlen;
00505
00506 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR));
00507 ofs += 1;
00508 snmp_asn1_enc_length(p, ofs, m_stat->rhl.comlen);
00509 ofs += m_stat->rhl.comlenlen;
00510 snmp_asn1_enc_raw(p, ofs, m_stat->rhl.comlen, m_stat->community);
00511 ofs += m_stat->rhl.comlen;
00512
00513 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_RESP));
00514 ofs += 1;
00515 snmp_asn1_enc_length(p, ofs, m_stat->rhl.pdulen);
00516 ofs += m_stat->rhl.pdulenlen;
00517
00518 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00519 ofs += 1;
00520 snmp_asn1_enc_length(p, ofs, m_stat->rhl.ridlen);
00521 ofs += m_stat->rhl.ridlenlen;
00522 snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.ridlen, m_stat->rid);
00523 ofs += m_stat->rhl.ridlen;
00524
00525 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00526 ofs += 1;
00527 snmp_asn1_enc_length(p, ofs, m_stat->rhl.errstatlen);
00528 ofs += m_stat->rhl.errstatlenlen;
00529 snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.errstatlen, m_stat->error_status);
00530 ofs += m_stat->rhl.errstatlen;
00531
00532 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00533 ofs += 1;
00534 snmp_asn1_enc_length(p, ofs, m_stat->rhl.erridxlen);
00535 ofs += m_stat->rhl.erridxlenlen;
00536 snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.erridxlen, m_stat->error_index);
00537 ofs += m_stat->rhl.erridxlen;
00538
00539 return ofs;
00540 }
00541
00542
00543
00544
00545 static u16_t
00546 snmp_trap_header_enc(struct snmp_msg_trap *m_trap, struct pbuf *p)
00547 {
00548 u16_t ofs;
00549
00550 ofs = 0;
00551 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
00552 ofs += 1;
00553 snmp_asn1_enc_length(p, ofs, m_trap->thl.seqlen);
00554 ofs += m_trap->thl.seqlenlen;
00555
00556 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00557 ofs += 1;
00558 snmp_asn1_enc_length(p, ofs, m_trap->thl.verlen);
00559 ofs += m_trap->thl.verlenlen;
00560 snmp_asn1_enc_s32t(p, ofs, m_trap->thl.verlen, snmp_version);
00561 ofs += m_trap->thl.verlen;
00562
00563 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR));
00564 ofs += 1;
00565 snmp_asn1_enc_length(p, ofs, m_trap->thl.comlen);
00566 ofs += m_trap->thl.comlenlen;
00567 snmp_asn1_enc_raw(p, ofs, m_trap->thl.comlen, (u8_t *)&snmp_publiccommunity[0]);
00568 ofs += m_trap->thl.comlen;
00569
00570 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_TRAP));
00571 ofs += 1;
00572 snmp_asn1_enc_length(p, ofs, m_trap->thl.pdulen);
00573 ofs += m_trap->thl.pdulenlen;
00574
00575 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID));
00576 ofs += 1;
00577 snmp_asn1_enc_length(p, ofs, m_trap->thl.eidlen);
00578 ofs += m_trap->thl.eidlenlen;
00579 snmp_asn1_enc_oid(p, ofs, m_trap->enterprise->len, &m_trap->enterprise->id[0]);
00580 ofs += m_trap->thl.eidlen;
00581
00582 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR));
00583 ofs += 1;
00584 snmp_asn1_enc_length(p, ofs, m_trap->thl.aaddrlen);
00585 ofs += m_trap->thl.aaddrlenlen;
00586 snmp_asn1_enc_raw(p, ofs, m_trap->thl.aaddrlen, &m_trap->sip_raw[0]);
00587 ofs += m_trap->thl.aaddrlen;
00588
00589 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00590 ofs += 1;
00591 snmp_asn1_enc_length(p, ofs, m_trap->thl.gtrplen);
00592 ofs += m_trap->thl.gtrplenlen;
00593 snmp_asn1_enc_u32t(p, ofs, m_trap->thl.gtrplen, m_trap->gen_trap);
00594 ofs += m_trap->thl.gtrplen;
00595
00596 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG));
00597 ofs += 1;
00598 snmp_asn1_enc_length(p, ofs, m_trap->thl.strplen);
00599 ofs += m_trap->thl.strplenlen;
00600 snmp_asn1_enc_u32t(p, ofs, m_trap->thl.strplen, m_trap->spc_trap);
00601 ofs += m_trap->thl.strplen;
00602
00603 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS));
00604 ofs += 1;
00605 snmp_asn1_enc_length(p, ofs, m_trap->thl.tslen);
00606 ofs += m_trap->thl.tslenlen;
00607 snmp_asn1_enc_u32t(p, ofs, m_trap->thl.tslen, m_trap->ts);
00608 ofs += m_trap->thl.tslen;
00609
00610 return ofs;
00611 }
00612
00613
00614
00615
00616 static u16_t
00617 snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs)
00618 {
00619 struct snmp_varbind *vb;
00620 s32_t *sint_ptr;
00621 u32_t *uint_ptr;
00622 u8_t *raw_ptr;
00623
00624 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
00625 ofs += 1;
00626 snmp_asn1_enc_length(p, ofs, root->seqlen);
00627 ofs += root->seqlenlen;
00628
00629 vb = root->head;
00630 while ( vb != NULL )
00631 {
00632 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
00633 ofs += 1;
00634 snmp_asn1_enc_length(p, ofs, vb->seqlen);
00635 ofs += vb->seqlenlen;
00636
00637 snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID));
00638 ofs += 1;
00639 snmp_asn1_enc_length(p, ofs, vb->olen);
00640 ofs += vb->olenlen;
00641 snmp_asn1_enc_oid(p, ofs, vb->ident_len, &vb->ident[0]);
00642 ofs += vb->olen;
00643
00644 snmp_asn1_enc_type(p, ofs, vb->value_type);
00645 ofs += 1;
00646 snmp_asn1_enc_length(p, ofs, vb->vlen);
00647 ofs += vb->vlenlen;
00648
00649 switch (vb->value_type)
00650 {
00651 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
00652 sint_ptr = vb->value;
00653 snmp_asn1_enc_s32t(p, ofs, vb->vlen, *sint_ptr);
00654 break;
00655 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
00656 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
00657 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
00658 uint_ptr = vb->value;
00659 snmp_asn1_enc_u32t(p, ofs, vb->vlen, *uint_ptr);
00660 break;
00661 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
00662 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
00663 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
00664 raw_ptr = vb->value;
00665 snmp_asn1_enc_raw(p, ofs, vb->vlen, raw_ptr);
00666 break;
00667 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
00668 break;
00669 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
00670 sint_ptr = vb->value;
00671 snmp_asn1_enc_oid(p, ofs, vb->value_len / sizeof(s32_t), sint_ptr);
00672 break;
00673 default:
00674
00675 break;
00676 };
00677 ofs += vb->vlen;
00678 vb = vb->next;
00679 }
00680 return ofs;
00681 }
00682
00683 #endif