Webserver+3d print
cyclone_tcp/mibs/mib2_impl.c@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file mib2_impl.c |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief MIB-II module implementation |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 30 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 31 | #include "mibs/mib_common.h" |
Sergunb | 0:8918a71cdbe9 | 32 | #include "mibs/mib2_module.h" |
Sergunb | 0:8918a71cdbe9 | 33 | #include "mibs/mib2_impl.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "crypto.h" |
Sergunb | 0:8918a71cdbe9 | 35 | #include "asn1.h" |
Sergunb | 0:8918a71cdbe9 | 36 | #include "oid.h" |
Sergunb | 0:8918a71cdbe9 | 37 | #include "debug.h" |
Sergunb | 0:8918a71cdbe9 | 38 | |
Sergunb | 0:8918a71cdbe9 | 39 | //Check TCP/IP stack configuration |
Sergunb | 0:8918a71cdbe9 | 40 | #if (MIB2_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 41 | |
Sergunb | 0:8918a71cdbe9 | 42 | |
Sergunb | 0:8918a71cdbe9 | 43 | /** |
Sergunb | 0:8918a71cdbe9 | 44 | * @brief MIB-II module initialization |
Sergunb | 0:8918a71cdbe9 | 45 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 46 | **/ |
Sergunb | 0:8918a71cdbe9 | 47 | |
Sergunb | 0:8918a71cdbe9 | 48 | error_t mib2Init(void) |
Sergunb | 0:8918a71cdbe9 | 49 | { |
Sergunb | 0:8918a71cdbe9 | 50 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 51 | Mib2SysGroup *sysGroup; |
Sergunb | 0:8918a71cdbe9 | 52 | Mib2IfGroup *ifGroup; |
Sergunb | 0:8918a71cdbe9 | 53 | #if (IPV4_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 54 | Mib2IpGroup *ipGroup; |
Sergunb | 0:8918a71cdbe9 | 55 | #endif |
Sergunb | 0:8918a71cdbe9 | 56 | #if (TCP_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 57 | Mib2TcpGroup *tcpGroup; |
Sergunb | 0:8918a71cdbe9 | 58 | #endif |
Sergunb | 0:8918a71cdbe9 | 59 | |
Sergunb | 0:8918a71cdbe9 | 60 | //Debug message |
Sergunb | 0:8918a71cdbe9 | 61 | TRACE_INFO("Initializing standard MIB-II base...\r\n"); |
Sergunb | 0:8918a71cdbe9 | 62 | |
Sergunb | 0:8918a71cdbe9 | 63 | //Clear MIB-II base |
Sergunb | 0:8918a71cdbe9 | 64 | memset(&mib2Base, 0, sizeof(mib2Base)); |
Sergunb | 0:8918a71cdbe9 | 65 | |
Sergunb | 0:8918a71cdbe9 | 66 | //Point to the system group |
Sergunb | 0:8918a71cdbe9 | 67 | sysGroup = &mib2Base.sysGroup; |
Sergunb | 0:8918a71cdbe9 | 68 | |
Sergunb | 0:8918a71cdbe9 | 69 | #if (MIB2_SYS_DESCR_SIZE > 0) |
Sergunb | 0:8918a71cdbe9 | 70 | //sysDescr object |
Sergunb | 0:8918a71cdbe9 | 71 | strcpy(sysGroup->sysDescr, "Description"); |
Sergunb | 0:8918a71cdbe9 | 72 | sysGroup->sysDescrLen = strlen(sysGroup->sysDescr); |
Sergunb | 0:8918a71cdbe9 | 73 | #endif |
Sergunb | 0:8918a71cdbe9 | 74 | |
Sergunb | 0:8918a71cdbe9 | 75 | #if (MIB2_SYS_OBJECT_ID_SIZE > 0) |
Sergunb | 0:8918a71cdbe9 | 76 | //sysObjectID object |
Sergunb | 0:8918a71cdbe9 | 77 | sysGroup->sysObjectID[0] = 0; |
Sergunb | 0:8918a71cdbe9 | 78 | sysGroup->sysObjectIDLen = 1; |
Sergunb | 0:8918a71cdbe9 | 79 | #endif |
Sergunb | 0:8918a71cdbe9 | 80 | |
Sergunb | 0:8918a71cdbe9 | 81 | #if (MIB2_SYS_CONTACT_SIZE > 0) |
Sergunb | 0:8918a71cdbe9 | 82 | //sysContact object |
Sergunb | 0:8918a71cdbe9 | 83 | strcpy(sysGroup->sysContact, "Contact"); |
Sergunb | 0:8918a71cdbe9 | 84 | sysGroup->sysContactLen = strlen(sysGroup->sysContact); |
Sergunb | 0:8918a71cdbe9 | 85 | #endif |
Sergunb | 0:8918a71cdbe9 | 86 | |
Sergunb | 0:8918a71cdbe9 | 87 | #if (MIB2_SYS_NAME_SIZE > 0) |
Sergunb | 0:8918a71cdbe9 | 88 | //sysName object |
Sergunb | 0:8918a71cdbe9 | 89 | strcpy(sysGroup->sysName, "Name"); |
Sergunb | 0:8918a71cdbe9 | 90 | sysGroup->sysNameLen = strlen(sysGroup->sysName); |
Sergunb | 0:8918a71cdbe9 | 91 | #endif |
Sergunb | 0:8918a71cdbe9 | 92 | |
Sergunb | 0:8918a71cdbe9 | 93 | #if (MIB2_SYS_LOCATION_SIZE > 0) |
Sergunb | 0:8918a71cdbe9 | 94 | //sysLocation object |
Sergunb | 0:8918a71cdbe9 | 95 | strcpy(sysGroup->sysLocation, "Location"); |
Sergunb | 0:8918a71cdbe9 | 96 | sysGroup->sysLocationLen = strlen(sysGroup->sysLocation); |
Sergunb | 0:8918a71cdbe9 | 97 | #endif |
Sergunb | 0:8918a71cdbe9 | 98 | |
Sergunb | 0:8918a71cdbe9 | 99 | //sysServices object |
Sergunb | 0:8918a71cdbe9 | 100 | sysGroup->sysServices = MIB2_SYS_SERVICE_INTERNET; |
Sergunb | 0:8918a71cdbe9 | 101 | |
Sergunb | 0:8918a71cdbe9 | 102 | //Point to the interfaces group |
Sergunb | 0:8918a71cdbe9 | 103 | ifGroup = &mib2Base.ifGroup; |
Sergunb | 0:8918a71cdbe9 | 104 | |
Sergunb | 0:8918a71cdbe9 | 105 | //Interfaces table entry |
Sergunb | 0:8918a71cdbe9 | 106 | for(i = 0; i < NET_INTERFACE_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 107 | { |
Sergunb | 0:8918a71cdbe9 | 108 | //ifSpecific object |
Sergunb | 0:8918a71cdbe9 | 109 | ifGroup->ifTable[i].ifSpecific[0] = 0; |
Sergunb | 0:8918a71cdbe9 | 110 | ifGroup->ifTable[i].ifSpecificLen = 1; |
Sergunb | 0:8918a71cdbe9 | 111 | } |
Sergunb | 0:8918a71cdbe9 | 112 | |
Sergunb | 0:8918a71cdbe9 | 113 | #if (IPV4_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 114 | //Point to the IP group |
Sergunb | 0:8918a71cdbe9 | 115 | ipGroup = &mib2Base.ipGroup; |
Sergunb | 0:8918a71cdbe9 | 116 | |
Sergunb | 0:8918a71cdbe9 | 117 | //ipForwarding object |
Sergunb | 0:8918a71cdbe9 | 118 | ipGroup->ipForwarding = MIB2_IP_FORWARDING_DISABLED; |
Sergunb | 0:8918a71cdbe9 | 119 | //ipDefaultTTL object |
Sergunb | 0:8918a71cdbe9 | 120 | ipGroup->ipDefaultTTL = IPV4_DEFAULT_TTL; |
Sergunb | 0:8918a71cdbe9 | 121 | //ipReasmTimeout object |
Sergunb | 0:8918a71cdbe9 | 122 | ipGroup->ipReasmTimeout = IPV4_FRAG_TIME_TO_LIVE / 1000; |
Sergunb | 0:8918a71cdbe9 | 123 | #endif |
Sergunb | 0:8918a71cdbe9 | 124 | |
Sergunb | 0:8918a71cdbe9 | 125 | #if (TCP_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 126 | //Point to the TCP group |
Sergunb | 0:8918a71cdbe9 | 127 | tcpGroup = &mib2Base.tcpGroup; |
Sergunb | 0:8918a71cdbe9 | 128 | |
Sergunb | 0:8918a71cdbe9 | 129 | //tcpRtoAlgorithm object |
Sergunb | 0:8918a71cdbe9 | 130 | tcpGroup->tcpRtoAlgorithm = MIB2_TCP_RTO_ALGORITHM_VANJ; |
Sergunb | 0:8918a71cdbe9 | 131 | //tcpRtoMin object |
Sergunb | 0:8918a71cdbe9 | 132 | tcpGroup->tcpRtoMin = TCP_MIN_RTO; |
Sergunb | 0:8918a71cdbe9 | 133 | //tcpRtoMax object |
Sergunb | 0:8918a71cdbe9 | 134 | tcpGroup->tcpRtoMax = TCP_MAX_RTO; |
Sergunb | 0:8918a71cdbe9 | 135 | //tcpMaxConn object |
Sergunb | 0:8918a71cdbe9 | 136 | tcpGroup->tcpMaxConn = SOCKET_MAX_COUNT; |
Sergunb | 0:8918a71cdbe9 | 137 | #endif |
Sergunb | 0:8918a71cdbe9 | 138 | |
Sergunb | 0:8918a71cdbe9 | 139 | //Successful processing |
Sergunb | 0:8918a71cdbe9 | 140 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 141 | } |
Sergunb | 0:8918a71cdbe9 | 142 | |
Sergunb | 0:8918a71cdbe9 | 143 | |
Sergunb | 0:8918a71cdbe9 | 144 | /** |
Sergunb | 0:8918a71cdbe9 | 145 | * @brief Lock MIB-II base |
Sergunb | 0:8918a71cdbe9 | 146 | **/ |
Sergunb | 0:8918a71cdbe9 | 147 | |
Sergunb | 0:8918a71cdbe9 | 148 | void mib2Lock(void) |
Sergunb | 0:8918a71cdbe9 | 149 | { |
Sergunb | 0:8918a71cdbe9 | 150 | //Get exclusive access |
Sergunb | 0:8918a71cdbe9 | 151 | osAcquireMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 152 | } |
Sergunb | 0:8918a71cdbe9 | 153 | |
Sergunb | 0:8918a71cdbe9 | 154 | |
Sergunb | 0:8918a71cdbe9 | 155 | /** |
Sergunb | 0:8918a71cdbe9 | 156 | * @brief Unlock MIB-II base |
Sergunb | 0:8918a71cdbe9 | 157 | **/ |
Sergunb | 0:8918a71cdbe9 | 158 | |
Sergunb | 0:8918a71cdbe9 | 159 | void mib2Unlock(void) |
Sergunb | 0:8918a71cdbe9 | 160 | { |
Sergunb | 0:8918a71cdbe9 | 161 | //Release exclusive access |
Sergunb | 0:8918a71cdbe9 | 162 | osReleaseMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 163 | } |
Sergunb | 0:8918a71cdbe9 | 164 | |
Sergunb | 0:8918a71cdbe9 | 165 | |
Sergunb | 0:8918a71cdbe9 | 166 | /** |
Sergunb | 0:8918a71cdbe9 | 167 | * @brief Get sysUpTime object value |
Sergunb | 0:8918a71cdbe9 | 168 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 169 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 170 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 171 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 172 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 173 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 174 | **/ |
Sergunb | 0:8918a71cdbe9 | 175 | |
Sergunb | 0:8918a71cdbe9 | 176 | error_t mib2GetSysUpTime(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 177 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 178 | { |
Sergunb | 0:8918a71cdbe9 | 179 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 180 | value->timeTicks = osGetSystemTime() / 10; |
Sergunb | 0:8918a71cdbe9 | 181 | //Successful processing |
Sergunb | 0:8918a71cdbe9 | 182 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 183 | } |
Sergunb | 0:8918a71cdbe9 | 184 | |
Sergunb | 0:8918a71cdbe9 | 185 | |
Sergunb | 0:8918a71cdbe9 | 186 | /** |
Sergunb | 0:8918a71cdbe9 | 187 | * @brief Get ifEntry object value |
Sergunb | 0:8918a71cdbe9 | 188 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 189 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 190 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 191 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 192 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 193 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 194 | **/ |
Sergunb | 0:8918a71cdbe9 | 195 | |
Sergunb | 0:8918a71cdbe9 | 196 | error_t mib2GetIfEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 197 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 198 | { |
Sergunb | 0:8918a71cdbe9 | 199 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 200 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 201 | uint_t index; |
Sergunb | 0:8918a71cdbe9 | 202 | Mib2IfEntry *entry; |
Sergunb | 0:8918a71cdbe9 | 203 | |
Sergunb | 0:8918a71cdbe9 | 204 | //Point to the instance identifier |
Sergunb | 0:8918a71cdbe9 | 205 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 206 | |
Sergunb | 0:8918a71cdbe9 | 207 | //The ifIndex is used as instance identifier |
Sergunb | 0:8918a71cdbe9 | 208 | error = mibDecodeIndex(oid, oidLen, &n, &index); |
Sergunb | 0:8918a71cdbe9 | 209 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 210 | if(error) |
Sergunb | 0:8918a71cdbe9 | 211 | return error; |
Sergunb | 0:8918a71cdbe9 | 212 | |
Sergunb | 0:8918a71cdbe9 | 213 | //Sanity check |
Sergunb | 0:8918a71cdbe9 | 214 | if(n != oidLen) |
Sergunb | 0:8918a71cdbe9 | 215 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 216 | |
Sergunb | 0:8918a71cdbe9 | 217 | //Check index range |
Sergunb | 0:8918a71cdbe9 | 218 | if(index < 1 || index > NET_INTERFACE_COUNT) |
Sergunb | 0:8918a71cdbe9 | 219 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 220 | |
Sergunb | 0:8918a71cdbe9 | 221 | //Point to the interface table entry |
Sergunb | 0:8918a71cdbe9 | 222 | entry = &mib2Base.ifGroup.ifTable[index - 1]; |
Sergunb | 0:8918a71cdbe9 | 223 | |
Sergunb | 0:8918a71cdbe9 | 224 | //ifIndex object? |
Sergunb | 0:8918a71cdbe9 | 225 | if(!strcmp(object->name, "ifIndex")) |
Sergunb | 0:8918a71cdbe9 | 226 | { |
Sergunb | 0:8918a71cdbe9 | 227 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 228 | value->integer = entry->ifIndex; |
Sergunb | 0:8918a71cdbe9 | 229 | } |
Sergunb | 0:8918a71cdbe9 | 230 | //ifDescr object? |
Sergunb | 0:8918a71cdbe9 | 231 | else if(!strcmp(object->name, "ifDescr")) |
Sergunb | 0:8918a71cdbe9 | 232 | { |
Sergunb | 0:8918a71cdbe9 | 233 | //Make sure the buffer is large enough to hold the entire object |
Sergunb | 0:8918a71cdbe9 | 234 | if(*valueLen >= entry->ifDescrLen) |
Sergunb | 0:8918a71cdbe9 | 235 | { |
Sergunb | 0:8918a71cdbe9 | 236 | //Copy object value |
Sergunb | 0:8918a71cdbe9 | 237 | memcpy(value->octetString, entry->ifDescr, entry->ifDescrLen); |
Sergunb | 0:8918a71cdbe9 | 238 | //Return object length |
Sergunb | 0:8918a71cdbe9 | 239 | *valueLen = entry->ifDescrLen; |
Sergunb | 0:8918a71cdbe9 | 240 | } |
Sergunb | 0:8918a71cdbe9 | 241 | else |
Sergunb | 0:8918a71cdbe9 | 242 | { |
Sergunb | 0:8918a71cdbe9 | 243 | //Report an error |
Sergunb | 0:8918a71cdbe9 | 244 | error = ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 245 | } |
Sergunb | 0:8918a71cdbe9 | 246 | } |
Sergunb | 0:8918a71cdbe9 | 247 | //ifType object? |
Sergunb | 0:8918a71cdbe9 | 248 | else if(!strcmp(object->name, "ifType")) |
Sergunb | 0:8918a71cdbe9 | 249 | { |
Sergunb | 0:8918a71cdbe9 | 250 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 251 | value->integer = entry->ifType; |
Sergunb | 0:8918a71cdbe9 | 252 | } |
Sergunb | 0:8918a71cdbe9 | 253 | //ifMtu object? |
Sergunb | 0:8918a71cdbe9 | 254 | else if(!strcmp(object->name, "ifMtu")) |
Sergunb | 0:8918a71cdbe9 | 255 | { |
Sergunb | 0:8918a71cdbe9 | 256 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 257 | value->integer = entry->ifMtu; |
Sergunb | 0:8918a71cdbe9 | 258 | } |
Sergunb | 0:8918a71cdbe9 | 259 | //ifSpeed object? |
Sergunb | 0:8918a71cdbe9 | 260 | else if(!strcmp(object->name, "ifSpeed")) |
Sergunb | 0:8918a71cdbe9 | 261 | { |
Sergunb | 0:8918a71cdbe9 | 262 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 263 | value->gauge32 = entry->ifSpeed; |
Sergunb | 0:8918a71cdbe9 | 264 | } |
Sergunb | 0:8918a71cdbe9 | 265 | //ifPhysAddress object? |
Sergunb | 0:8918a71cdbe9 | 266 | else if(!strcmp(object->name, "ifPhysAddress")) |
Sergunb | 0:8918a71cdbe9 | 267 | { |
Sergunb | 0:8918a71cdbe9 | 268 | //Make sure the buffer is large enough to hold the entire object |
Sergunb | 0:8918a71cdbe9 | 269 | if(*valueLen >= entry->ifPhysAddressLen) |
Sergunb | 0:8918a71cdbe9 | 270 | { |
Sergunb | 0:8918a71cdbe9 | 271 | //Copy object value |
Sergunb | 0:8918a71cdbe9 | 272 | memcpy(value->octetString, entry->ifPhysAddress, entry->ifPhysAddressLen); |
Sergunb | 0:8918a71cdbe9 | 273 | //Return object length |
Sergunb | 0:8918a71cdbe9 | 274 | *valueLen = entry->ifPhysAddressLen; |
Sergunb | 0:8918a71cdbe9 | 275 | } |
Sergunb | 0:8918a71cdbe9 | 276 | else |
Sergunb | 0:8918a71cdbe9 | 277 | { |
Sergunb | 0:8918a71cdbe9 | 278 | //Report an error |
Sergunb | 0:8918a71cdbe9 | 279 | error = ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 280 | } |
Sergunb | 0:8918a71cdbe9 | 281 | } |
Sergunb | 0:8918a71cdbe9 | 282 | //ifAdminStatus object? |
Sergunb | 0:8918a71cdbe9 | 283 | else if(!strcmp(object->name, "ifAdminStatus")) |
Sergunb | 0:8918a71cdbe9 | 284 | { |
Sergunb | 0:8918a71cdbe9 | 285 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 286 | value->integer = entry->ifAdminStatus; |
Sergunb | 0:8918a71cdbe9 | 287 | } |
Sergunb | 0:8918a71cdbe9 | 288 | //ifOperStatus object? |
Sergunb | 0:8918a71cdbe9 | 289 | else if(!strcmp(object->name, "ifOperStatus")) |
Sergunb | 0:8918a71cdbe9 | 290 | { |
Sergunb | 0:8918a71cdbe9 | 291 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 292 | value->integer = entry->ifOperStatus; |
Sergunb | 0:8918a71cdbe9 | 293 | } |
Sergunb | 0:8918a71cdbe9 | 294 | //ifLastChange object? |
Sergunb | 0:8918a71cdbe9 | 295 | else if(!strcmp(object->name, "ifLastChange")) |
Sergunb | 0:8918a71cdbe9 | 296 | { |
Sergunb | 0:8918a71cdbe9 | 297 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 298 | value->timeTicks = entry->ifLastChange; |
Sergunb | 0:8918a71cdbe9 | 299 | } |
Sergunb | 0:8918a71cdbe9 | 300 | //ifInOctets object? |
Sergunb | 0:8918a71cdbe9 | 301 | else if(!strcmp(object->name, "ifInOctets")) |
Sergunb | 0:8918a71cdbe9 | 302 | { |
Sergunb | 0:8918a71cdbe9 | 303 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 304 | value->counter32 = entry->ifInOctets; |
Sergunb | 0:8918a71cdbe9 | 305 | } |
Sergunb | 0:8918a71cdbe9 | 306 | //ifInUcastPkts object? |
Sergunb | 0:8918a71cdbe9 | 307 | else if(!strcmp(object->name, "ifInUcastPkts")) |
Sergunb | 0:8918a71cdbe9 | 308 | { |
Sergunb | 0:8918a71cdbe9 | 309 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 310 | value->counter32 = entry->ifInUcastPkts; |
Sergunb | 0:8918a71cdbe9 | 311 | } |
Sergunb | 0:8918a71cdbe9 | 312 | //ifInNUcastPkts object? |
Sergunb | 0:8918a71cdbe9 | 313 | else if(!strcmp(object->name, "ifInNUcastPkts")) |
Sergunb | 0:8918a71cdbe9 | 314 | { |
Sergunb | 0:8918a71cdbe9 | 315 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 316 | value->counter32 = entry->ifInNUcastPkts; |
Sergunb | 0:8918a71cdbe9 | 317 | } |
Sergunb | 0:8918a71cdbe9 | 318 | //ifInDiscards object? |
Sergunb | 0:8918a71cdbe9 | 319 | else if(!strcmp(object->name, "ifInDiscards")) |
Sergunb | 0:8918a71cdbe9 | 320 | { |
Sergunb | 0:8918a71cdbe9 | 321 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 322 | value->counter32 = entry->ifInDiscards; |
Sergunb | 0:8918a71cdbe9 | 323 | } |
Sergunb | 0:8918a71cdbe9 | 324 | //ifInErrors object? |
Sergunb | 0:8918a71cdbe9 | 325 | else if(!strcmp(object->name, "ifInErrors")) |
Sergunb | 0:8918a71cdbe9 | 326 | { |
Sergunb | 0:8918a71cdbe9 | 327 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 328 | value->counter32 = entry->ifInErrors; |
Sergunb | 0:8918a71cdbe9 | 329 | } |
Sergunb | 0:8918a71cdbe9 | 330 | //ifInUnknownProtos object? |
Sergunb | 0:8918a71cdbe9 | 331 | else if(!strcmp(object->name, "ifInUnknownProtos")) |
Sergunb | 0:8918a71cdbe9 | 332 | { |
Sergunb | 0:8918a71cdbe9 | 333 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 334 | value->counter32 = entry->ifInUnknownProtos; |
Sergunb | 0:8918a71cdbe9 | 335 | } |
Sergunb | 0:8918a71cdbe9 | 336 | //ifOutOctets object? |
Sergunb | 0:8918a71cdbe9 | 337 | else if(!strcmp(object->name, "ifOutOctets")) |
Sergunb | 0:8918a71cdbe9 | 338 | { |
Sergunb | 0:8918a71cdbe9 | 339 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 340 | value->counter32 = entry->ifOutOctets; |
Sergunb | 0:8918a71cdbe9 | 341 | } |
Sergunb | 0:8918a71cdbe9 | 342 | //ifOutUcastPkts object? |
Sergunb | 0:8918a71cdbe9 | 343 | else if(!strcmp(object->name, "ifOutUcastPkts")) |
Sergunb | 0:8918a71cdbe9 | 344 | { |
Sergunb | 0:8918a71cdbe9 | 345 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 346 | value->counter32 = entry->ifOutUcastPkts; |
Sergunb | 0:8918a71cdbe9 | 347 | } |
Sergunb | 0:8918a71cdbe9 | 348 | //ifOutNUcastPkts object? |
Sergunb | 0:8918a71cdbe9 | 349 | else if(!strcmp(object->name, "ifOutNUcastPkts")) |
Sergunb | 0:8918a71cdbe9 | 350 | { |
Sergunb | 0:8918a71cdbe9 | 351 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 352 | value->counter32 = entry->ifOutNUcastPkts; |
Sergunb | 0:8918a71cdbe9 | 353 | } |
Sergunb | 0:8918a71cdbe9 | 354 | //ifOutDiscards object? |
Sergunb | 0:8918a71cdbe9 | 355 | else if(!strcmp(object->name, "ifOutDiscards")) |
Sergunb | 0:8918a71cdbe9 | 356 | { |
Sergunb | 0:8918a71cdbe9 | 357 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 358 | value->counter32 = entry->ifOutDiscards; |
Sergunb | 0:8918a71cdbe9 | 359 | } |
Sergunb | 0:8918a71cdbe9 | 360 | //ifOutErrors object? |
Sergunb | 0:8918a71cdbe9 | 361 | else if(!strcmp(object->name, "ifOutErrors")) |
Sergunb | 0:8918a71cdbe9 | 362 | { |
Sergunb | 0:8918a71cdbe9 | 363 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 364 | value->counter32 = entry->ifOutErrors; |
Sergunb | 0:8918a71cdbe9 | 365 | } |
Sergunb | 0:8918a71cdbe9 | 366 | //ifOutQLen object? |
Sergunb | 0:8918a71cdbe9 | 367 | else if(!strcmp(object->name, "ifOutQLen")) |
Sergunb | 0:8918a71cdbe9 | 368 | { |
Sergunb | 0:8918a71cdbe9 | 369 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 370 | value->gauge32 = entry->ifOutQLen; |
Sergunb | 0:8918a71cdbe9 | 371 | } |
Sergunb | 0:8918a71cdbe9 | 372 | //ifSpecific object? |
Sergunb | 0:8918a71cdbe9 | 373 | else if(!strcmp(object->name, "ifSpecific")) |
Sergunb | 0:8918a71cdbe9 | 374 | { |
Sergunb | 0:8918a71cdbe9 | 375 | //Make sure the buffer is large enough to hold the entire object |
Sergunb | 0:8918a71cdbe9 | 376 | if(*valueLen >= entry->ifSpecificLen) |
Sergunb | 0:8918a71cdbe9 | 377 | { |
Sergunb | 0:8918a71cdbe9 | 378 | //Copy object value |
Sergunb | 0:8918a71cdbe9 | 379 | memcpy(value->oid, entry->ifSpecific, entry->ifSpecificLen); |
Sergunb | 0:8918a71cdbe9 | 380 | //Return object length |
Sergunb | 0:8918a71cdbe9 | 381 | *valueLen = entry->ifSpecificLen; |
Sergunb | 0:8918a71cdbe9 | 382 | } |
Sergunb | 0:8918a71cdbe9 | 383 | else |
Sergunb | 0:8918a71cdbe9 | 384 | { |
Sergunb | 0:8918a71cdbe9 | 385 | //Report an error |
Sergunb | 0:8918a71cdbe9 | 386 | error = ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 387 | } |
Sergunb | 0:8918a71cdbe9 | 388 | } |
Sergunb | 0:8918a71cdbe9 | 389 | //Unknown object? |
Sergunb | 0:8918a71cdbe9 | 390 | else |
Sergunb | 0:8918a71cdbe9 | 391 | { |
Sergunb | 0:8918a71cdbe9 | 392 | //The specified object does not exist |
Sergunb | 0:8918a71cdbe9 | 393 | error = ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 394 | } |
Sergunb | 0:8918a71cdbe9 | 395 | |
Sergunb | 0:8918a71cdbe9 | 396 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 397 | return error; |
Sergunb | 0:8918a71cdbe9 | 398 | } |
Sergunb | 0:8918a71cdbe9 | 399 | |
Sergunb | 0:8918a71cdbe9 | 400 | |
Sergunb | 0:8918a71cdbe9 | 401 | /** |
Sergunb | 0:8918a71cdbe9 | 402 | * @brief Get next ifEntry object |
Sergunb | 0:8918a71cdbe9 | 403 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 404 | * @param[in] oid Object identifier |
Sergunb | 0:8918a71cdbe9 | 405 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 406 | * @param[out] nextOid OID of the next object in the MIB |
Sergunb | 0:8918a71cdbe9 | 407 | * @param[out] nextOidLen Length of the next object identifier, in bytes |
Sergunb | 0:8918a71cdbe9 | 408 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 409 | **/ |
Sergunb | 0:8918a71cdbe9 | 410 | |
Sergunb | 0:8918a71cdbe9 | 411 | error_t mib2GetNextIfEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 412 | size_t oidLen, uint8_t *nextOid, size_t *nextOidLen) |
Sergunb | 0:8918a71cdbe9 | 413 | { |
Sergunb | 0:8918a71cdbe9 | 414 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 415 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 416 | uint_t index; |
Sergunb | 0:8918a71cdbe9 | 417 | |
Sergunb | 0:8918a71cdbe9 | 418 | //Make sure the buffer is large enough to hold the OID prefix |
Sergunb | 0:8918a71cdbe9 | 419 | if(*nextOidLen < object->oidLen) |
Sergunb | 0:8918a71cdbe9 | 420 | return ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 421 | |
Sergunb | 0:8918a71cdbe9 | 422 | //Copy OID prefix |
Sergunb | 0:8918a71cdbe9 | 423 | memcpy(nextOid, object->oid, object->oidLen); |
Sergunb | 0:8918a71cdbe9 | 424 | |
Sergunb | 0:8918a71cdbe9 | 425 | //Loop through network interfaces |
Sergunb | 0:8918a71cdbe9 | 426 | for(index = 1; index <= NET_INTERFACE_COUNT; index++) |
Sergunb | 0:8918a71cdbe9 | 427 | { |
Sergunb | 0:8918a71cdbe9 | 428 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 429 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 430 | |
Sergunb | 0:8918a71cdbe9 | 431 | //The ifIndex is used as instance identifier |
Sergunb | 0:8918a71cdbe9 | 432 | error = mibEncodeIndex(nextOid, *nextOidLen, &n, index); |
Sergunb | 0:8918a71cdbe9 | 433 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 434 | if(error) |
Sergunb | 0:8918a71cdbe9 | 435 | return error; |
Sergunb | 0:8918a71cdbe9 | 436 | |
Sergunb | 0:8918a71cdbe9 | 437 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 438 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 439 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 440 | { |
Sergunb | 0:8918a71cdbe9 | 441 | //Save the length of the resulting object identifier |
Sergunb | 0:8918a71cdbe9 | 442 | *nextOidLen = n; |
Sergunb | 0:8918a71cdbe9 | 443 | //Next object found |
Sergunb | 0:8918a71cdbe9 | 444 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 445 | } |
Sergunb | 0:8918a71cdbe9 | 446 | } |
Sergunb | 0:8918a71cdbe9 | 447 | |
Sergunb | 0:8918a71cdbe9 | 448 | //The specified OID does not lexicographically precede the name |
Sergunb | 0:8918a71cdbe9 | 449 | //of some object |
Sergunb | 0:8918a71cdbe9 | 450 | return ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 451 | } |
Sergunb | 0:8918a71cdbe9 | 452 | |
Sergunb | 0:8918a71cdbe9 | 453 | |
Sergunb | 0:8918a71cdbe9 | 454 | #if (IPV4_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 455 | |
Sergunb | 0:8918a71cdbe9 | 456 | /** |
Sergunb | 0:8918a71cdbe9 | 457 | * @brief Get ipAddrEntry object value |
Sergunb | 0:8918a71cdbe9 | 458 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 459 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 460 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 461 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 462 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 463 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 464 | **/ |
Sergunb | 0:8918a71cdbe9 | 465 | |
Sergunb | 0:8918a71cdbe9 | 466 | error_t mib2GetIpAddrEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 467 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 468 | { |
Sergunb | 0:8918a71cdbe9 | 469 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 470 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 471 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 472 | Ipv4Addr ipAddr; |
Sergunb | 0:8918a71cdbe9 | 473 | NetInterface *interface; |
Sergunb | 0:8918a71cdbe9 | 474 | |
Sergunb | 0:8918a71cdbe9 | 475 | //Point to the instance identifier |
Sergunb | 0:8918a71cdbe9 | 476 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 477 | |
Sergunb | 0:8918a71cdbe9 | 478 | //The ipAdEntAddr is used as instance identifier |
Sergunb | 0:8918a71cdbe9 | 479 | error = mibDecodeIpv4Addr(oid, oidLen, &n, &ipAddr); |
Sergunb | 0:8918a71cdbe9 | 480 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 481 | if(error) |
Sergunb | 0:8918a71cdbe9 | 482 | return error; |
Sergunb | 0:8918a71cdbe9 | 483 | |
Sergunb | 0:8918a71cdbe9 | 484 | //Sanity check |
Sergunb | 0:8918a71cdbe9 | 485 | if(n != oidLen) |
Sergunb | 0:8918a71cdbe9 | 486 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 487 | |
Sergunb | 0:8918a71cdbe9 | 488 | //Loop through network interfaces |
Sergunb | 0:8918a71cdbe9 | 489 | for(i = 0; i < NET_INTERFACE_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 490 | { |
Sergunb | 0:8918a71cdbe9 | 491 | //Point to the current interface |
Sergunb | 0:8918a71cdbe9 | 492 | interface = &netInterface[i]; |
Sergunb | 0:8918a71cdbe9 | 493 | |
Sergunb | 0:8918a71cdbe9 | 494 | //Check address state |
Sergunb | 0:8918a71cdbe9 | 495 | if(interface->ipv4Context.addrState == IPV4_ADDR_STATE_VALID) |
Sergunb | 0:8918a71cdbe9 | 496 | { |
Sergunb | 0:8918a71cdbe9 | 497 | //Compare the current address against the IP address used as |
Sergunb | 0:8918a71cdbe9 | 498 | //instance identifier |
Sergunb | 0:8918a71cdbe9 | 499 | if(interface->ipv4Context.addr == ipAddr) |
Sergunb | 0:8918a71cdbe9 | 500 | break; |
Sergunb | 0:8918a71cdbe9 | 501 | } |
Sergunb | 0:8918a71cdbe9 | 502 | } |
Sergunb | 0:8918a71cdbe9 | 503 | |
Sergunb | 0:8918a71cdbe9 | 504 | //IP address not assigned to any interface? |
Sergunb | 0:8918a71cdbe9 | 505 | if(i >= NET_INTERFACE_COUNT) |
Sergunb | 0:8918a71cdbe9 | 506 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 507 | |
Sergunb | 0:8918a71cdbe9 | 508 | //ipAdEntAddr object? |
Sergunb | 0:8918a71cdbe9 | 509 | if(!strcmp(object->name, "ipAdEntAddr")) |
Sergunb | 0:8918a71cdbe9 | 510 | { |
Sergunb | 0:8918a71cdbe9 | 511 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 512 | ipv4CopyAddr(value->ipAddr, &interface->ipv4Context.addr); |
Sergunb | 0:8918a71cdbe9 | 513 | } |
Sergunb | 0:8918a71cdbe9 | 514 | //ipAdEntIfIndex object? |
Sergunb | 0:8918a71cdbe9 | 515 | else if(!strcmp(object->name, "ipAdEntIfIndex")) |
Sergunb | 0:8918a71cdbe9 | 516 | { |
Sergunb | 0:8918a71cdbe9 | 517 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 518 | value->integer = interface->id + 1; |
Sergunb | 0:8918a71cdbe9 | 519 | } |
Sergunb | 0:8918a71cdbe9 | 520 | //ipAdEntNetMask object? |
Sergunb | 0:8918a71cdbe9 | 521 | else if(!strcmp(object->name, "ipAdEntNetMask")) |
Sergunb | 0:8918a71cdbe9 | 522 | { |
Sergunb | 0:8918a71cdbe9 | 523 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 524 | ipv4CopyAddr(value->ipAddr, &interface->ipv4Context.subnetMask); |
Sergunb | 0:8918a71cdbe9 | 525 | } |
Sergunb | 0:8918a71cdbe9 | 526 | //ipAdEntBcastAddr object? |
Sergunb | 0:8918a71cdbe9 | 527 | else if(!strcmp(object->name, "ipAdEntBcastAddr")) |
Sergunb | 0:8918a71cdbe9 | 528 | { |
Sergunb | 0:8918a71cdbe9 | 529 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 530 | value->integer = 1; |
Sergunb | 0:8918a71cdbe9 | 531 | } |
Sergunb | 0:8918a71cdbe9 | 532 | //ipAdEntReasmMaxSize object? |
Sergunb | 0:8918a71cdbe9 | 533 | else if(!strcmp(object->name, "ipAdEntReasmMaxSize")) |
Sergunb | 0:8918a71cdbe9 | 534 | { |
Sergunb | 0:8918a71cdbe9 | 535 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 536 | value->integer = IPV4_MAX_FRAG_DATAGRAM_SIZE; |
Sergunb | 0:8918a71cdbe9 | 537 | } |
Sergunb | 0:8918a71cdbe9 | 538 | //Unknown object? |
Sergunb | 0:8918a71cdbe9 | 539 | else |
Sergunb | 0:8918a71cdbe9 | 540 | { |
Sergunb | 0:8918a71cdbe9 | 541 | //The specified object does not exist |
Sergunb | 0:8918a71cdbe9 | 542 | error = ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 543 | } |
Sergunb | 0:8918a71cdbe9 | 544 | |
Sergunb | 0:8918a71cdbe9 | 545 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 546 | return error; |
Sergunb | 0:8918a71cdbe9 | 547 | } |
Sergunb | 0:8918a71cdbe9 | 548 | |
Sergunb | 0:8918a71cdbe9 | 549 | |
Sergunb | 0:8918a71cdbe9 | 550 | /** |
Sergunb | 0:8918a71cdbe9 | 551 | * @brief Get next ipAddrEntry object |
Sergunb | 0:8918a71cdbe9 | 552 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 553 | * @param[in] oid Object identifier |
Sergunb | 0:8918a71cdbe9 | 554 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 555 | * @param[out] nextOid OID of the next object in the MIB |
Sergunb | 0:8918a71cdbe9 | 556 | * @param[out] nextOidLen Length of the next object identifier, in bytes |
Sergunb | 0:8918a71cdbe9 | 557 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 558 | **/ |
Sergunb | 0:8918a71cdbe9 | 559 | |
Sergunb | 0:8918a71cdbe9 | 560 | error_t mib2GetNextIpAddrEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 561 | size_t oidLen, uint8_t *nextOid, size_t *nextOidLen) |
Sergunb | 0:8918a71cdbe9 | 562 | { |
Sergunb | 0:8918a71cdbe9 | 563 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 564 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 565 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 566 | Ipv4Addr ipAddr; |
Sergunb | 0:8918a71cdbe9 | 567 | NetInterface *interface; |
Sergunb | 0:8918a71cdbe9 | 568 | |
Sergunb | 0:8918a71cdbe9 | 569 | //Initialize IP address |
Sergunb | 0:8918a71cdbe9 | 570 | ipAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 571 | |
Sergunb | 0:8918a71cdbe9 | 572 | //Make sure the buffer is large enough to hold the OID prefix |
Sergunb | 0:8918a71cdbe9 | 573 | if(*nextOidLen < object->oidLen) |
Sergunb | 0:8918a71cdbe9 | 574 | return ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 575 | |
Sergunb | 0:8918a71cdbe9 | 576 | //Copy OID prefix |
Sergunb | 0:8918a71cdbe9 | 577 | memcpy(nextOid, object->oid, object->oidLen); |
Sergunb | 0:8918a71cdbe9 | 578 | |
Sergunb | 0:8918a71cdbe9 | 579 | //Loop through network interfaces |
Sergunb | 0:8918a71cdbe9 | 580 | for(i = 0; i < NET_INTERFACE_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 581 | { |
Sergunb | 0:8918a71cdbe9 | 582 | //Point to the current interface |
Sergunb | 0:8918a71cdbe9 | 583 | interface = &netInterface[i]; |
Sergunb | 0:8918a71cdbe9 | 584 | |
Sergunb | 0:8918a71cdbe9 | 585 | //Check address state |
Sergunb | 0:8918a71cdbe9 | 586 | if(interface->ipv4Context.addrState == IPV4_ADDR_STATE_VALID) |
Sergunb | 0:8918a71cdbe9 | 587 | { |
Sergunb | 0:8918a71cdbe9 | 588 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 589 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 590 | |
Sergunb | 0:8918a71cdbe9 | 591 | //The ipAdEntAddr is used as instance identifier |
Sergunb | 0:8918a71cdbe9 | 592 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, interface->ipv4Context.addr); |
Sergunb | 0:8918a71cdbe9 | 593 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 594 | if(error) |
Sergunb | 0:8918a71cdbe9 | 595 | return error; |
Sergunb | 0:8918a71cdbe9 | 596 | |
Sergunb | 0:8918a71cdbe9 | 597 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 598 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 599 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 600 | { |
Sergunb | 0:8918a71cdbe9 | 601 | //Save the closest object identifier that follows the specified |
Sergunb | 0:8918a71cdbe9 | 602 | //OID in lexicographic order |
Sergunb | 0:8918a71cdbe9 | 603 | if(ipAddr == IPV4_UNSPECIFIED_ADDR) |
Sergunb | 0:8918a71cdbe9 | 604 | { |
Sergunb | 0:8918a71cdbe9 | 605 | ipAddr = interface->ipv4Context.addr; |
Sergunb | 0:8918a71cdbe9 | 606 | } |
Sergunb | 0:8918a71cdbe9 | 607 | else if(ntohl(interface->ipv4Context.addr) < ntohl(ipAddr)) |
Sergunb | 0:8918a71cdbe9 | 608 | { |
Sergunb | 0:8918a71cdbe9 | 609 | ipAddr = interface->ipv4Context.addr; |
Sergunb | 0:8918a71cdbe9 | 610 | } |
Sergunb | 0:8918a71cdbe9 | 611 | } |
Sergunb | 0:8918a71cdbe9 | 612 | } |
Sergunb | 0:8918a71cdbe9 | 613 | } |
Sergunb | 0:8918a71cdbe9 | 614 | |
Sergunb | 0:8918a71cdbe9 | 615 | //The specified OID does not lexicographically precede the name |
Sergunb | 0:8918a71cdbe9 | 616 | //of some object? |
Sergunb | 0:8918a71cdbe9 | 617 | if(ipAddr == IPV4_UNSPECIFIED_ADDR) |
Sergunb | 0:8918a71cdbe9 | 618 | return ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 619 | |
Sergunb | 0:8918a71cdbe9 | 620 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 621 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 622 | |
Sergunb | 0:8918a71cdbe9 | 623 | //The ipAdEntAddr is used as instance identifier |
Sergunb | 0:8918a71cdbe9 | 624 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, interface->ipv4Context.addr); |
Sergunb | 0:8918a71cdbe9 | 625 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 626 | if(error) |
Sergunb | 0:8918a71cdbe9 | 627 | return error; |
Sergunb | 0:8918a71cdbe9 | 628 | |
Sergunb | 0:8918a71cdbe9 | 629 | //Save the length of the resulting object identifier |
Sergunb | 0:8918a71cdbe9 | 630 | *nextOidLen = n; |
Sergunb | 0:8918a71cdbe9 | 631 | //Next object found |
Sergunb | 0:8918a71cdbe9 | 632 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 633 | } |
Sergunb | 0:8918a71cdbe9 | 634 | |
Sergunb | 0:8918a71cdbe9 | 635 | |
Sergunb | 0:8918a71cdbe9 | 636 | /** |
Sergunb | 0:8918a71cdbe9 | 637 | * @brief Set ipNetToMediaEntry object value |
Sergunb | 0:8918a71cdbe9 | 638 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 639 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 640 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 641 | * @param[in] value Object value |
Sergunb | 0:8918a71cdbe9 | 642 | * @param[in] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 643 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 644 | **/ |
Sergunb | 0:8918a71cdbe9 | 645 | |
Sergunb | 0:8918a71cdbe9 | 646 | error_t mib2SetIpNetToMediaEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 647 | size_t oidLen, const MibVariant *value, size_t valueLen) |
Sergunb | 0:8918a71cdbe9 | 648 | { |
Sergunb | 0:8918a71cdbe9 | 649 | //Not implemented |
Sergunb | 0:8918a71cdbe9 | 650 | return ERROR_WRITE_FAILED; |
Sergunb | 0:8918a71cdbe9 | 651 | } |
Sergunb | 0:8918a71cdbe9 | 652 | |
Sergunb | 0:8918a71cdbe9 | 653 | |
Sergunb | 0:8918a71cdbe9 | 654 | /** |
Sergunb | 0:8918a71cdbe9 | 655 | * @brief Get ipNetToMediaEntry object value |
Sergunb | 0:8918a71cdbe9 | 656 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 657 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 658 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 659 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 660 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 661 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 662 | **/ |
Sergunb | 0:8918a71cdbe9 | 663 | |
Sergunb | 0:8918a71cdbe9 | 664 | error_t mib2GetIpNetToMediaEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 665 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 666 | { |
Sergunb | 0:8918a71cdbe9 | 667 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 668 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 669 | uint_t index; |
Sergunb | 0:8918a71cdbe9 | 670 | Ipv4Addr ipAddr; |
Sergunb | 0:8918a71cdbe9 | 671 | NetInterface *interface; |
Sergunb | 0:8918a71cdbe9 | 672 | ArpCacheEntry *entry; |
Sergunb | 0:8918a71cdbe9 | 673 | |
Sergunb | 0:8918a71cdbe9 | 674 | //Point to the instance identifier |
Sergunb | 0:8918a71cdbe9 | 675 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 676 | |
Sergunb | 0:8918a71cdbe9 | 677 | //The ipNetToMediaIfIndex is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 678 | error = mibDecodeIndex(oid, oidLen, &n, &index); |
Sergunb | 0:8918a71cdbe9 | 679 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 680 | if(error) |
Sergunb | 0:8918a71cdbe9 | 681 | return error; |
Sergunb | 0:8918a71cdbe9 | 682 | |
Sergunb | 0:8918a71cdbe9 | 683 | //The ipNetToMediaNetAddress is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 684 | error = mibDecodeIpv4Addr(oid, oidLen, &n, &ipAddr); |
Sergunb | 0:8918a71cdbe9 | 685 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 686 | if(error) |
Sergunb | 0:8918a71cdbe9 | 687 | return error; |
Sergunb | 0:8918a71cdbe9 | 688 | |
Sergunb | 0:8918a71cdbe9 | 689 | //Sanity check |
Sergunb | 0:8918a71cdbe9 | 690 | if(n != oidLen) |
Sergunb | 0:8918a71cdbe9 | 691 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 692 | |
Sergunb | 0:8918a71cdbe9 | 693 | //Check index range |
Sergunb | 0:8918a71cdbe9 | 694 | if(index < 1 || index > NET_INTERFACE_COUNT) |
Sergunb | 0:8918a71cdbe9 | 695 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 696 | |
Sergunb | 0:8918a71cdbe9 | 697 | //Point to the network interface |
Sergunb | 0:8918a71cdbe9 | 698 | interface = &netInterface[index - 1]; |
Sergunb | 0:8918a71cdbe9 | 699 | |
Sergunb | 0:8918a71cdbe9 | 700 | //Search the ARP cache for the specified IP address |
Sergunb | 0:8918a71cdbe9 | 701 | entry = arpFindEntry(interface, ipAddr); |
Sergunb | 0:8918a71cdbe9 | 702 | |
Sergunb | 0:8918a71cdbe9 | 703 | //No matching entry found? |
Sergunb | 0:8918a71cdbe9 | 704 | if(entry == NULL) |
Sergunb | 0:8918a71cdbe9 | 705 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 706 | |
Sergunb | 0:8918a71cdbe9 | 707 | //ipNetToMediaIfIndex object? |
Sergunb | 0:8918a71cdbe9 | 708 | if(!strcmp(object->name, "ipNetToMediaIfIndex")) |
Sergunb | 0:8918a71cdbe9 | 709 | { |
Sergunb | 0:8918a71cdbe9 | 710 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 711 | value->integer = index; |
Sergunb | 0:8918a71cdbe9 | 712 | } |
Sergunb | 0:8918a71cdbe9 | 713 | //ipNetToMediaPhysAddress object? |
Sergunb | 0:8918a71cdbe9 | 714 | else if(!strcmp(object->name, "ipNetToMediaPhysAddress")) |
Sergunb | 0:8918a71cdbe9 | 715 | { |
Sergunb | 0:8918a71cdbe9 | 716 | //Make sure the buffer is large enough to hold the entire object |
Sergunb | 0:8918a71cdbe9 | 717 | if(*valueLen >= MIB2_PHYS_ADDRESS_SIZE) |
Sergunb | 0:8918a71cdbe9 | 718 | { |
Sergunb | 0:8918a71cdbe9 | 719 | //Copy object value |
Sergunb | 0:8918a71cdbe9 | 720 | macCopyAddr(value->octetString, &entry->macAddr); |
Sergunb | 0:8918a71cdbe9 | 721 | //Return object length |
Sergunb | 0:8918a71cdbe9 | 722 | *valueLen = MIB2_PHYS_ADDRESS_SIZE; |
Sergunb | 0:8918a71cdbe9 | 723 | } |
Sergunb | 0:8918a71cdbe9 | 724 | else |
Sergunb | 0:8918a71cdbe9 | 725 | { |
Sergunb | 0:8918a71cdbe9 | 726 | //Report an error |
Sergunb | 0:8918a71cdbe9 | 727 | error = ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 728 | } |
Sergunb | 0:8918a71cdbe9 | 729 | } |
Sergunb | 0:8918a71cdbe9 | 730 | //ipNetToMediaNetAddress object? |
Sergunb | 0:8918a71cdbe9 | 731 | else if(!strcmp(object->name, "ipNetToMediaNetAddress")) |
Sergunb | 0:8918a71cdbe9 | 732 | { |
Sergunb | 0:8918a71cdbe9 | 733 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 734 | ipv4CopyAddr(value->ipAddr, &entry->ipAddr); |
Sergunb | 0:8918a71cdbe9 | 735 | } |
Sergunb | 0:8918a71cdbe9 | 736 | //ipNetToMediaType object? |
Sergunb | 0:8918a71cdbe9 | 737 | else if(!strcmp(object->name, "ipNetToMediaType")) |
Sergunb | 0:8918a71cdbe9 | 738 | { |
Sergunb | 0:8918a71cdbe9 | 739 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 740 | value->integer = MIB2_IP_NET_TO_MEDIA_TYPE_DYNAMIC; |
Sergunb | 0:8918a71cdbe9 | 741 | } |
Sergunb | 0:8918a71cdbe9 | 742 | //Unknown object? |
Sergunb | 0:8918a71cdbe9 | 743 | else |
Sergunb | 0:8918a71cdbe9 | 744 | { |
Sergunb | 0:8918a71cdbe9 | 745 | //The specified object does not exist |
Sergunb | 0:8918a71cdbe9 | 746 | error = ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 747 | } |
Sergunb | 0:8918a71cdbe9 | 748 | |
Sergunb | 0:8918a71cdbe9 | 749 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 750 | return error; |
Sergunb | 0:8918a71cdbe9 | 751 | } |
Sergunb | 0:8918a71cdbe9 | 752 | |
Sergunb | 0:8918a71cdbe9 | 753 | |
Sergunb | 0:8918a71cdbe9 | 754 | /** |
Sergunb | 0:8918a71cdbe9 | 755 | * @brief Get next ipNetToMediaEntry object |
Sergunb | 0:8918a71cdbe9 | 756 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 757 | * @param[in] oid Object identifier |
Sergunb | 0:8918a71cdbe9 | 758 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 759 | * @param[out] nextOid OID of the next object in the MIB |
Sergunb | 0:8918a71cdbe9 | 760 | * @param[out] nextOidLen Length of the next object identifier, in bytes |
Sergunb | 0:8918a71cdbe9 | 761 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 762 | **/ |
Sergunb | 0:8918a71cdbe9 | 763 | |
Sergunb | 0:8918a71cdbe9 | 764 | error_t mib2GetNextIpNetToMediaEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 765 | size_t oidLen, uint8_t *nextOid, size_t *nextOidLen) |
Sergunb | 0:8918a71cdbe9 | 766 | { |
Sergunb | 0:8918a71cdbe9 | 767 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 768 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 769 | uint_t j; |
Sergunb | 0:8918a71cdbe9 | 770 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 771 | uint32_t index; |
Sergunb | 0:8918a71cdbe9 | 772 | bool_t acceptable; |
Sergunb | 0:8918a71cdbe9 | 773 | Ipv4Addr ipAddr; |
Sergunb | 0:8918a71cdbe9 | 774 | NetInterface *interface; |
Sergunb | 0:8918a71cdbe9 | 775 | ArpCacheEntry *entry; |
Sergunb | 0:8918a71cdbe9 | 776 | |
Sergunb | 0:8918a71cdbe9 | 777 | //Initialize variables |
Sergunb | 0:8918a71cdbe9 | 778 | index = 0; |
Sergunb | 0:8918a71cdbe9 | 779 | ipAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 780 | |
Sergunb | 0:8918a71cdbe9 | 781 | //Make sure the buffer is large enough to hold the OID prefix |
Sergunb | 0:8918a71cdbe9 | 782 | if(*nextOidLen < object->oidLen) |
Sergunb | 0:8918a71cdbe9 | 783 | return ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 784 | |
Sergunb | 0:8918a71cdbe9 | 785 | //Copy OID prefix |
Sergunb | 0:8918a71cdbe9 | 786 | memcpy(nextOid, object->oid, object->oidLen); |
Sergunb | 0:8918a71cdbe9 | 787 | |
Sergunb | 0:8918a71cdbe9 | 788 | //Loop through network interfaces |
Sergunb | 0:8918a71cdbe9 | 789 | for(i = 1; i <= NET_INTERFACE_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 790 | { |
Sergunb | 0:8918a71cdbe9 | 791 | //Point to the current interface |
Sergunb | 0:8918a71cdbe9 | 792 | interface = &netInterface[i - 1]; |
Sergunb | 0:8918a71cdbe9 | 793 | |
Sergunb | 0:8918a71cdbe9 | 794 | //Loop through ARP cache entries |
Sergunb | 0:8918a71cdbe9 | 795 | for(j = 0; j < ARP_CACHE_SIZE; j++) |
Sergunb | 0:8918a71cdbe9 | 796 | { |
Sergunb | 0:8918a71cdbe9 | 797 | //Point to the current entry |
Sergunb | 0:8918a71cdbe9 | 798 | entry = &interface->arpCache[j]; |
Sergunb | 0:8918a71cdbe9 | 799 | |
Sergunb | 0:8918a71cdbe9 | 800 | //Valid entry? |
Sergunb | 0:8918a71cdbe9 | 801 | if(entry->state != ARP_STATE_NONE) |
Sergunb | 0:8918a71cdbe9 | 802 | { |
Sergunb | 0:8918a71cdbe9 | 803 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 804 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 805 | |
Sergunb | 0:8918a71cdbe9 | 806 | //The ipNetToMediaIfIndex is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 807 | error = mibEncodeIndex(nextOid, *nextOidLen, &n, i); |
Sergunb | 0:8918a71cdbe9 | 808 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 809 | if(error) |
Sergunb | 0:8918a71cdbe9 | 810 | return error; |
Sergunb | 0:8918a71cdbe9 | 811 | |
Sergunb | 0:8918a71cdbe9 | 812 | //The ipNetToMediaNetAddress is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 813 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, entry->ipAddr); |
Sergunb | 0:8918a71cdbe9 | 814 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 815 | if(error) |
Sergunb | 0:8918a71cdbe9 | 816 | return error; |
Sergunb | 0:8918a71cdbe9 | 817 | |
Sergunb | 0:8918a71cdbe9 | 818 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 819 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 820 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 821 | { |
Sergunb | 0:8918a71cdbe9 | 822 | //Perform lexicographic comparison |
Sergunb | 0:8918a71cdbe9 | 823 | if(index == 0) |
Sergunb | 0:8918a71cdbe9 | 824 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 825 | else if(i < index) |
Sergunb | 0:8918a71cdbe9 | 826 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 827 | else if(i > index) |
Sergunb | 0:8918a71cdbe9 | 828 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 829 | else if(ntohl(entry->ipAddr) < ntohl(ipAddr)) |
Sergunb | 0:8918a71cdbe9 | 830 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 831 | else |
Sergunb | 0:8918a71cdbe9 | 832 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 833 | |
Sergunb | 0:8918a71cdbe9 | 834 | //Save the closest object identifier that follows the specified |
Sergunb | 0:8918a71cdbe9 | 835 | //OID in lexicographic order |
Sergunb | 0:8918a71cdbe9 | 836 | if(acceptable) |
Sergunb | 0:8918a71cdbe9 | 837 | { |
Sergunb | 0:8918a71cdbe9 | 838 | index = i; |
Sergunb | 0:8918a71cdbe9 | 839 | ipAddr = entry->ipAddr; |
Sergunb | 0:8918a71cdbe9 | 840 | } |
Sergunb | 0:8918a71cdbe9 | 841 | } |
Sergunb | 0:8918a71cdbe9 | 842 | } |
Sergunb | 0:8918a71cdbe9 | 843 | } |
Sergunb | 0:8918a71cdbe9 | 844 | } |
Sergunb | 0:8918a71cdbe9 | 845 | |
Sergunb | 0:8918a71cdbe9 | 846 | //The specified OID does not lexicographically precede the name |
Sergunb | 0:8918a71cdbe9 | 847 | //of some object? |
Sergunb | 0:8918a71cdbe9 | 848 | if(index == 0) |
Sergunb | 0:8918a71cdbe9 | 849 | return ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 850 | |
Sergunb | 0:8918a71cdbe9 | 851 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 852 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 853 | |
Sergunb | 0:8918a71cdbe9 | 854 | //The ipNetToMediaIfIndex is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 855 | error = mibEncodeIndex(nextOid, *nextOidLen, &n, index); |
Sergunb | 0:8918a71cdbe9 | 856 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 857 | if(error) |
Sergunb | 0:8918a71cdbe9 | 858 | return error; |
Sergunb | 0:8918a71cdbe9 | 859 | |
Sergunb | 0:8918a71cdbe9 | 860 | //The ipNetToMediaNetAddress is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 861 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, ipAddr); |
Sergunb | 0:8918a71cdbe9 | 862 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 863 | if(error) |
Sergunb | 0:8918a71cdbe9 | 864 | return error; |
Sergunb | 0:8918a71cdbe9 | 865 | |
Sergunb | 0:8918a71cdbe9 | 866 | //Save the length of the resulting object identifier |
Sergunb | 0:8918a71cdbe9 | 867 | *nextOidLen = n; |
Sergunb | 0:8918a71cdbe9 | 868 | //Next object found |
Sergunb | 0:8918a71cdbe9 | 869 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 870 | } |
Sergunb | 0:8918a71cdbe9 | 871 | |
Sergunb | 0:8918a71cdbe9 | 872 | |
Sergunb | 0:8918a71cdbe9 | 873 | /** |
Sergunb | 0:8918a71cdbe9 | 874 | * @brief Set tcpConnEntry object value |
Sergunb | 0:8918a71cdbe9 | 875 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 876 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 877 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 878 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 879 | * @param[in] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 880 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 881 | **/ |
Sergunb | 0:8918a71cdbe9 | 882 | |
Sergunb | 0:8918a71cdbe9 | 883 | error_t mib2SetTcpConnEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 884 | size_t oidLen, const MibVariant *value, size_t valueLen) |
Sergunb | 0:8918a71cdbe9 | 885 | { |
Sergunb | 0:8918a71cdbe9 | 886 | //Not implemented |
Sergunb | 0:8918a71cdbe9 | 887 | return ERROR_WRITE_FAILED; |
Sergunb | 0:8918a71cdbe9 | 888 | } |
Sergunb | 0:8918a71cdbe9 | 889 | |
Sergunb | 0:8918a71cdbe9 | 890 | |
Sergunb | 0:8918a71cdbe9 | 891 | /** |
Sergunb | 0:8918a71cdbe9 | 892 | * @brief Get tcpConnEntry object value |
Sergunb | 0:8918a71cdbe9 | 893 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 894 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 895 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 896 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 897 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 898 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 899 | **/ |
Sergunb | 0:8918a71cdbe9 | 900 | |
Sergunb | 0:8918a71cdbe9 | 901 | error_t mib2GetTcpConnEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 902 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 903 | { |
Sergunb | 0:8918a71cdbe9 | 904 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 905 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 906 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 907 | Ipv4Addr localIpAddr; |
Sergunb | 0:8918a71cdbe9 | 908 | uint16_t localPort; |
Sergunb | 0:8918a71cdbe9 | 909 | Ipv4Addr remoteIpAddr; |
Sergunb | 0:8918a71cdbe9 | 910 | uint16_t remotePort; |
Sergunb | 0:8918a71cdbe9 | 911 | Socket *socket; |
Sergunb | 0:8918a71cdbe9 | 912 | |
Sergunb | 0:8918a71cdbe9 | 913 | //Point to the instance identifier |
Sergunb | 0:8918a71cdbe9 | 914 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 915 | |
Sergunb | 0:8918a71cdbe9 | 916 | //The tcpConnLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 917 | error = mibDecodeIpv4Addr(oid, oidLen, &n, &localIpAddr); |
Sergunb | 0:8918a71cdbe9 | 918 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 919 | if(error) |
Sergunb | 0:8918a71cdbe9 | 920 | return error; |
Sergunb | 0:8918a71cdbe9 | 921 | |
Sergunb | 0:8918a71cdbe9 | 922 | //The tcpConnLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 923 | error = mibDecodePort(oid, oidLen, &n, &localPort); |
Sergunb | 0:8918a71cdbe9 | 924 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 925 | if(error) |
Sergunb | 0:8918a71cdbe9 | 926 | return error; |
Sergunb | 0:8918a71cdbe9 | 927 | |
Sergunb | 0:8918a71cdbe9 | 928 | //The tcpConnRemAddress is used as 3rd instance identifier |
Sergunb | 0:8918a71cdbe9 | 929 | error = mibDecodeIpv4Addr(oid, oidLen, &n, &remoteIpAddr); |
Sergunb | 0:8918a71cdbe9 | 930 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 931 | if(error) |
Sergunb | 0:8918a71cdbe9 | 932 | return error; |
Sergunb | 0:8918a71cdbe9 | 933 | |
Sergunb | 0:8918a71cdbe9 | 934 | //The tcpConnRemPort is used as 4th instance identifier |
Sergunb | 0:8918a71cdbe9 | 935 | error = mibDecodePort(oid, oidLen, &n, &remotePort); |
Sergunb | 0:8918a71cdbe9 | 936 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 937 | if(error) |
Sergunb | 0:8918a71cdbe9 | 938 | return error; |
Sergunb | 0:8918a71cdbe9 | 939 | |
Sergunb | 0:8918a71cdbe9 | 940 | //Sanity check |
Sergunb | 0:8918a71cdbe9 | 941 | if(n != oidLen) |
Sergunb | 0:8918a71cdbe9 | 942 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 943 | |
Sergunb | 0:8918a71cdbe9 | 944 | //Loop through socket descriptors |
Sergunb | 0:8918a71cdbe9 | 945 | for(i = 0; i < SOCKET_MAX_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 946 | { |
Sergunb | 0:8918a71cdbe9 | 947 | //Point to current socket |
Sergunb | 0:8918a71cdbe9 | 948 | socket = &socketTable[i]; |
Sergunb | 0:8918a71cdbe9 | 949 | |
Sergunb | 0:8918a71cdbe9 | 950 | //TCP socket? |
Sergunb | 0:8918a71cdbe9 | 951 | if(socketTable[i].type == SOCKET_TYPE_STREAM) |
Sergunb | 0:8918a71cdbe9 | 952 | { |
Sergunb | 0:8918a71cdbe9 | 953 | //Check local IP address |
Sergunb | 0:8918a71cdbe9 | 954 | if(socket->localIpAddr.length == sizeof(Ipv6Addr)) |
Sergunb | 0:8918a71cdbe9 | 955 | continue; |
Sergunb | 0:8918a71cdbe9 | 956 | if(socket->localIpAddr.ipv4Addr != localIpAddr) |
Sergunb | 0:8918a71cdbe9 | 957 | continue; |
Sergunb | 0:8918a71cdbe9 | 958 | //Check local port number |
Sergunb | 0:8918a71cdbe9 | 959 | if(socket->localPort != localPort) |
Sergunb | 0:8918a71cdbe9 | 960 | continue; |
Sergunb | 0:8918a71cdbe9 | 961 | //Check remote IP address |
Sergunb | 0:8918a71cdbe9 | 962 | if(socket->remoteIpAddr.length == sizeof(Ipv6Addr)) |
Sergunb | 0:8918a71cdbe9 | 963 | continue; |
Sergunb | 0:8918a71cdbe9 | 964 | if(socket->remoteIpAddr.ipv4Addr != remoteIpAddr) |
Sergunb | 0:8918a71cdbe9 | 965 | continue; |
Sergunb | 0:8918a71cdbe9 | 966 | //Check remote port number |
Sergunb | 0:8918a71cdbe9 | 967 | if(socket->remotePort != remotePort) |
Sergunb | 0:8918a71cdbe9 | 968 | continue; |
Sergunb | 0:8918a71cdbe9 | 969 | |
Sergunb | 0:8918a71cdbe9 | 970 | //A matching socket has been found |
Sergunb | 0:8918a71cdbe9 | 971 | break; |
Sergunb | 0:8918a71cdbe9 | 972 | } |
Sergunb | 0:8918a71cdbe9 | 973 | } |
Sergunb | 0:8918a71cdbe9 | 974 | |
Sergunb | 0:8918a71cdbe9 | 975 | //No matching connection found in socket table? |
Sergunb | 0:8918a71cdbe9 | 976 | if(i >= SOCKET_MAX_COUNT) |
Sergunb | 0:8918a71cdbe9 | 977 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 978 | |
Sergunb | 0:8918a71cdbe9 | 979 | //tcpConnState object? |
Sergunb | 0:8918a71cdbe9 | 980 | if(!strcmp(object->name, "tcpConnState")) |
Sergunb | 0:8918a71cdbe9 | 981 | { |
Sergunb | 0:8918a71cdbe9 | 982 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 983 | switch(socket->state) |
Sergunb | 0:8918a71cdbe9 | 984 | { |
Sergunb | 0:8918a71cdbe9 | 985 | case TCP_STATE_CLOSED: |
Sergunb | 0:8918a71cdbe9 | 986 | value->integer = MIB2_TCP_CONN_STATE_CLOSED; |
Sergunb | 0:8918a71cdbe9 | 987 | break; |
Sergunb | 0:8918a71cdbe9 | 988 | case TCP_STATE_LISTEN: |
Sergunb | 0:8918a71cdbe9 | 989 | value->integer = MIB2_TCP_CONN_STATE_LISTEN; |
Sergunb | 0:8918a71cdbe9 | 990 | break; |
Sergunb | 0:8918a71cdbe9 | 991 | case TCP_STATE_SYN_SENT: |
Sergunb | 0:8918a71cdbe9 | 992 | value->integer = MIB2_TCP_CONN_STATE_SYN_SENT; |
Sergunb | 0:8918a71cdbe9 | 993 | break; |
Sergunb | 0:8918a71cdbe9 | 994 | case TCP_STATE_SYN_RECEIVED: |
Sergunb | 0:8918a71cdbe9 | 995 | value->integer = MIB2_TCP_CONN_STATE_SYN_RECEIVED; |
Sergunb | 0:8918a71cdbe9 | 996 | break; |
Sergunb | 0:8918a71cdbe9 | 997 | case TCP_STATE_ESTABLISHED: |
Sergunb | 0:8918a71cdbe9 | 998 | value->integer = MIB2_TCP_CONN_STATE_ESTABLISHED; |
Sergunb | 0:8918a71cdbe9 | 999 | break; |
Sergunb | 0:8918a71cdbe9 | 1000 | case TCP_STATE_FIN_WAIT_1: |
Sergunb | 0:8918a71cdbe9 | 1001 | value->integer = MIB2_TCP_CONN_STATE_FIN_WAIT_1; |
Sergunb | 0:8918a71cdbe9 | 1002 | break; |
Sergunb | 0:8918a71cdbe9 | 1003 | case TCP_STATE_FIN_WAIT_2: |
Sergunb | 0:8918a71cdbe9 | 1004 | value->integer = MIB2_TCP_CONN_STATE_FIN_WAIT_2; |
Sergunb | 0:8918a71cdbe9 | 1005 | break; |
Sergunb | 0:8918a71cdbe9 | 1006 | case TCP_STATE_CLOSE_WAIT: |
Sergunb | 0:8918a71cdbe9 | 1007 | value->integer = MIB2_TCP_CONN_STATE_CLOSE_WAIT; |
Sergunb | 0:8918a71cdbe9 | 1008 | break; |
Sergunb | 0:8918a71cdbe9 | 1009 | case TCP_STATE_LAST_ACK: |
Sergunb | 0:8918a71cdbe9 | 1010 | value->integer = MIB2_TCP_CONN_STATE_LAST_ACK; |
Sergunb | 0:8918a71cdbe9 | 1011 | break; |
Sergunb | 0:8918a71cdbe9 | 1012 | case TCP_STATE_CLOSING: |
Sergunb | 0:8918a71cdbe9 | 1013 | value->integer = MIB2_TCP_CONN_STATE_CLOSING; |
Sergunb | 0:8918a71cdbe9 | 1014 | break; |
Sergunb | 0:8918a71cdbe9 | 1015 | case TCP_STATE_TIME_WAIT: |
Sergunb | 0:8918a71cdbe9 | 1016 | value->integer = MIB2_TCP_CONN_STATE_TIME_WAIT; |
Sergunb | 0:8918a71cdbe9 | 1017 | break; |
Sergunb | 0:8918a71cdbe9 | 1018 | default: |
Sergunb | 0:8918a71cdbe9 | 1019 | value->integer = 0; |
Sergunb | 0:8918a71cdbe9 | 1020 | break; |
Sergunb | 0:8918a71cdbe9 | 1021 | } |
Sergunb | 0:8918a71cdbe9 | 1022 | } |
Sergunb | 0:8918a71cdbe9 | 1023 | //tcpConnLocalAddress object? |
Sergunb | 0:8918a71cdbe9 | 1024 | else if(!strcmp(object->name, "tcpConnLocalAddress")) |
Sergunb | 0:8918a71cdbe9 | 1025 | { |
Sergunb | 0:8918a71cdbe9 | 1026 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1027 | ipv4CopyAddr(value->ipAddr, &socket->localIpAddr.ipv4Addr); |
Sergunb | 0:8918a71cdbe9 | 1028 | } |
Sergunb | 0:8918a71cdbe9 | 1029 | //tcpConnLocalPort object? |
Sergunb | 0:8918a71cdbe9 | 1030 | else if(!strcmp(object->name, "tcpConnLocalPort")) |
Sergunb | 0:8918a71cdbe9 | 1031 | { |
Sergunb | 0:8918a71cdbe9 | 1032 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1033 | value->integer = socket->localPort; |
Sergunb | 0:8918a71cdbe9 | 1034 | } |
Sergunb | 0:8918a71cdbe9 | 1035 | //tcpConnRemAddress object? |
Sergunb | 0:8918a71cdbe9 | 1036 | else if(!strcmp(object->name, "tcpConnRemAddress")) |
Sergunb | 0:8918a71cdbe9 | 1037 | { |
Sergunb | 0:8918a71cdbe9 | 1038 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1039 | ipv4CopyAddr(value->ipAddr, &socket->remoteIpAddr.ipv4Addr); |
Sergunb | 0:8918a71cdbe9 | 1040 | } |
Sergunb | 0:8918a71cdbe9 | 1041 | //tcpConnRemPort object? |
Sergunb | 0:8918a71cdbe9 | 1042 | else if(!strcmp(object->name, "tcpConnRemPort")) |
Sergunb | 0:8918a71cdbe9 | 1043 | { |
Sergunb | 0:8918a71cdbe9 | 1044 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1045 | value->integer = socket->remotePort; |
Sergunb | 0:8918a71cdbe9 | 1046 | } |
Sergunb | 0:8918a71cdbe9 | 1047 | //Unknown object? |
Sergunb | 0:8918a71cdbe9 | 1048 | else |
Sergunb | 0:8918a71cdbe9 | 1049 | { |
Sergunb | 0:8918a71cdbe9 | 1050 | //The specified object does not exist |
Sergunb | 0:8918a71cdbe9 | 1051 | error = ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1052 | } |
Sergunb | 0:8918a71cdbe9 | 1053 | |
Sergunb | 0:8918a71cdbe9 | 1054 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 1055 | return error; |
Sergunb | 0:8918a71cdbe9 | 1056 | } |
Sergunb | 0:8918a71cdbe9 | 1057 | |
Sergunb | 0:8918a71cdbe9 | 1058 | |
Sergunb | 0:8918a71cdbe9 | 1059 | /** |
Sergunb | 0:8918a71cdbe9 | 1060 | * @brief Get next tcpConnEntry object |
Sergunb | 0:8918a71cdbe9 | 1061 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 1062 | * @param[in] oid Object identifier |
Sergunb | 0:8918a71cdbe9 | 1063 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 1064 | * @param[out] nextOid OID of the next object in the MIB |
Sergunb | 0:8918a71cdbe9 | 1065 | * @param[out] nextOidLen Length of the next object identifier, in bytes |
Sergunb | 0:8918a71cdbe9 | 1066 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 1067 | **/ |
Sergunb | 0:8918a71cdbe9 | 1068 | |
Sergunb | 0:8918a71cdbe9 | 1069 | error_t mib2GetNextTcpConnEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 1070 | size_t oidLen, uint8_t *nextOid, size_t *nextOidLen) |
Sergunb | 0:8918a71cdbe9 | 1071 | { |
Sergunb | 0:8918a71cdbe9 | 1072 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 1073 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 1074 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 1075 | bool_t acceptable; |
Sergunb | 0:8918a71cdbe9 | 1076 | Ipv4Addr localIpAddr; |
Sergunb | 0:8918a71cdbe9 | 1077 | uint16_t localPort; |
Sergunb | 0:8918a71cdbe9 | 1078 | Ipv4Addr remoteIpAddr; |
Sergunb | 0:8918a71cdbe9 | 1079 | uint16_t remotePort; |
Sergunb | 0:8918a71cdbe9 | 1080 | Socket *socket; |
Sergunb | 0:8918a71cdbe9 | 1081 | |
Sergunb | 0:8918a71cdbe9 | 1082 | //Initialize variables |
Sergunb | 0:8918a71cdbe9 | 1083 | localIpAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 1084 | localPort = 0; |
Sergunb | 0:8918a71cdbe9 | 1085 | remoteIpAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 1086 | remotePort = 0; |
Sergunb | 0:8918a71cdbe9 | 1087 | |
Sergunb | 0:8918a71cdbe9 | 1088 | //Make sure the buffer is large enough to hold the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1089 | if(*nextOidLen < object->oidLen) |
Sergunb | 0:8918a71cdbe9 | 1090 | return ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 1091 | |
Sergunb | 0:8918a71cdbe9 | 1092 | //Copy OID prefix |
Sergunb | 0:8918a71cdbe9 | 1093 | memcpy(nextOid, object->oid, object->oidLen); |
Sergunb | 0:8918a71cdbe9 | 1094 | |
Sergunb | 0:8918a71cdbe9 | 1095 | //Loop through socket descriptors |
Sergunb | 0:8918a71cdbe9 | 1096 | for(i = 0; i < SOCKET_MAX_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 1097 | { |
Sergunb | 0:8918a71cdbe9 | 1098 | //Point to current socket |
Sergunb | 0:8918a71cdbe9 | 1099 | socket = &socketTable[i]; |
Sergunb | 0:8918a71cdbe9 | 1100 | |
Sergunb | 0:8918a71cdbe9 | 1101 | //TCP socket? |
Sergunb | 0:8918a71cdbe9 | 1102 | if(socketTable[i].type == SOCKET_TYPE_STREAM) |
Sergunb | 0:8918a71cdbe9 | 1103 | { |
Sergunb | 0:8918a71cdbe9 | 1104 | //Filter out IPv6 connections |
Sergunb | 0:8918a71cdbe9 | 1105 | if(socket->localIpAddr.length != sizeof(Ipv6Addr) && |
Sergunb | 0:8918a71cdbe9 | 1106 | socket->remoteIpAddr.length != sizeof(Ipv6Addr)) |
Sergunb | 0:8918a71cdbe9 | 1107 | { |
Sergunb | 0:8918a71cdbe9 | 1108 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1109 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1110 | |
Sergunb | 0:8918a71cdbe9 | 1111 | //The tcpConnLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1112 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, socket->localIpAddr.ipv4Addr); |
Sergunb | 0:8918a71cdbe9 | 1113 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1114 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1115 | return error; |
Sergunb | 0:8918a71cdbe9 | 1116 | |
Sergunb | 0:8918a71cdbe9 | 1117 | //The tcpConnLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1118 | error = mibEncodePort(nextOid, *nextOidLen, &n, socket->localPort); |
Sergunb | 0:8918a71cdbe9 | 1119 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1120 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1121 | return error; |
Sergunb | 0:8918a71cdbe9 | 1122 | |
Sergunb | 0:8918a71cdbe9 | 1123 | //The tcpConnRemAddress is used as 3rd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1124 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, socket->remoteIpAddr.ipv4Addr); |
Sergunb | 0:8918a71cdbe9 | 1125 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1126 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1127 | return error; |
Sergunb | 0:8918a71cdbe9 | 1128 | |
Sergunb | 0:8918a71cdbe9 | 1129 | //The tcpConnRemPort is used as 4th instance identifier |
Sergunb | 0:8918a71cdbe9 | 1130 | error = mibEncodePort(nextOid, *nextOidLen, &n, socket->remotePort); |
Sergunb | 0:8918a71cdbe9 | 1131 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1132 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1133 | return error; |
Sergunb | 0:8918a71cdbe9 | 1134 | |
Sergunb | 0:8918a71cdbe9 | 1135 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 1136 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 1137 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 1138 | { |
Sergunb | 0:8918a71cdbe9 | 1139 | //Perform lexicographic comparison |
Sergunb | 0:8918a71cdbe9 | 1140 | if(localPort == 0 && remotePort == 0) |
Sergunb | 0:8918a71cdbe9 | 1141 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1142 | else if(ntohl(socket->localIpAddr.ipv4Addr) < ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1143 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1144 | else if(ntohl(socket->localIpAddr.ipv4Addr) > ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1145 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1146 | else if(socket->localPort < localPort) |
Sergunb | 0:8918a71cdbe9 | 1147 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1148 | else if(socket->localPort > localPort) |
Sergunb | 0:8918a71cdbe9 | 1149 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1150 | else if(ntohl(socket->remoteIpAddr.ipv4Addr) < ntohl(remoteIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1151 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1152 | else if(ntohl(socket->remoteIpAddr.ipv4Addr) > ntohl(remoteIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1153 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1154 | else if(socket->remotePort < remotePort) |
Sergunb | 0:8918a71cdbe9 | 1155 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1156 | else |
Sergunb | 0:8918a71cdbe9 | 1157 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1158 | |
Sergunb | 0:8918a71cdbe9 | 1159 | //Save the closest object identifier that follows the specified |
Sergunb | 0:8918a71cdbe9 | 1160 | //OID in lexicographic order |
Sergunb | 0:8918a71cdbe9 | 1161 | if(acceptable) |
Sergunb | 0:8918a71cdbe9 | 1162 | { |
Sergunb | 0:8918a71cdbe9 | 1163 | localIpAddr = socket->localIpAddr.ipv4Addr; |
Sergunb | 0:8918a71cdbe9 | 1164 | localPort = socket->localPort; |
Sergunb | 0:8918a71cdbe9 | 1165 | remoteIpAddr = socket->remoteIpAddr.ipv4Addr; |
Sergunb | 0:8918a71cdbe9 | 1166 | remotePort = socket->remotePort; |
Sergunb | 0:8918a71cdbe9 | 1167 | } |
Sergunb | 0:8918a71cdbe9 | 1168 | } |
Sergunb | 0:8918a71cdbe9 | 1169 | } |
Sergunb | 0:8918a71cdbe9 | 1170 | } |
Sergunb | 0:8918a71cdbe9 | 1171 | } |
Sergunb | 0:8918a71cdbe9 | 1172 | |
Sergunb | 0:8918a71cdbe9 | 1173 | //The specified OID does not lexicographically precede the name |
Sergunb | 0:8918a71cdbe9 | 1174 | //of some object? |
Sergunb | 0:8918a71cdbe9 | 1175 | if(localPort == 0 && remotePort == 0) |
Sergunb | 0:8918a71cdbe9 | 1176 | return ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1177 | |
Sergunb | 0:8918a71cdbe9 | 1178 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1179 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1180 | |
Sergunb | 0:8918a71cdbe9 | 1181 | //The tcpConnLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1182 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, localIpAddr); |
Sergunb | 0:8918a71cdbe9 | 1183 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1184 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1185 | return error; |
Sergunb | 0:8918a71cdbe9 | 1186 | |
Sergunb | 0:8918a71cdbe9 | 1187 | //The tcpConnLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1188 | error = mibEncodePort(nextOid, *nextOidLen, &n, localPort); |
Sergunb | 0:8918a71cdbe9 | 1189 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1190 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1191 | return error; |
Sergunb | 0:8918a71cdbe9 | 1192 | |
Sergunb | 0:8918a71cdbe9 | 1193 | //The tcpConnRemAddress is used as 3rd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1194 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, remoteIpAddr); |
Sergunb | 0:8918a71cdbe9 | 1195 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1196 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1197 | return error; |
Sergunb | 0:8918a71cdbe9 | 1198 | |
Sergunb | 0:8918a71cdbe9 | 1199 | //The tcpConnRemPort is used as 4th instance identifier |
Sergunb | 0:8918a71cdbe9 | 1200 | error = mibEncodePort(nextOid, *nextOidLen, &n, remotePort); |
Sergunb | 0:8918a71cdbe9 | 1201 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1202 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1203 | return error; |
Sergunb | 0:8918a71cdbe9 | 1204 | |
Sergunb | 0:8918a71cdbe9 | 1205 | //Save the length of the resulting object identifier |
Sergunb | 0:8918a71cdbe9 | 1206 | *nextOidLen = n; |
Sergunb | 0:8918a71cdbe9 | 1207 | //Next object found |
Sergunb | 0:8918a71cdbe9 | 1208 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 1209 | } |
Sergunb | 0:8918a71cdbe9 | 1210 | |
Sergunb | 0:8918a71cdbe9 | 1211 | |
Sergunb | 0:8918a71cdbe9 | 1212 | /** |
Sergunb | 0:8918a71cdbe9 | 1213 | * @brief Get udpEntry object value |
Sergunb | 0:8918a71cdbe9 | 1214 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 1215 | * @param[in] oid Object identifier (object name and instance identifier) |
Sergunb | 0:8918a71cdbe9 | 1216 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 1217 | * @param[out] value Object value |
Sergunb | 0:8918a71cdbe9 | 1218 | * @param[in,out] valueLen Length of the object value, in bytes |
Sergunb | 0:8918a71cdbe9 | 1219 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 1220 | **/ |
Sergunb | 0:8918a71cdbe9 | 1221 | |
Sergunb | 0:8918a71cdbe9 | 1222 | error_t mib2GetUdpEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 1223 | size_t oidLen, MibVariant *value, size_t *valueLen) |
Sergunb | 0:8918a71cdbe9 | 1224 | { |
Sergunb | 0:8918a71cdbe9 | 1225 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 1226 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 1227 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 1228 | Ipv4Addr localIpAddr; |
Sergunb | 0:8918a71cdbe9 | 1229 | uint16_t localPort; |
Sergunb | 0:8918a71cdbe9 | 1230 | |
Sergunb | 0:8918a71cdbe9 | 1231 | //Point to the instance identifier |
Sergunb | 0:8918a71cdbe9 | 1232 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1233 | |
Sergunb | 0:8918a71cdbe9 | 1234 | //The udpLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1235 | error = mibDecodeIpv4Addr(oid, oidLen, &n, &localIpAddr); |
Sergunb | 0:8918a71cdbe9 | 1236 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 1237 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1238 | return error; |
Sergunb | 0:8918a71cdbe9 | 1239 | |
Sergunb | 0:8918a71cdbe9 | 1240 | //The udpLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1241 | error = mibDecodePort(oid, oidLen, &n, &localPort); |
Sergunb | 0:8918a71cdbe9 | 1242 | //Invalid instance identifier? |
Sergunb | 0:8918a71cdbe9 | 1243 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1244 | return error; |
Sergunb | 0:8918a71cdbe9 | 1245 | |
Sergunb | 0:8918a71cdbe9 | 1246 | //Sanity check |
Sergunb | 0:8918a71cdbe9 | 1247 | if(n != oidLen) |
Sergunb | 0:8918a71cdbe9 | 1248 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1249 | |
Sergunb | 0:8918a71cdbe9 | 1250 | //Loop through socket descriptors |
Sergunb | 0:8918a71cdbe9 | 1251 | for(i = 0; i < SOCKET_MAX_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 1252 | { |
Sergunb | 0:8918a71cdbe9 | 1253 | //Point to current socket |
Sergunb | 0:8918a71cdbe9 | 1254 | Socket *socket = &socketTable[i]; |
Sergunb | 0:8918a71cdbe9 | 1255 | |
Sergunb | 0:8918a71cdbe9 | 1256 | //UDP socket? |
Sergunb | 0:8918a71cdbe9 | 1257 | if(socketTable[i].type == SOCKET_TYPE_DGRAM) |
Sergunb | 0:8918a71cdbe9 | 1258 | { |
Sergunb | 0:8918a71cdbe9 | 1259 | //Check local IP address |
Sergunb | 0:8918a71cdbe9 | 1260 | if(socket->localIpAddr.length == sizeof(Ipv6Addr)) |
Sergunb | 0:8918a71cdbe9 | 1261 | continue; |
Sergunb | 0:8918a71cdbe9 | 1262 | if(socket->localIpAddr.ipv4Addr != localIpAddr) |
Sergunb | 0:8918a71cdbe9 | 1263 | continue; |
Sergunb | 0:8918a71cdbe9 | 1264 | //Check local port number |
Sergunb | 0:8918a71cdbe9 | 1265 | if(socket->localPort != localPort) |
Sergunb | 0:8918a71cdbe9 | 1266 | continue; |
Sergunb | 0:8918a71cdbe9 | 1267 | |
Sergunb | 0:8918a71cdbe9 | 1268 | //A matching socket has been found |
Sergunb | 0:8918a71cdbe9 | 1269 | break; |
Sergunb | 0:8918a71cdbe9 | 1270 | } |
Sergunb | 0:8918a71cdbe9 | 1271 | } |
Sergunb | 0:8918a71cdbe9 | 1272 | |
Sergunb | 0:8918a71cdbe9 | 1273 | //No matching connection found in socket table? |
Sergunb | 0:8918a71cdbe9 | 1274 | if(i >= SOCKET_MAX_COUNT) |
Sergunb | 0:8918a71cdbe9 | 1275 | { |
Sergunb | 0:8918a71cdbe9 | 1276 | //Loop through the UDP callback table |
Sergunb | 0:8918a71cdbe9 | 1277 | for(i = 0; i < UDP_CALLBACK_TABLE_SIZE; i++) |
Sergunb | 0:8918a71cdbe9 | 1278 | { |
Sergunb | 0:8918a71cdbe9 | 1279 | //Point to the current entry |
Sergunb | 0:8918a71cdbe9 | 1280 | UdpRxCallbackDesc *entry = &udpCallbackTable[i]; |
Sergunb | 0:8918a71cdbe9 | 1281 | |
Sergunb | 0:8918a71cdbe9 | 1282 | //Check whether the entry is currently in used |
Sergunb | 0:8918a71cdbe9 | 1283 | if(entry->callback != NULL) |
Sergunb | 0:8918a71cdbe9 | 1284 | { |
Sergunb | 0:8918a71cdbe9 | 1285 | //Check local port number |
Sergunb | 0:8918a71cdbe9 | 1286 | if(entry->port == localPort) |
Sergunb | 0:8918a71cdbe9 | 1287 | break; |
Sergunb | 0:8918a71cdbe9 | 1288 | } |
Sergunb | 0:8918a71cdbe9 | 1289 | } |
Sergunb | 0:8918a71cdbe9 | 1290 | |
Sergunb | 0:8918a71cdbe9 | 1291 | //No matching connection found in UDP callback table? |
Sergunb | 0:8918a71cdbe9 | 1292 | if(i >= UDP_CALLBACK_TABLE_SIZE) |
Sergunb | 0:8918a71cdbe9 | 1293 | return ERROR_INSTANCE_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1294 | } |
Sergunb | 0:8918a71cdbe9 | 1295 | |
Sergunb | 0:8918a71cdbe9 | 1296 | //udpLocalAddress object? |
Sergunb | 0:8918a71cdbe9 | 1297 | if(!strcmp(object->name, "udpLocalAddress")) |
Sergunb | 0:8918a71cdbe9 | 1298 | { |
Sergunb | 0:8918a71cdbe9 | 1299 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1300 | ipv4CopyAddr(value->ipAddr, &localIpAddr); |
Sergunb | 0:8918a71cdbe9 | 1301 | } |
Sergunb | 0:8918a71cdbe9 | 1302 | //udpLocalPort object? |
Sergunb | 0:8918a71cdbe9 | 1303 | else if(!strcmp(object->name, "udpLocalPort")) |
Sergunb | 0:8918a71cdbe9 | 1304 | { |
Sergunb | 0:8918a71cdbe9 | 1305 | //Get object value |
Sergunb | 0:8918a71cdbe9 | 1306 | value->integer = localPort; |
Sergunb | 0:8918a71cdbe9 | 1307 | } |
Sergunb | 0:8918a71cdbe9 | 1308 | //Unknown object? |
Sergunb | 0:8918a71cdbe9 | 1309 | else |
Sergunb | 0:8918a71cdbe9 | 1310 | { |
Sergunb | 0:8918a71cdbe9 | 1311 | //The specified object does not exist |
Sergunb | 0:8918a71cdbe9 | 1312 | error = ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1313 | } |
Sergunb | 0:8918a71cdbe9 | 1314 | |
Sergunb | 0:8918a71cdbe9 | 1315 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 1316 | return error; |
Sergunb | 0:8918a71cdbe9 | 1317 | } |
Sergunb | 0:8918a71cdbe9 | 1318 | |
Sergunb | 0:8918a71cdbe9 | 1319 | |
Sergunb | 0:8918a71cdbe9 | 1320 | /** |
Sergunb | 0:8918a71cdbe9 | 1321 | * @brief Get next udpEntry object |
Sergunb | 0:8918a71cdbe9 | 1322 | * @param[in] object Pointer to the MIB object descriptor |
Sergunb | 0:8918a71cdbe9 | 1323 | * @param[in] oid Object identifier |
Sergunb | 0:8918a71cdbe9 | 1324 | * @param[in] oidLen Length of the OID, in bytes |
Sergunb | 0:8918a71cdbe9 | 1325 | * @param[out] nextOid OID of the next object in the MIB |
Sergunb | 0:8918a71cdbe9 | 1326 | * @param[out] nextOidLen Length of the next object identifier, in bytes |
Sergunb | 0:8918a71cdbe9 | 1327 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 1328 | **/ |
Sergunb | 0:8918a71cdbe9 | 1329 | |
Sergunb | 0:8918a71cdbe9 | 1330 | error_t mib2GetNextUdpEntry(const MibObject *object, const uint8_t *oid, |
Sergunb | 0:8918a71cdbe9 | 1331 | size_t oidLen, uint8_t *nextOid, size_t *nextOidLen) |
Sergunb | 0:8918a71cdbe9 | 1332 | { |
Sergunb | 0:8918a71cdbe9 | 1333 | error_t error; |
Sergunb | 0:8918a71cdbe9 | 1334 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 1335 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 1336 | bool_t acceptable; |
Sergunb | 0:8918a71cdbe9 | 1337 | Ipv4Addr localIpAddr; |
Sergunb | 0:8918a71cdbe9 | 1338 | uint16_t localPort; |
Sergunb | 0:8918a71cdbe9 | 1339 | |
Sergunb | 0:8918a71cdbe9 | 1340 | //Initialize variables |
Sergunb | 0:8918a71cdbe9 | 1341 | localIpAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 1342 | localPort = 0; |
Sergunb | 0:8918a71cdbe9 | 1343 | |
Sergunb | 0:8918a71cdbe9 | 1344 | //Make sure the buffer is large enough to hold the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1345 | if(*nextOidLen < object->oidLen) |
Sergunb | 0:8918a71cdbe9 | 1346 | return ERROR_BUFFER_OVERFLOW; |
Sergunb | 0:8918a71cdbe9 | 1347 | |
Sergunb | 0:8918a71cdbe9 | 1348 | //Copy OID prefix |
Sergunb | 0:8918a71cdbe9 | 1349 | memcpy(nextOid, object->oid, object->oidLen); |
Sergunb | 0:8918a71cdbe9 | 1350 | |
Sergunb | 0:8918a71cdbe9 | 1351 | //Loop through socket descriptors |
Sergunb | 0:8918a71cdbe9 | 1352 | for(i = 0; i < SOCKET_MAX_COUNT; i++) |
Sergunb | 0:8918a71cdbe9 | 1353 | { |
Sergunb | 0:8918a71cdbe9 | 1354 | //Point to current socket |
Sergunb | 0:8918a71cdbe9 | 1355 | Socket *socket = &socketTable[i]; |
Sergunb | 0:8918a71cdbe9 | 1356 | |
Sergunb | 0:8918a71cdbe9 | 1357 | //TCP socket? |
Sergunb | 0:8918a71cdbe9 | 1358 | if(socketTable[i].type == SOCKET_TYPE_DGRAM) |
Sergunb | 0:8918a71cdbe9 | 1359 | { |
Sergunb | 0:8918a71cdbe9 | 1360 | //Filter out IPv6 connections |
Sergunb | 0:8918a71cdbe9 | 1361 | if(socket->localIpAddr.length != sizeof(Ipv6Addr) && |
Sergunb | 0:8918a71cdbe9 | 1362 | socket->remoteIpAddr.length != sizeof(Ipv6Addr)) |
Sergunb | 0:8918a71cdbe9 | 1363 | { |
Sergunb | 0:8918a71cdbe9 | 1364 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1365 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1366 | |
Sergunb | 0:8918a71cdbe9 | 1367 | //The udpLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1368 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, socket->localIpAddr.ipv4Addr); |
Sergunb | 0:8918a71cdbe9 | 1369 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1370 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1371 | return error; |
Sergunb | 0:8918a71cdbe9 | 1372 | |
Sergunb | 0:8918a71cdbe9 | 1373 | //The udpLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1374 | error = mibEncodePort(nextOid, *nextOidLen, &n, socket->localPort); |
Sergunb | 0:8918a71cdbe9 | 1375 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1376 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1377 | return error; |
Sergunb | 0:8918a71cdbe9 | 1378 | |
Sergunb | 0:8918a71cdbe9 | 1379 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 1380 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 1381 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 1382 | { |
Sergunb | 0:8918a71cdbe9 | 1383 | //Perform lexicographic comparison |
Sergunb | 0:8918a71cdbe9 | 1384 | if(localPort == 0) |
Sergunb | 0:8918a71cdbe9 | 1385 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1386 | else if(ntohl(socket->localIpAddr.ipv4Addr) < ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1387 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1388 | else if(ntohl(socket->localIpAddr.ipv4Addr) > ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1389 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1390 | else if(socket->localPort < localPort) |
Sergunb | 0:8918a71cdbe9 | 1391 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1392 | else |
Sergunb | 0:8918a71cdbe9 | 1393 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1394 | |
Sergunb | 0:8918a71cdbe9 | 1395 | //Save the closest object identifier that follows the specified |
Sergunb | 0:8918a71cdbe9 | 1396 | //OID in lexicographic order |
Sergunb | 0:8918a71cdbe9 | 1397 | if(acceptable) |
Sergunb | 0:8918a71cdbe9 | 1398 | { |
Sergunb | 0:8918a71cdbe9 | 1399 | localIpAddr = socket->localIpAddr.ipv4Addr; |
Sergunb | 0:8918a71cdbe9 | 1400 | localPort = socket->localPort; |
Sergunb | 0:8918a71cdbe9 | 1401 | } |
Sergunb | 0:8918a71cdbe9 | 1402 | } |
Sergunb | 0:8918a71cdbe9 | 1403 | } |
Sergunb | 0:8918a71cdbe9 | 1404 | } |
Sergunb | 0:8918a71cdbe9 | 1405 | } |
Sergunb | 0:8918a71cdbe9 | 1406 | |
Sergunb | 0:8918a71cdbe9 | 1407 | //Loop through the UDP callback table |
Sergunb | 0:8918a71cdbe9 | 1408 | for(i = 0; i < UDP_CALLBACK_TABLE_SIZE; i++) |
Sergunb | 0:8918a71cdbe9 | 1409 | { |
Sergunb | 0:8918a71cdbe9 | 1410 | //Point to the current entry |
Sergunb | 0:8918a71cdbe9 | 1411 | UdpRxCallbackDesc *entry = &udpCallbackTable[i]; |
Sergunb | 0:8918a71cdbe9 | 1412 | |
Sergunb | 0:8918a71cdbe9 | 1413 | //Check whether the entry is currently in used |
Sergunb | 0:8918a71cdbe9 | 1414 | if(entry->callback != NULL) |
Sergunb | 0:8918a71cdbe9 | 1415 | { |
Sergunb | 0:8918a71cdbe9 | 1416 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1417 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1418 | |
Sergunb | 0:8918a71cdbe9 | 1419 | //The udpLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1420 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, IPV4_UNSPECIFIED_ADDR); |
Sergunb | 0:8918a71cdbe9 | 1421 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1422 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1423 | return error; |
Sergunb | 0:8918a71cdbe9 | 1424 | |
Sergunb | 0:8918a71cdbe9 | 1425 | //The udpLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1426 | error = mibEncodePort(nextOid, *nextOidLen, &n, entry->port); |
Sergunb | 0:8918a71cdbe9 | 1427 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1428 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1429 | return error; |
Sergunb | 0:8918a71cdbe9 | 1430 | |
Sergunb | 0:8918a71cdbe9 | 1431 | //Check whether the resulting object identifier lexicographically |
Sergunb | 0:8918a71cdbe9 | 1432 | //follows the specified OID |
Sergunb | 0:8918a71cdbe9 | 1433 | if(oidComp(nextOid, n, oid, oidLen) > 0) |
Sergunb | 0:8918a71cdbe9 | 1434 | { |
Sergunb | 0:8918a71cdbe9 | 1435 | //Perform lexicographic comparison |
Sergunb | 0:8918a71cdbe9 | 1436 | if(localPort == 0) |
Sergunb | 0:8918a71cdbe9 | 1437 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1438 | else if(ntohl(IPV4_UNSPECIFIED_ADDR) < ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1439 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1440 | else if(ntohl(IPV4_UNSPECIFIED_ADDR) > ntohl(localIpAddr)) |
Sergunb | 0:8918a71cdbe9 | 1441 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1442 | else if(entry->port < localPort) |
Sergunb | 0:8918a71cdbe9 | 1443 | acceptable = TRUE; |
Sergunb | 0:8918a71cdbe9 | 1444 | else |
Sergunb | 0:8918a71cdbe9 | 1445 | acceptable = FALSE; |
Sergunb | 0:8918a71cdbe9 | 1446 | |
Sergunb | 0:8918a71cdbe9 | 1447 | //Save the closest object identifier that follows the specified |
Sergunb | 0:8918a71cdbe9 | 1448 | //OID in lexicographic order |
Sergunb | 0:8918a71cdbe9 | 1449 | if(acceptable) |
Sergunb | 0:8918a71cdbe9 | 1450 | { |
Sergunb | 0:8918a71cdbe9 | 1451 | localIpAddr = IPV4_UNSPECIFIED_ADDR; |
Sergunb | 0:8918a71cdbe9 | 1452 | localPort = entry->port; |
Sergunb | 0:8918a71cdbe9 | 1453 | } |
Sergunb | 0:8918a71cdbe9 | 1454 | } |
Sergunb | 0:8918a71cdbe9 | 1455 | } |
Sergunb | 0:8918a71cdbe9 | 1456 | } |
Sergunb | 0:8918a71cdbe9 | 1457 | |
Sergunb | 0:8918a71cdbe9 | 1458 | //The specified OID does not lexicographically precede the name |
Sergunb | 0:8918a71cdbe9 | 1459 | //of some object? |
Sergunb | 0:8918a71cdbe9 | 1460 | if(localPort == 0) |
Sergunb | 0:8918a71cdbe9 | 1461 | return ERROR_OBJECT_NOT_FOUND; |
Sergunb | 0:8918a71cdbe9 | 1462 | |
Sergunb | 0:8918a71cdbe9 | 1463 | //Append the instance identifier to the OID prefix |
Sergunb | 0:8918a71cdbe9 | 1464 | n = object->oidLen; |
Sergunb | 0:8918a71cdbe9 | 1465 | |
Sergunb | 0:8918a71cdbe9 | 1466 | //The udpLocalAddress is used as 1st instance identifier |
Sergunb | 0:8918a71cdbe9 | 1467 | error = mibEncodeIpv4Addr(nextOid, *nextOidLen, &n, localIpAddr); |
Sergunb | 0:8918a71cdbe9 | 1468 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1469 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1470 | return error; |
Sergunb | 0:8918a71cdbe9 | 1471 | |
Sergunb | 0:8918a71cdbe9 | 1472 | //The udpLocalPort is used as 2nd instance identifier |
Sergunb | 0:8918a71cdbe9 | 1473 | error = mibEncodePort(nextOid, *nextOidLen, &n, localPort); |
Sergunb | 0:8918a71cdbe9 | 1474 | //Any error to report? |
Sergunb | 0:8918a71cdbe9 | 1475 | if(error) |
Sergunb | 0:8918a71cdbe9 | 1476 | return error; |
Sergunb | 0:8918a71cdbe9 | 1477 | |
Sergunb | 0:8918a71cdbe9 | 1478 | //Save the length of the resulting object identifier |
Sergunb | 0:8918a71cdbe9 | 1479 | *nextOidLen = n; |
Sergunb | 0:8918a71cdbe9 | 1480 | //Next object found |
Sergunb | 0:8918a71cdbe9 | 1481 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 1482 | } |
Sergunb | 0:8918a71cdbe9 | 1483 | |
Sergunb | 0:8918a71cdbe9 | 1484 | #endif |
Sergunb | 0:8918a71cdbe9 | 1485 | #endif |
Sergunb | 0:8918a71cdbe9 | 1486 |