Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only
lwip/core/snmp/asn1_enc.c@0:8f5825f330b0, 2011-09-08 (annotated)
- Committer:
- RodColeman
- Date:
- Thu Sep 08 10:41:36 2011 +0000
- Revision:
- 0:8f5825f330b0
setDataLen hacked to 180bytes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 0:8f5825f330b0 | 1 | /** |
RodColeman | 0:8f5825f330b0 | 2 | * @file |
RodColeman | 0:8f5825f330b0 | 3 | * Abstract Syntax Notation One (ISO 8824, 8825) encoding |
RodColeman | 0:8f5825f330b0 | 4 | * |
RodColeman | 0:8f5825f330b0 | 5 | * @todo not optimised (yet), favor correctness over speed, favor speed over size |
RodColeman | 0:8f5825f330b0 | 6 | */ |
RodColeman | 0:8f5825f330b0 | 7 | |
RodColeman | 0:8f5825f330b0 | 8 | /* |
RodColeman | 0:8f5825f330b0 | 9 | * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. |
RodColeman | 0:8f5825f330b0 | 10 | * All rights reserved. |
RodColeman | 0:8f5825f330b0 | 11 | * |
RodColeman | 0:8f5825f330b0 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
RodColeman | 0:8f5825f330b0 | 13 | * are permitted provided that the following conditions are met: |
RodColeman | 0:8f5825f330b0 | 14 | * |
RodColeman | 0:8f5825f330b0 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
RodColeman | 0:8f5825f330b0 | 16 | * this list of conditions and the following disclaimer. |
RodColeman | 0:8f5825f330b0 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
RodColeman | 0:8f5825f330b0 | 18 | * this list of conditions and the following disclaimer in the documentation |
RodColeman | 0:8f5825f330b0 | 19 | * and/or other materials provided with the distribution. |
RodColeman | 0:8f5825f330b0 | 20 | * 3. The name of the author may not be used to endorse or promote products |
RodColeman | 0:8f5825f330b0 | 21 | * derived from this software without specific prior written permission. |
RodColeman | 0:8f5825f330b0 | 22 | * |
RodColeman | 0:8f5825f330b0 | 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
RodColeman | 0:8f5825f330b0 | 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
RodColeman | 0:8f5825f330b0 | 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
RodColeman | 0:8f5825f330b0 | 26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
RodColeman | 0:8f5825f330b0 | 27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
RodColeman | 0:8f5825f330b0 | 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
RodColeman | 0:8f5825f330b0 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
RodColeman | 0:8f5825f330b0 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
RodColeman | 0:8f5825f330b0 | 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
RodColeman | 0:8f5825f330b0 | 32 | * OF SUCH DAMAGE. |
RodColeman | 0:8f5825f330b0 | 33 | * |
RodColeman | 0:8f5825f330b0 | 34 | * Author: Christiaan Simons <christiaan.simons@axon.tv> |
RodColeman | 0:8f5825f330b0 | 35 | */ |
RodColeman | 0:8f5825f330b0 | 36 | |
RodColeman | 0:8f5825f330b0 | 37 | #include "lwip/opt.h" |
RodColeman | 0:8f5825f330b0 | 38 | |
RodColeman | 0:8f5825f330b0 | 39 | #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ |
RodColeman | 0:8f5825f330b0 | 40 | |
RodColeman | 0:8f5825f330b0 | 41 | #include "lwip/snmp_asn1.h" |
RodColeman | 0:8f5825f330b0 | 42 | |
RodColeman | 0:8f5825f330b0 | 43 | /** |
RodColeman | 0:8f5825f330b0 | 44 | * Returns octet count for length. |
RodColeman | 0:8f5825f330b0 | 45 | * |
RodColeman | 0:8f5825f330b0 | 46 | * @param length |
RodColeman | 0:8f5825f330b0 | 47 | * @param octets_needed points to the return value |
RodColeman | 0:8f5825f330b0 | 48 | */ |
RodColeman | 0:8f5825f330b0 | 49 | void |
RodColeman | 0:8f5825f330b0 | 50 | snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed) |
RodColeman | 0:8f5825f330b0 | 51 | { |
RodColeman | 0:8f5825f330b0 | 52 | if (length < 0x80U) |
RodColeman | 0:8f5825f330b0 | 53 | { |
RodColeman | 0:8f5825f330b0 | 54 | *octets_needed = 1; |
RodColeman | 0:8f5825f330b0 | 55 | } |
RodColeman | 0:8f5825f330b0 | 56 | else if (length < 0x100U) |
RodColeman | 0:8f5825f330b0 | 57 | { |
RodColeman | 0:8f5825f330b0 | 58 | *octets_needed = 2; |
RodColeman | 0:8f5825f330b0 | 59 | } |
RodColeman | 0:8f5825f330b0 | 60 | else |
RodColeman | 0:8f5825f330b0 | 61 | { |
RodColeman | 0:8f5825f330b0 | 62 | *octets_needed = 3; |
RodColeman | 0:8f5825f330b0 | 63 | } |
RodColeman | 0:8f5825f330b0 | 64 | } |
RodColeman | 0:8f5825f330b0 | 65 | |
RodColeman | 0:8f5825f330b0 | 66 | /** |
RodColeman | 0:8f5825f330b0 | 67 | * Returns octet count for an u32_t. |
RodColeman | 0:8f5825f330b0 | 68 | * |
RodColeman | 0:8f5825f330b0 | 69 | * @param value |
RodColeman | 0:8f5825f330b0 | 70 | * @param octets_needed points to the return value |
RodColeman | 0:8f5825f330b0 | 71 | * |
RodColeman | 0:8f5825f330b0 | 72 | * @note ASN coded integers are _always_ signed. E.g. +0xFFFF is coded |
RodColeman | 0:8f5825f330b0 | 73 | * as 0x00,0xFF,0xFF. Note the leading sign octet. A positive value |
RodColeman | 0:8f5825f330b0 | 74 | * of 0xFFFFFFFF is preceded with 0x00 and the length is 5 octets!! |
RodColeman | 0:8f5825f330b0 | 75 | */ |
RodColeman | 0:8f5825f330b0 | 76 | void |
RodColeman | 0:8f5825f330b0 | 77 | snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed) |
RodColeman | 0:8f5825f330b0 | 78 | { |
RodColeman | 0:8f5825f330b0 | 79 | if (value < 0x80UL) |
RodColeman | 0:8f5825f330b0 | 80 | { |
RodColeman | 0:8f5825f330b0 | 81 | *octets_needed = 1; |
RodColeman | 0:8f5825f330b0 | 82 | } |
RodColeman | 0:8f5825f330b0 | 83 | else if (value < 0x8000UL) |
RodColeman | 0:8f5825f330b0 | 84 | { |
RodColeman | 0:8f5825f330b0 | 85 | *octets_needed = 2; |
RodColeman | 0:8f5825f330b0 | 86 | } |
RodColeman | 0:8f5825f330b0 | 87 | else if (value < 0x800000UL) |
RodColeman | 0:8f5825f330b0 | 88 | { |
RodColeman | 0:8f5825f330b0 | 89 | *octets_needed = 3; |
RodColeman | 0:8f5825f330b0 | 90 | } |
RodColeman | 0:8f5825f330b0 | 91 | else if (value < 0x80000000UL) |
RodColeman | 0:8f5825f330b0 | 92 | { |
RodColeman | 0:8f5825f330b0 | 93 | *octets_needed = 4; |
RodColeman | 0:8f5825f330b0 | 94 | } |
RodColeman | 0:8f5825f330b0 | 95 | else |
RodColeman | 0:8f5825f330b0 | 96 | { |
RodColeman | 0:8f5825f330b0 | 97 | *octets_needed = 5; |
RodColeman | 0:8f5825f330b0 | 98 | } |
RodColeman | 0:8f5825f330b0 | 99 | } |
RodColeman | 0:8f5825f330b0 | 100 | |
RodColeman | 0:8f5825f330b0 | 101 | /** |
RodColeman | 0:8f5825f330b0 | 102 | * Returns octet count for an s32_t. |
RodColeman | 0:8f5825f330b0 | 103 | * |
RodColeman | 0:8f5825f330b0 | 104 | * @param value |
RodColeman | 0:8f5825f330b0 | 105 | * @param octets_needed points to the return value |
RodColeman | 0:8f5825f330b0 | 106 | * |
RodColeman | 0:8f5825f330b0 | 107 | * @note ASN coded integers are _always_ signed. |
RodColeman | 0:8f5825f330b0 | 108 | */ |
RodColeman | 0:8f5825f330b0 | 109 | void |
RodColeman | 0:8f5825f330b0 | 110 | snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed) |
RodColeman | 0:8f5825f330b0 | 111 | { |
RodColeman | 0:8f5825f330b0 | 112 | if (value < 0) |
RodColeman | 0:8f5825f330b0 | 113 | { |
RodColeman | 0:8f5825f330b0 | 114 | value = ~value; |
RodColeman | 0:8f5825f330b0 | 115 | } |
RodColeman | 0:8f5825f330b0 | 116 | if (value < 0x80L) |
RodColeman | 0:8f5825f330b0 | 117 | { |
RodColeman | 0:8f5825f330b0 | 118 | *octets_needed = 1; |
RodColeman | 0:8f5825f330b0 | 119 | } |
RodColeman | 0:8f5825f330b0 | 120 | else if (value < 0x8000L) |
RodColeman | 0:8f5825f330b0 | 121 | { |
RodColeman | 0:8f5825f330b0 | 122 | *octets_needed = 2; |
RodColeman | 0:8f5825f330b0 | 123 | } |
RodColeman | 0:8f5825f330b0 | 124 | else if (value < 0x800000L) |
RodColeman | 0:8f5825f330b0 | 125 | { |
RodColeman | 0:8f5825f330b0 | 126 | *octets_needed = 3; |
RodColeman | 0:8f5825f330b0 | 127 | } |
RodColeman | 0:8f5825f330b0 | 128 | else |
RodColeman | 0:8f5825f330b0 | 129 | { |
RodColeman | 0:8f5825f330b0 | 130 | *octets_needed = 4; |
RodColeman | 0:8f5825f330b0 | 131 | } |
RodColeman | 0:8f5825f330b0 | 132 | } |
RodColeman | 0:8f5825f330b0 | 133 | |
RodColeman | 0:8f5825f330b0 | 134 | /** |
RodColeman | 0:8f5825f330b0 | 135 | * Returns octet count for an object identifier. |
RodColeman | 0:8f5825f330b0 | 136 | * |
RodColeman | 0:8f5825f330b0 | 137 | * @param ident_len object identifier array length |
RodColeman | 0:8f5825f330b0 | 138 | * @param ident points to object identifier array |
RodColeman | 0:8f5825f330b0 | 139 | * @param octets_needed points to the return value |
RodColeman | 0:8f5825f330b0 | 140 | */ |
RodColeman | 0:8f5825f330b0 | 141 | void |
RodColeman | 0:8f5825f330b0 | 142 | snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed) |
RodColeman | 0:8f5825f330b0 | 143 | { |
RodColeman | 0:8f5825f330b0 | 144 | s32_t sub_id; |
RodColeman | 0:8f5825f330b0 | 145 | u8_t cnt; |
RodColeman | 0:8f5825f330b0 | 146 | |
RodColeman | 0:8f5825f330b0 | 147 | cnt = 0; |
RodColeman | 0:8f5825f330b0 | 148 | if (ident_len > 1) |
RodColeman | 0:8f5825f330b0 | 149 | { |
RodColeman | 0:8f5825f330b0 | 150 | /* compressed prefix in one octet */ |
RodColeman | 0:8f5825f330b0 | 151 | cnt++; |
RodColeman | 0:8f5825f330b0 | 152 | ident_len -= 2; |
RodColeman | 0:8f5825f330b0 | 153 | ident += 2; |
RodColeman | 0:8f5825f330b0 | 154 | } |
RodColeman | 0:8f5825f330b0 | 155 | while(ident_len > 0) |
RodColeman | 0:8f5825f330b0 | 156 | { |
RodColeman | 0:8f5825f330b0 | 157 | ident_len--; |
RodColeman | 0:8f5825f330b0 | 158 | sub_id = *ident; |
RodColeman | 0:8f5825f330b0 | 159 | |
RodColeman | 0:8f5825f330b0 | 160 | sub_id >>= 7; |
RodColeman | 0:8f5825f330b0 | 161 | cnt++; |
RodColeman | 0:8f5825f330b0 | 162 | while(sub_id > 0) |
RodColeman | 0:8f5825f330b0 | 163 | { |
RodColeman | 0:8f5825f330b0 | 164 | sub_id >>= 7; |
RodColeman | 0:8f5825f330b0 | 165 | cnt++; |
RodColeman | 0:8f5825f330b0 | 166 | } |
RodColeman | 0:8f5825f330b0 | 167 | ident++; |
RodColeman | 0:8f5825f330b0 | 168 | } |
RodColeman | 0:8f5825f330b0 | 169 | *octets_needed = cnt; |
RodColeman | 0:8f5825f330b0 | 170 | } |
RodColeman | 0:8f5825f330b0 | 171 | |
RodColeman | 0:8f5825f330b0 | 172 | /** |
RodColeman | 0:8f5825f330b0 | 173 | * Encodes ASN type field into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 174 | * |
RodColeman | 0:8f5825f330b0 | 175 | * @param p points to output pbuf to encode value into |
RodColeman | 0:8f5825f330b0 | 176 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 177 | * @param type input ASN1 type |
RodColeman | 0:8f5825f330b0 | 178 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 179 | */ |
RodColeman | 0:8f5825f330b0 | 180 | err_t |
RodColeman | 0:8f5825f330b0 | 181 | snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type) |
RodColeman | 0:8f5825f330b0 | 182 | { |
RodColeman | 0:8f5825f330b0 | 183 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 184 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 185 | |
RodColeman | 0:8f5825f330b0 | 186 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 187 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 188 | { |
RodColeman | 0:8f5825f330b0 | 189 | base = plen; |
RodColeman | 0:8f5825f330b0 | 190 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 191 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 192 | { |
RodColeman | 0:8f5825f330b0 | 193 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 194 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 195 | *msg_ptr = type; |
RodColeman | 0:8f5825f330b0 | 196 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 197 | } |
RodColeman | 0:8f5825f330b0 | 198 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 199 | } |
RodColeman | 0:8f5825f330b0 | 200 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 201 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 202 | } |
RodColeman | 0:8f5825f330b0 | 203 | |
RodColeman | 0:8f5825f330b0 | 204 | /** |
RodColeman | 0:8f5825f330b0 | 205 | * Encodes host order length field into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 206 | * |
RodColeman | 0:8f5825f330b0 | 207 | * @param p points to output pbuf to encode length into |
RodColeman | 0:8f5825f330b0 | 208 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 209 | * @param length is the host order length to be encoded |
RodColeman | 0:8f5825f330b0 | 210 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 211 | */ |
RodColeman | 0:8f5825f330b0 | 212 | err_t |
RodColeman | 0:8f5825f330b0 | 213 | snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length) |
RodColeman | 0:8f5825f330b0 | 214 | { |
RodColeman | 0:8f5825f330b0 | 215 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 216 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 217 | |
RodColeman | 0:8f5825f330b0 | 218 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 219 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 220 | { |
RodColeman | 0:8f5825f330b0 | 221 | base = plen; |
RodColeman | 0:8f5825f330b0 | 222 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 223 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 224 | { |
RodColeman | 0:8f5825f330b0 | 225 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 226 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 227 | |
RodColeman | 0:8f5825f330b0 | 228 | if (length < 0x80) |
RodColeman | 0:8f5825f330b0 | 229 | { |
RodColeman | 0:8f5825f330b0 | 230 | *msg_ptr = (u8_t)length; |
RodColeman | 0:8f5825f330b0 | 231 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 232 | } |
RodColeman | 0:8f5825f330b0 | 233 | else if (length < 0x100) |
RodColeman | 0:8f5825f330b0 | 234 | { |
RodColeman | 0:8f5825f330b0 | 235 | *msg_ptr = 0x81; |
RodColeman | 0:8f5825f330b0 | 236 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 237 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 238 | { |
RodColeman | 0:8f5825f330b0 | 239 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 240 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 241 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 242 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 243 | } |
RodColeman | 0:8f5825f330b0 | 244 | else |
RodColeman | 0:8f5825f330b0 | 245 | { |
RodColeman | 0:8f5825f330b0 | 246 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 247 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 248 | } |
RodColeman | 0:8f5825f330b0 | 249 | *msg_ptr = (u8_t)length; |
RodColeman | 0:8f5825f330b0 | 250 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 251 | } |
RodColeman | 0:8f5825f330b0 | 252 | else |
RodColeman | 0:8f5825f330b0 | 253 | { |
RodColeman | 0:8f5825f330b0 | 254 | u8_t i; |
RodColeman | 0:8f5825f330b0 | 255 | |
RodColeman | 0:8f5825f330b0 | 256 | /* length >= 0x100 && length <= 0xFFFF */ |
RodColeman | 0:8f5825f330b0 | 257 | *msg_ptr = 0x82; |
RodColeman | 0:8f5825f330b0 | 258 | i = 2; |
RodColeman | 0:8f5825f330b0 | 259 | while (i > 0) |
RodColeman | 0:8f5825f330b0 | 260 | { |
RodColeman | 0:8f5825f330b0 | 261 | i--; |
RodColeman | 0:8f5825f330b0 | 262 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 263 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 264 | { |
RodColeman | 0:8f5825f330b0 | 265 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 266 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 267 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 268 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 269 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 270 | } |
RodColeman | 0:8f5825f330b0 | 271 | else |
RodColeman | 0:8f5825f330b0 | 272 | { |
RodColeman | 0:8f5825f330b0 | 273 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 274 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 275 | } |
RodColeman | 0:8f5825f330b0 | 276 | if (i == 0) |
RodColeman | 0:8f5825f330b0 | 277 | { |
RodColeman | 0:8f5825f330b0 | 278 | /* least significant length octet */ |
RodColeman | 0:8f5825f330b0 | 279 | *msg_ptr = (u8_t)length; |
RodColeman | 0:8f5825f330b0 | 280 | } |
RodColeman | 0:8f5825f330b0 | 281 | else |
RodColeman | 0:8f5825f330b0 | 282 | { |
RodColeman | 0:8f5825f330b0 | 283 | /* most significant length octet */ |
RodColeman | 0:8f5825f330b0 | 284 | *msg_ptr = (u8_t)(length >> 8); |
RodColeman | 0:8f5825f330b0 | 285 | } |
RodColeman | 0:8f5825f330b0 | 286 | } |
RodColeman | 0:8f5825f330b0 | 287 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 288 | } |
RodColeman | 0:8f5825f330b0 | 289 | } |
RodColeman | 0:8f5825f330b0 | 290 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 291 | } |
RodColeman | 0:8f5825f330b0 | 292 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 293 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 294 | } |
RodColeman | 0:8f5825f330b0 | 295 | |
RodColeman | 0:8f5825f330b0 | 296 | /** |
RodColeman | 0:8f5825f330b0 | 297 | * Encodes u32_t (counter, gauge, timeticks) into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 298 | * |
RodColeman | 0:8f5825f330b0 | 299 | * @param p points to output pbuf to encode value into |
RodColeman | 0:8f5825f330b0 | 300 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 301 | * @param octets_needed encoding length (from snmp_asn1_enc_u32t_cnt()) |
RodColeman | 0:8f5825f330b0 | 302 | * @param value is the host order u32_t value to be encoded |
RodColeman | 0:8f5825f330b0 | 303 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 304 | * |
RodColeman | 0:8f5825f330b0 | 305 | * @see snmp_asn1_enc_u32t_cnt() |
RodColeman | 0:8f5825f330b0 | 306 | */ |
RodColeman | 0:8f5825f330b0 | 307 | err_t |
RodColeman | 0:8f5825f330b0 | 308 | snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value) |
RodColeman | 0:8f5825f330b0 | 309 | { |
RodColeman | 0:8f5825f330b0 | 310 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 311 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 312 | |
RodColeman | 0:8f5825f330b0 | 313 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 314 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 315 | { |
RodColeman | 0:8f5825f330b0 | 316 | base = plen; |
RodColeman | 0:8f5825f330b0 | 317 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 318 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 319 | { |
RodColeman | 0:8f5825f330b0 | 320 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 321 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 322 | |
RodColeman | 0:8f5825f330b0 | 323 | if (octets_needed == 5) |
RodColeman | 0:8f5825f330b0 | 324 | { |
RodColeman | 0:8f5825f330b0 | 325 | /* not enough bits in 'value' add leading 0x00 */ |
RodColeman | 0:8f5825f330b0 | 326 | octets_needed--; |
RodColeman | 0:8f5825f330b0 | 327 | *msg_ptr = 0x00; |
RodColeman | 0:8f5825f330b0 | 328 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 329 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 330 | { |
RodColeman | 0:8f5825f330b0 | 331 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 332 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 333 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 334 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 335 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 336 | } |
RodColeman | 0:8f5825f330b0 | 337 | else |
RodColeman | 0:8f5825f330b0 | 338 | { |
RodColeman | 0:8f5825f330b0 | 339 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 340 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 341 | } |
RodColeman | 0:8f5825f330b0 | 342 | } |
RodColeman | 0:8f5825f330b0 | 343 | while (octets_needed > 1) |
RodColeman | 0:8f5825f330b0 | 344 | { |
RodColeman | 0:8f5825f330b0 | 345 | octets_needed--; |
RodColeman | 0:8f5825f330b0 | 346 | *msg_ptr = (u8_t)(value >> (octets_needed << 3)); |
RodColeman | 0:8f5825f330b0 | 347 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 348 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 349 | { |
RodColeman | 0:8f5825f330b0 | 350 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 351 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 352 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 353 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 354 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 355 | } |
RodColeman | 0:8f5825f330b0 | 356 | else |
RodColeman | 0:8f5825f330b0 | 357 | { |
RodColeman | 0:8f5825f330b0 | 358 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 359 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 360 | } |
RodColeman | 0:8f5825f330b0 | 361 | } |
RodColeman | 0:8f5825f330b0 | 362 | /* (only) one least significant octet */ |
RodColeman | 0:8f5825f330b0 | 363 | *msg_ptr = (u8_t)value; |
RodColeman | 0:8f5825f330b0 | 364 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 365 | } |
RodColeman | 0:8f5825f330b0 | 366 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 367 | } |
RodColeman | 0:8f5825f330b0 | 368 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 369 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 370 | } |
RodColeman | 0:8f5825f330b0 | 371 | |
RodColeman | 0:8f5825f330b0 | 372 | /** |
RodColeman | 0:8f5825f330b0 | 373 | * Encodes s32_t integer into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 374 | * |
RodColeman | 0:8f5825f330b0 | 375 | * @param p points to output pbuf to encode value into |
RodColeman | 0:8f5825f330b0 | 376 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 377 | * @param octets_needed encoding length (from snmp_asn1_enc_s32t_cnt()) |
RodColeman | 0:8f5825f330b0 | 378 | * @param value is the host order s32_t value to be encoded |
RodColeman | 0:8f5825f330b0 | 379 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 380 | * |
RodColeman | 0:8f5825f330b0 | 381 | * @see snmp_asn1_enc_s32t_cnt() |
RodColeman | 0:8f5825f330b0 | 382 | */ |
RodColeman | 0:8f5825f330b0 | 383 | err_t |
RodColeman | 0:8f5825f330b0 | 384 | snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value) |
RodColeman | 0:8f5825f330b0 | 385 | { |
RodColeman | 0:8f5825f330b0 | 386 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 387 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 388 | |
RodColeman | 0:8f5825f330b0 | 389 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 390 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 391 | { |
RodColeman | 0:8f5825f330b0 | 392 | base = plen; |
RodColeman | 0:8f5825f330b0 | 393 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 394 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 395 | { |
RodColeman | 0:8f5825f330b0 | 396 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 397 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 398 | |
RodColeman | 0:8f5825f330b0 | 399 | while (octets_needed > 1) |
RodColeman | 0:8f5825f330b0 | 400 | { |
RodColeman | 0:8f5825f330b0 | 401 | octets_needed--; |
RodColeman | 0:8f5825f330b0 | 402 | *msg_ptr = (u8_t)(value >> (octets_needed << 3)); |
RodColeman | 0:8f5825f330b0 | 403 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 404 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 405 | { |
RodColeman | 0:8f5825f330b0 | 406 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 407 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 408 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 409 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 410 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 411 | } |
RodColeman | 0:8f5825f330b0 | 412 | else |
RodColeman | 0:8f5825f330b0 | 413 | { |
RodColeman | 0:8f5825f330b0 | 414 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 415 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 416 | } |
RodColeman | 0:8f5825f330b0 | 417 | } |
RodColeman | 0:8f5825f330b0 | 418 | /* (only) one least significant octet */ |
RodColeman | 0:8f5825f330b0 | 419 | *msg_ptr = (u8_t)value; |
RodColeman | 0:8f5825f330b0 | 420 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 421 | } |
RodColeman | 0:8f5825f330b0 | 422 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 423 | } |
RodColeman | 0:8f5825f330b0 | 424 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 425 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 426 | } |
RodColeman | 0:8f5825f330b0 | 427 | |
RodColeman | 0:8f5825f330b0 | 428 | /** |
RodColeman | 0:8f5825f330b0 | 429 | * Encodes object identifier into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 430 | * |
RodColeman | 0:8f5825f330b0 | 431 | * @param p points to output pbuf to encode oid into |
RodColeman | 0:8f5825f330b0 | 432 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 433 | * @param ident_len object identifier array length |
RodColeman | 0:8f5825f330b0 | 434 | * @param ident points to object identifier array |
RodColeman | 0:8f5825f330b0 | 435 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 436 | */ |
RodColeman | 0:8f5825f330b0 | 437 | err_t |
RodColeman | 0:8f5825f330b0 | 438 | snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident) |
RodColeman | 0:8f5825f330b0 | 439 | { |
RodColeman | 0:8f5825f330b0 | 440 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 441 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 442 | |
RodColeman | 0:8f5825f330b0 | 443 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 444 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 445 | { |
RodColeman | 0:8f5825f330b0 | 446 | base = plen; |
RodColeman | 0:8f5825f330b0 | 447 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 448 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 449 | { |
RodColeman | 0:8f5825f330b0 | 450 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 451 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 452 | |
RodColeman | 0:8f5825f330b0 | 453 | if (ident_len > 1) |
RodColeman | 0:8f5825f330b0 | 454 | { |
RodColeman | 0:8f5825f330b0 | 455 | if ((ident[0] == 1) && (ident[1] == 3)) |
RodColeman | 0:8f5825f330b0 | 456 | { |
RodColeman | 0:8f5825f330b0 | 457 | /* compressed (most common) prefix .iso.org */ |
RodColeman | 0:8f5825f330b0 | 458 | *msg_ptr = 0x2b; |
RodColeman | 0:8f5825f330b0 | 459 | } |
RodColeman | 0:8f5825f330b0 | 460 | else |
RodColeman | 0:8f5825f330b0 | 461 | { |
RodColeman | 0:8f5825f330b0 | 462 | /* calculate prefix */ |
RodColeman | 0:8f5825f330b0 | 463 | *msg_ptr = (u8_t)((ident[0] * 40) + ident[1]); |
RodColeman | 0:8f5825f330b0 | 464 | } |
RodColeman | 0:8f5825f330b0 | 465 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 466 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 467 | { |
RodColeman | 0:8f5825f330b0 | 468 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 469 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 470 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 471 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 472 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 473 | } |
RodColeman | 0:8f5825f330b0 | 474 | else |
RodColeman | 0:8f5825f330b0 | 475 | { |
RodColeman | 0:8f5825f330b0 | 476 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 477 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 478 | } |
RodColeman | 0:8f5825f330b0 | 479 | ident_len -= 2; |
RodColeman | 0:8f5825f330b0 | 480 | ident += 2; |
RodColeman | 0:8f5825f330b0 | 481 | } |
RodColeman | 0:8f5825f330b0 | 482 | else |
RodColeman | 0:8f5825f330b0 | 483 | { |
RodColeman | 0:8f5825f330b0 | 484 | /* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */ |
RodColeman | 0:8f5825f330b0 | 485 | /* ident_len <= 1, at least we need zeroDotZero (0.0) (ident_len == 2) */ |
RodColeman | 0:8f5825f330b0 | 486 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 487 | } |
RodColeman | 0:8f5825f330b0 | 488 | while (ident_len > 0) |
RodColeman | 0:8f5825f330b0 | 489 | { |
RodColeman | 0:8f5825f330b0 | 490 | s32_t sub_id; |
RodColeman | 0:8f5825f330b0 | 491 | u8_t shift, tail; |
RodColeman | 0:8f5825f330b0 | 492 | |
RodColeman | 0:8f5825f330b0 | 493 | ident_len--; |
RodColeman | 0:8f5825f330b0 | 494 | sub_id = *ident; |
RodColeman | 0:8f5825f330b0 | 495 | tail = 0; |
RodColeman | 0:8f5825f330b0 | 496 | shift = 28; |
RodColeman | 0:8f5825f330b0 | 497 | while(shift > 0) |
RodColeman | 0:8f5825f330b0 | 498 | { |
RodColeman | 0:8f5825f330b0 | 499 | u8_t code; |
RodColeman | 0:8f5825f330b0 | 500 | |
RodColeman | 0:8f5825f330b0 | 501 | code = (u8_t)(sub_id >> shift); |
RodColeman | 0:8f5825f330b0 | 502 | if ((code != 0) || (tail != 0)) |
RodColeman | 0:8f5825f330b0 | 503 | { |
RodColeman | 0:8f5825f330b0 | 504 | tail = 1; |
RodColeman | 0:8f5825f330b0 | 505 | *msg_ptr = code | 0x80; |
RodColeman | 0:8f5825f330b0 | 506 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 507 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 508 | { |
RodColeman | 0:8f5825f330b0 | 509 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 510 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 511 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 512 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 513 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 514 | } |
RodColeman | 0:8f5825f330b0 | 515 | else |
RodColeman | 0:8f5825f330b0 | 516 | { |
RodColeman | 0:8f5825f330b0 | 517 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 518 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 519 | } |
RodColeman | 0:8f5825f330b0 | 520 | } |
RodColeman | 0:8f5825f330b0 | 521 | shift -= 7; |
RodColeman | 0:8f5825f330b0 | 522 | } |
RodColeman | 0:8f5825f330b0 | 523 | *msg_ptr = (u8_t)sub_id & 0x7F; |
RodColeman | 0:8f5825f330b0 | 524 | if (ident_len > 0) |
RodColeman | 0:8f5825f330b0 | 525 | { |
RodColeman | 0:8f5825f330b0 | 526 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 527 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 528 | { |
RodColeman | 0:8f5825f330b0 | 529 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 530 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 531 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 532 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 533 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 534 | } |
RodColeman | 0:8f5825f330b0 | 535 | else |
RodColeman | 0:8f5825f330b0 | 536 | { |
RodColeman | 0:8f5825f330b0 | 537 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 538 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 539 | } |
RodColeman | 0:8f5825f330b0 | 540 | } |
RodColeman | 0:8f5825f330b0 | 541 | /* proceed to next sub-identifier */ |
RodColeman | 0:8f5825f330b0 | 542 | ident++; |
RodColeman | 0:8f5825f330b0 | 543 | } |
RodColeman | 0:8f5825f330b0 | 544 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 545 | } |
RodColeman | 0:8f5825f330b0 | 546 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 547 | } |
RodColeman | 0:8f5825f330b0 | 548 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 549 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 550 | } |
RodColeman | 0:8f5825f330b0 | 551 | |
RodColeman | 0:8f5825f330b0 | 552 | /** |
RodColeman | 0:8f5825f330b0 | 553 | * Encodes raw data (octet string, opaque) into a pbuf chained ASN1 msg. |
RodColeman | 0:8f5825f330b0 | 554 | * |
RodColeman | 0:8f5825f330b0 | 555 | * @param p points to output pbuf to encode raw data into |
RodColeman | 0:8f5825f330b0 | 556 | * @param ofs points to the offset within the pbuf chain |
RodColeman | 0:8f5825f330b0 | 557 | * @param raw_len raw data length |
RodColeman | 0:8f5825f330b0 | 558 | * @param raw points raw data |
RodColeman | 0:8f5825f330b0 | 559 | * @return ERR_OK if successfull, ERR_ARG if we can't (or won't) encode |
RodColeman | 0:8f5825f330b0 | 560 | */ |
RodColeman | 0:8f5825f330b0 | 561 | err_t |
RodColeman | 0:8f5825f330b0 | 562 | snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, u8_t *raw) |
RodColeman | 0:8f5825f330b0 | 563 | { |
RodColeman | 0:8f5825f330b0 | 564 | u16_t plen, base; |
RodColeman | 0:8f5825f330b0 | 565 | u8_t *msg_ptr; |
RodColeman | 0:8f5825f330b0 | 566 | |
RodColeman | 0:8f5825f330b0 | 567 | plen = 0; |
RodColeman | 0:8f5825f330b0 | 568 | while (p != NULL) |
RodColeman | 0:8f5825f330b0 | 569 | { |
RodColeman | 0:8f5825f330b0 | 570 | base = plen; |
RodColeman | 0:8f5825f330b0 | 571 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 572 | if (ofs < plen) |
RodColeman | 0:8f5825f330b0 | 573 | { |
RodColeman | 0:8f5825f330b0 | 574 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 575 | msg_ptr += ofs - base; |
RodColeman | 0:8f5825f330b0 | 576 | |
RodColeman | 0:8f5825f330b0 | 577 | while (raw_len > 1) |
RodColeman | 0:8f5825f330b0 | 578 | { |
RodColeman | 0:8f5825f330b0 | 579 | /* copy raw_len - 1 octets */ |
RodColeman | 0:8f5825f330b0 | 580 | raw_len--; |
RodColeman | 0:8f5825f330b0 | 581 | *msg_ptr = *raw; |
RodColeman | 0:8f5825f330b0 | 582 | raw++; |
RodColeman | 0:8f5825f330b0 | 583 | ofs += 1; |
RodColeman | 0:8f5825f330b0 | 584 | if (ofs >= plen) |
RodColeman | 0:8f5825f330b0 | 585 | { |
RodColeman | 0:8f5825f330b0 | 586 | /* next octet in next pbuf */ |
RodColeman | 0:8f5825f330b0 | 587 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 588 | if (p == NULL) { return ERR_ARG; } |
RodColeman | 0:8f5825f330b0 | 589 | msg_ptr = (u8_t*)p->payload; |
RodColeman | 0:8f5825f330b0 | 590 | plen += p->len; |
RodColeman | 0:8f5825f330b0 | 591 | } |
RodColeman | 0:8f5825f330b0 | 592 | else |
RodColeman | 0:8f5825f330b0 | 593 | { |
RodColeman | 0:8f5825f330b0 | 594 | /* next octet in same pbuf */ |
RodColeman | 0:8f5825f330b0 | 595 | msg_ptr++; |
RodColeman | 0:8f5825f330b0 | 596 | } |
RodColeman | 0:8f5825f330b0 | 597 | } |
RodColeman | 0:8f5825f330b0 | 598 | if (raw_len > 0) |
RodColeman | 0:8f5825f330b0 | 599 | { |
RodColeman | 0:8f5825f330b0 | 600 | /* copy last or single octet */ |
RodColeman | 0:8f5825f330b0 | 601 | *msg_ptr = *raw; |
RodColeman | 0:8f5825f330b0 | 602 | } |
RodColeman | 0:8f5825f330b0 | 603 | return ERR_OK; |
RodColeman | 0:8f5825f330b0 | 604 | } |
RodColeman | 0:8f5825f330b0 | 605 | p = p->next; |
RodColeman | 0:8f5825f330b0 | 606 | } |
RodColeman | 0:8f5825f330b0 | 607 | /* p == NULL, ofs >= plen */ |
RodColeman | 0:8f5825f330b0 | 608 | return ERR_ARG; |
RodColeman | 0:8f5825f330b0 | 609 | } |
RodColeman | 0:8f5825f330b0 | 610 | |
RodColeman | 0:8f5825f330b0 | 611 | #endif /* LWIP_SNMP */ |