LwIP 2.2.1在STM32F407VET6平台 移植

This commit is contained in:
冯佳
2026-01-29 17:26:04 +08:00
parent ffd33c4644
commit e7e10a8328
2207 changed files with 409723 additions and 165 deletions

View File

@ -0,0 +1,29 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/31
* Time: 13:18
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// The AGENT-CAPABILITIES construct is used to specify implementation characteristics of an SNMP agent sub-system with respect to object types and events.
/// </summary>
public sealed class AgentCapabilities : EntityBase
{
/// <summary>
/// Creates an <see cref="AgentCapabilities"/> instance.
/// </summary>
/// <param name="module"></param>
/// <param name="header"></param>
/// <param name="lexer"></param>
public AgentCapabilities(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,46 @@
using System;
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
public abstract class EntityBase: IEntity
{
private readonly IModule _module;
private string _parent;
private readonly uint _value;
private readonly string _name;
public EntityBase(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
{
_module = module;
_name = preAssignSymbols[0].ToString();
Lexer.ParseOidValue(symbols, out _parent, out _value);
}
public IModule Module
{
get { return _module; }
}
public string Parent
{
get { return _parent; }
set { _parent = value; }
}
public uint Value
{
get { return _value; }
}
public string Name
{
get { return _name; }
}
public virtual string Description
{
get { return string.Empty; }
}
}
}

View File

@ -0,0 +1,62 @@
// Entity interface.
// Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/19
* Time: 20:10
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Basic interface for all elements building up the MIB tree, thus having an OID as value.
/// </summary>
public interface IEntity : IDeclaration
{
/// <summary>
/// Parent name.
/// </summary>
string Parent
{
get;
set;
}
/// <summary>
/// Value.
/// </summary>
uint Value
{
get;
}
/// <summary>
/// Gets the description.
/// </summary>
/// <value>The description.</value>
string Description
{
get;
}
}
}

View File

@ -0,0 +1,23 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/21
* Time: 19:35
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Description of ModuleComplianceNode.
/// </summary>
public sealed class ModuleCompliance : EntityBase
{
public ModuleCompliance(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,10 @@
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
public sealed class ModuleIdentity : EntityBase
{
public ModuleIdentity(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,22 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/21
* Time: 19:34
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Description of NotificationGroupNode.
/// </summary>
public sealed class NotificationGroup : EntityBase
{
public NotificationGroup(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,11 @@
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
public sealed class NotificationType : EntityBase
{
public NotificationType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,22 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/21
* Time: 19:27
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Description of ObjectGroupNode.
/// </summary>
public sealed class ObjectGroup : EntityBase
{
public ObjectGroup(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,21 @@
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Object identifier node.
/// </summary>
public sealed class ObjectIdentity : EntityBase
{
/// <summary>
/// Creates a <see cref="ObjectIdentity"/>.
/// </summary>
/// <param name="module">Module name</param>
/// <param name="header">Header</param>
/// <param name="lexer">Lexer</param>
public ObjectIdentity(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,336 @@
using System;
using System.Collections.Generic;
using Lextm.SharpSnmpLib.Mib.Elements.Types;
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
public sealed class ObjectType : EntityBase, ITypeReferrer
{
private ITypeAssignment _syntax;
private string _units;
private MaxAccess _access;
private Status _status;
private string _description;
private string _reference;
private IList<string> _indices;
private string _augments;
private string _defVal;
public ObjectType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
ParseProperties(preAssignSymbols);
}
private void ParseProperties(SymbolList header)
{
ISymbolEnumerator headerSymbols = header.GetSymbolEnumerator();
Symbol temp = headerSymbols.NextNonEOLSymbol();
// Skip name
temp = headerSymbols.NextNonEOLSymbol();
temp.Expect(Symbol.ObjectType);
_syntax = ParseSyntax (Module, headerSymbols);
_units = ParseUnits (headerSymbols);
_access = ParseAccess (headerSymbols);
_status = ParseStatus (headerSymbols);
_description = ParseDescription (headerSymbols);
_reference = ParseReference (headerSymbols);
_indices = ParseIndices (headerSymbols);
_augments = ParseAugments (headerSymbols);
_defVal = ParseDefVal (headerSymbols);
}
private static string ParseAugments(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Augments)
{
string augment = null;
current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.OpenBracket);
current = symbols.NextNonEOLSymbol();
augment = current.ToString();
current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.CloseBracket);
return augment;
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static string ParseDefVal(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.DefVal)
{
current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.OpenBracket);
string defVal = null;
current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenBracket)
{
int depth = 1;
// TODO: decode this.
while (depth > 0)
{
current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenBracket)
{
depth++;
}
else if (current == Symbol.CloseBracket)
{
depth--;
}
}
}
else
{
defVal = current.ToString();
current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.CloseBracket);
}
return defVal;
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static IList<string> ParseIndices(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Index)
{
current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.OpenBracket);
List<string> indices = new List<string>();
while (current != Symbol.CloseBracket)
{
current = symbols.NextNonEOLSymbol();
bool lastIndex = false;
if (current == Symbol.Implied)
{
current = symbols.NextNonEOLSymbol();
lastIndex = true; // 'IMPLIED' may only be used for last index
}
current.Assert((current != Symbol.Comma) && (current != Symbol.CloseBracket), "Expected index name but found symbol!");
indices.Add(current.ToString());
current = symbols.NextNonEOLSymbol();
if (lastIndex)
{
current.Expect(Symbol.CloseBracket);
}
else
{
current.Expect(Symbol.Comma, Symbol.CloseBracket);
}
}
return indices;
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static string ParseReference(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Reference)
{
return symbols.NextNonEOLSymbol().ToString();
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static string ParseDescription(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Description)
{
return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' });
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static Status ParseStatus(ISymbolEnumerator symbols)
{
Status status = Status.obsolete;
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.Status);
current = symbols.NextNonEOLSymbol();
try
{
status = (Status)Enum.Parse(typeof(Status), current.ToString());
}
catch (ArgumentException)
{
current.Assert(false, "Invalid/Unknown status");
}
return status;
}
private static MaxAccess ParseAccess(ISymbolEnumerator symbols)
{
MaxAccess access = MaxAccess.notAccessible;
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.MaxAccess, Symbol.Access);
current = symbols.NextNonEOLSymbol();
switch (current.ToString())
{
case "not-accessible":
access = MaxAccess.notAccessible;
break;
case "accessible-for-notify":
access = MaxAccess.accessibleForNotify;
break;
case "read-only":
access = MaxAccess.readOnly;
break;
case "read-write":
access = MaxAccess.readWrite;
break;
case "read-create":
access = MaxAccess.readCreate;
break;
case "write-only":
access = MaxAccess.readWrite;
break;
default:
current.Assert(false, "Invalid/Unknown access");
break;
}
return access;
}
private static string ParseUnits(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Units)
{
return symbols.NextNonEOLSymbol().ToString();
}
else if (current != null)
{
symbols.PutBack(current);
}
return null;
}
private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.Syntax);
return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true);
}
private static bool IsProperty(Symbol sym)
{
string s = sym.ToString();
return s == "SYNTAX" || s == "MAX-ACCESS" || s == "STATUS" || s == "DESCRIPTION";
}
public ITypeAssignment Syntax
{
get { return _syntax; }
internal set { _syntax = value; }
}
public override string Description
{
get { return _description; }
}
public MaxAccess Access
{
get { return _access; }
}
public IList<string> Indices
{
get { return _indices; }
}
public string Augments
{
get { return _augments; }
}
#region ITypeReferrer Member
public ITypeAssignment ReferredType
{
get { return _syntax; }
set { _syntax = value; }
}
public ITypeAssignment BaseType
{
get
{
ITypeReferrer tr = this;
ITypeAssignment result = null;
while ((tr != null) && (tr.ReferredType != null))
{
result = tr.ReferredType;
tr = tr.ReferredType as ITypeReferrer;
}
return result;
}
}
#endregion
}
}

View File

@ -0,0 +1,30 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/17
* Time: 20:49
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace Lextm.SharpSnmpLib.Mib.Elements.Entities
{
/// <summary>
/// Object identifier node.
/// </summary>
public sealed class OidValueAssignment : EntityBase
{
/// <summary>
/// Creates a <see cref="OidValueAssignment"/>.
/// </summary>
/// <param name="module">Module</param>
/// <param name="name">Name</param>
/// <param name="lexer">Lexer</param>
public OidValueAssignment(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
: base(module, preAssignSymbols, symbols)
{
}
}
}

View File

@ -0,0 +1,56 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/6/7
* Time: 17:34
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements
{
/// <summary>
/// Description of Exports.
/// </summary>
public sealed class Exports: IElement
{
private IModule _module;
private readonly IList<string> _types = new List<string>();
public Exports(IModule module, ISymbolEnumerator s)
{
_module = module;
Symbol previous = null;
Symbol current;
do
{
current = s.NextSymbol();
if (current == Symbol.EOL)
{
continue;
}
else if (((current == Symbol.Comma) || (current == Symbol.Semicolon)) && (previous != null))
{
previous.AssertIsValidIdentifier();
_types.Add(previous.ToString());
}
previous = current;
}
while (current != Symbol.Semicolon);
}
#region IElement Member
public IModule Module
{
get { return _module; }
}
#endregion
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lextm.SharpSnmpLib.Mib.Elements
{
public interface IDeclaration: IElement
{
/// <summary>
/// Name.
/// </summary>
string Name
{
get;
}
}
}

View File

@ -0,0 +1,35 @@
// Construct interface.
// Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
namespace Lextm.SharpSnmpLib.Mib.Elements
{
/// <summary>
/// Construct interface.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")]
public interface IElement
{
/// <summary>
/// Containing module.
/// </summary>
IModule Module
{
get;
}
}
}

View File

@ -0,0 +1,10 @@
using Lextm.SharpSnmpLib.Mib.Elements.Types;
namespace Lextm.SharpSnmpLib.Mib.Elements
{
public interface ITypeReferrer
{
ITypeAssignment ReferredType { get; set; }
ITypeAssignment BaseType { get; }
}
}

View File

@ -0,0 +1,81 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/31
* Time: 12:07
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements
{
/// <summary>
/// The IMPORTS construct is used to specify items used in the current MIB module which are defined in another MIB module or ASN.1 module.
/// </summary>
public sealed class Imports : List<ImportsFrom>, IElement
{
private IModule _module;
/// <summary>
/// Creates an <see cref="Imports"/> instance.
/// </summary>
/// <param name="lexer"></param>
public Imports(IModule module, ISymbolEnumerator symbols)
{
_module = module;
Symbol current;
while ((current = symbols.NextSymbol()) != Symbol.Semicolon)
{
if (current == Symbol.EOL)
{
continue;
}
ImportsFrom imports = new ImportsFrom(current, symbols);
this.Add(imports);
}
}
public IList<string> Dependents
{
get
{
List<string> result = new List<string>();
foreach (ImportsFrom import in this)
{
result.Add(import.Module);
}
return result;
}
}
public ImportsFrom GetImportFromType(string type)
{
foreach (ImportsFrom import in this)
{
if (import.Types.Contains(type))
{
return import;
}
}
return null;
}
#region IElement Member
public IModule Module
{
get { return _module; }
}
#endregion
}
}

View File

@ -0,0 +1,60 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/31
* Time: 12:07
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements
{
public sealed class ImportsFrom
{
private readonly string _module;
private readonly List<string> _types = new List<string>();
public ImportsFrom(Symbol last, ISymbolEnumerator symbols)
{
Symbol previous = last;
Symbol current;
while ((current = symbols.NextSymbol()) != Symbol.From)
{
if (current == Symbol.EOL)
{
continue;
}
if (current == Symbol.Comma)
{
previous.AssertIsValidIdentifier();
_types.Add(previous.ToString());
}
previous = current;
}
previous.AssertIsValidIdentifier();
_types.Add(previous.ToString());
_module = symbols.NextSymbol().ToString().ToUpperInvariant(); // module names are uppercase
}
public string Module
{
get { return _module; }
}
public IList<string> Types
{
get { return _types; }
}
public override string ToString()
{
return string.Join(", ", _types.ToArray()) + " FROM " + _module;
}
}
}

View File

@ -0,0 +1,48 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/31
* Time: 12:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements
{
public sealed class TrapType : IDeclaration
{
private readonly IModule _module;
private readonly string _name;
private readonly int _value;
public TrapType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
{
_module = module;
_name = preAssignSymbols[0].ToString();
Symbol valueSymbol = symbols.NextNonEOLSymbol();
bool succeeded = int.TryParse(valueSymbol.ToString(), out _value);
valueSymbol.Assert(succeeded, "not a decimal");
}
public int Value
{
get { return _value; }
}
#region IDeclaration Member
public IModule Module
{
get { return _module; }
}
public string Name
{
get { return _name; }
}
#endregion
}
}

View File

@ -0,0 +1,54 @@

namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public abstract class BaseType : ITypeAssignment
{
private IModule _module;
private string _name;
protected BaseType(IModule module, string name)
{
_module = module;
_name = name;
}
public virtual IModule Module
{
// differentiate between:
// FddiTimeNano ::= INTEGER (0..2147483647)
// which is an IntegerType which appears under Types in a MibModule and therefore has a name and module
// and
// SYNTAX INTEGER (0..2147483647)
// which is also an IntegerType but not defined as a separate type and therefore has NO name and NO module
get
{
if (!string.IsNullOrEmpty(_name))
{
return _module;
}
else
{
return null;
}
}
protected set { _module = value; }
}
public virtual string Name
{
get
{
if (!string.IsNullOrEmpty(_name))
{
return _name;
}
else
{
return "{ Implicit Base Type }";
}
}
protected set { _name = value; }
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public class BitsType : BaseType
{
private ValueMap _map;
public BitsType(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name)
{
_map = Lexer.DecodeEnumerations(symbols);
}
public ValueMap Map
{
get { return _map; }
}
public string this[int value]
{
get { return _map[value]; }
}
}
}

View File

@ -0,0 +1,35 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/31
* Time: 11:39
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/// <summary>
/// The CHOICE type represents a list of alternatives..
/// </summary>
public sealed class Choice : BaseType
{
/// <summary>
/// Creates a <see cref="Choice"/> instance.
/// </summary>
/// <param name="module"></param>
/// <param name="name"></param>
/// <param name="lexer"></param>
public Choice(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name)
{
while (symbols.NextNonEOLSymbol() != Symbol.OpenBracket)
{
}
while (symbols.NextNonEOLSymbol() != Symbol.CloseBracket)
{
}
}
}
}

View File

@ -0,0 +1,6 @@
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public interface ITypeAssignment : IDeclaration
{
}
}

View File

@ -0,0 +1,117 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/7/25
* Time: 20:41
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/// <summary>
/// The INTEGER type represents a list of alternatives, or a range of numbers..
/// Includes Integer32 as it's indistinguishable from INTEGER.
/// </summary>
/**
* As this type is used for Integer32 as well as INTEGER it incorrectly
* allows enumeration sub-typing of Integer32. This is ok as currently we
* do not care about detecting incorrect MIBs and this doesn't block the
* decoding of correct MIBs.
*/
public sealed class IntegerType : BaseType
{
public enum Types
{
Integer,
Integer32
}
private Types _type;
private bool _isEnumeration;
private ValueMap _map;
private ValueRanges _ranges;
/// <summary>
/// Creates an <see cref="IntegerType"/> instance.
/// </summary>
/// <param name="module"></param>
/// <param name="name"></param>
/// <param name="enumerator"></param>
public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
: base (module, name)
{
Types? t = GetExactType(type);
type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
_type = t.Value;
_isEnumeration = false;
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenBracket)
{
_isEnumeration = true;
symbols.PutBack(current);
_map = Lexer.DecodeEnumerations(symbols);
}
else if (current == Symbol.OpenParentheses)
{
symbols.PutBack(current);
_ranges = Lexer.DecodeRanges(symbols);
current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
}
else
{
symbols.PutBack(current);
}
}
public Types Type
{
get { return _type; }
}
public ValueRanges Ranges
{
get { return _ranges; }
}
public bool IsEnumeration
{
get
{
return _isEnumeration;
}
}
public ValueMap Enumeration
{
get { return _isEnumeration ? _map : null; }
}
internal static Types? GetExactType(Symbol symbol)
{
if (symbol == Symbol.Integer)
{
// represents the ASN.1 builtin INTEGER type:
// may be represent any arbitrary (signed/unsigned) integer (in theory may have any size)
return Types.Integer;
}
else if (symbol == Symbol.Integer32)
{
// Integer32 ::= INTEGER (-2147483648..2147483647) // from SNMPv2-SMI
return Types.Integer32;
}
return null;
}
internal static bool IsIntegerType(Symbol symbol)
{
return GetExactType(symbol).HasValue;
}
}
}

View File

@ -0,0 +1,21 @@

namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public class IpAddressType : OctetStringType
{
public IpAddressType(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name, symbols)
{
if (this.Size.Count != 0)
{
throw new MibException("Size definition not allowed for IpAddress type!");
}
// IpAddress type is defined as:
// IpAddress ::=
// [APPLICATION 0]
// IMPLICIT OCTET STRING (SIZE (4))
this.Size.Add(new ValueRange(4, null));
}
}
}

View File

@ -0,0 +1,34 @@

namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public sealed class Macro : ITypeAssignment
{
private IModule _module;
private string _name;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "temp")]
public Macro(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
{
_module = module;
_name = preAssignSymbols[0].ToString();
while (symbols.NextNonEOLSymbol() != Symbol.Begin)
{
}
while (symbols.NextNonEOLSymbol() != Symbol.End)
{
}
}
public IModule Module
{
get { return _module; }
}
public string Name
{
get { return _name; }
}
}
}

View File

@ -0,0 +1,11 @@

namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public class ObjectIdentifierType : BaseType
{
public ObjectIdentifierType(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name)
{
}
}
}

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public class OctetStringType : BaseType
{
private ValueRanges _size;
public OctetStringType(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenParentheses)
{
symbols.PutBack(current);
_size = Lexer.DecodeRanges(symbols);
current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!");
}
else
{
symbols.PutBack(current);
_size = new ValueRanges(isSizeDecl: true);
}
}
public ValueRanges Size
{
get { return _size; }
}
}
}

View File

@ -0,0 +1,11 @@

namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public class OpaqueType : OctetStringType
{
public OpaqueType(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name, symbols)
{
}
}
}

View File

@ -0,0 +1,46 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/21
* Time: 19:43
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/// <summary>
/// The SEQUENCE type represents a set of specified types. This is roughly analogous to a <code>struct</code> in C.
/// </summary>
public sealed class Sequence : BaseType
{
/// <summary>
/// Creates a <see cref="Sequence" /> instance.
/// </summary>
/// <param name="module">The module.</param>
/// <param name="name">The name.</param>
/// <param name="symbols">The enumerator.</param>
public Sequence(IModule module, string name, ISymbolEnumerator symbols)
: base(module, name)
{
// parse between ( )
Symbol temp = symbols.NextNonEOLSymbol();
int bracketSection = 0;
temp.Expect(Symbol.OpenBracket);
bracketSection++;
while (bracketSection > 0)
{
temp = symbols.NextNonEOLSymbol();
if (temp == Symbol.OpenBracket)
{
bracketSection++;
}
else if (temp == Symbol.CloseBracket)
{
bracketSection--;
}
}
}
}
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/// <summary>
/// The SEQUENCE OF type represents a list of data sets..
/// </summary>
public sealed class SequenceOf : BaseType
{
private string _type;
public SequenceOf(IModule module, string name, ISymbolEnumerator sym)
: base(module, name)
{
_type = sym.NextNonEOLSymbol().ToString();
}
public string Type
{
get { return _type; }
}
}
}

View File

@ -0,0 +1,238 @@
using System;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
public sealed class TextualConvention : ITypeAssignment, ITypeReferrer
{
private IModule _module;
private string _name;
private DisplayHint _displayHint;
private Status _status;
private string _description;
private string _reference;
private ITypeAssignment _syntax;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "module")]
public TextualConvention(IModule module, string name, ISymbolEnumerator symbols)
{
_module = module;
_name = name;
_displayHint = ParseDisplayHint(symbols);
_status = ParseStatus(symbols);
_description = ParseDescription(symbols);
_reference = ParseReference(symbols);
_syntax = ParseSyntax(module, symbols);
}
private static DisplayHint ParseDisplayHint(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.DisplayHint)
{
return new DisplayHint(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }));
}
symbols.PutBack(current);
return null;
}
private static Status ParseStatus(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.Status);
try
{
return (Status)Enum.Parse(typeof(Status), symbols.NextNonEOLSymbol().ToString());
}
catch (ArgumentException)
{
current.Assert(false, "Invalid/Unknown status");
}
return Status.current;
}
private static string ParseDescription(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.Description);
return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' });
}
private static string ParseReference(ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.Reference)
{
string reference = symbols.NextNonEOLSymbol().ToString();
if ((reference.Length >= 2) && reference.StartsWith("\"") && reference.EndsWith("\""))
{
return reference.Substring(1, reference.Length-2);
}
return reference;
}
symbols.PutBack(current);
return null;
}
private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
{
Symbol current = symbols.NextNonEOLSymbol();
current.Expect(Symbol.Syntax);
/*
* RFC2579 definition:
* Syntax ::= -- Must be one of the following:
* -- a base type (or its refinement), or
* -- a BITS pseudo-type
* type
* | "BITS" "{" NamedBits "}"
*
* From section 3.5:
* The data structure must be one of the alternatives defined
* in the ObjectSyntax CHOICE or the BITS construct. Note
* that this means that the SYNTAX clause of a Textual
* Convention can not refer to a previously defined Textual
* Convention.
*
* The SYNTAX clause of a TEXTUAL CONVENTION macro may be
* sub-typed in the same way as the SYNTAX clause of an
* OBJECT-TYPE macro.
*
* Therefore the possible values are (grouped by underlying type):
* INTEGER, Integer32
* OCTET STRING, Opaque
* OBJECT IDENTIFIER
* IpAddress
* Counter64
* Unsigned32, Counter32, Gauge32, TimeTicks
* BITS
* With appropriate sub-typing.
*/
return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true);
}
public IModule Module
{
get { return _module; }
}
public string Name
{
get { return _name; }
}
public string DisplayHint
{
get { return _displayHint == null ? null : _displayHint.ToString(); }
}
public Status Status
{
get { return _status; }
}
public string Description
{
get { return _description; }
}
public string Reference
{
get { return _reference; }
}
public ITypeAssignment Syntax
{
get { return _syntax; }
}
//internal object Decode(Variable v)
//{
// if (_syntax is IntegerType)
// {
// Integer32 i = v.Data as Integer32;
// if (i == null || (_syntax as IntegerType).IsEnumeration)
// {
// return null;
// }
// else if (_displayHint != null)
// {
// return _displayHint.Decode(i.ToInt32());
// }
// else
// {
// return i.ToInt32();
// }
// }
// else if (_syntax is UnsignedType)
// {
// Integer32 i = v.Data as Integer32;
// if (i == null)
// {
// return null;
// }
// else if (_displayHint != null)
// {
// return _displayHint.Decode(i.ToInt32());
// }
// else
// {
// return i.ToInt32();
// }
// }
// else if (_syntax is OctetStringType)
// {
// OctetString o = v.Data as OctetString;
// if (o == null)
// {
// return null;
// }
// else
// {
// // TODO: Follow the format specifier for octet strings.
// return null;
// }
// }
// else
// {
// return null;
// }
//}
#region ITypeReferrer Member
public ITypeAssignment ReferredType
{
get { return _syntax; }
set { _syntax = value; }
}
public ITypeAssignment BaseType
{
get
{
ITypeReferrer tr = this;
ITypeAssignment result = this;
while ((tr != null) && (tr.ReferredType != null))
{
result = tr.ReferredType;
tr = tr.ReferredType as ITypeReferrer;
}
return result;
}
}
#endregion
}
}

View File

@ -0,0 +1,147 @@
/*
* Created by SharpDevelop.
* User: lextm
* Date: 2008/5/18
* Time: 13:24
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/* Please be aware of the following possible constructs:
*
* isnsRegEntityIndex OBJECT-TYPE
* SYNTAX IsnsEntityIndexIdOrZero
* ( 1 .. 4294967295 )
* MAX-ACCESS not-accessible
*
*
*/
/// <summary/>
/// </summary>
public sealed class TypeAssignment : ITypeAssignment
{
private IModule _module;
private string _name;
private string _type;
private ValueRanges _ranges;
private ValueMap _map;
/// <summary>
/// Creates an <see cref="TypeAssignment" />.
/// </summary>
/// <param name="module">The module.</param>
/// <param name="name">The name.</param>
/// <param name="type">The type.</param>
/// <param name="symbols">The symbols.</param>
/// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
{
_module = module;
_name = name;
SymbolList typeSymbols = new SymbolList();
typeSymbols.Add(type);
Symbol current = symbols.NextSymbol();
while (current != Symbol.EOL)
{
if (current == Symbol.OpenParentheses)
{
// parse range of unknown type
symbols.PutBack(current);
_ranges = Lexer.DecodeRanges(symbols);
break;
}
else if (current == Symbol.OpenBracket)
{
symbols.PutBack(current);
_map = Lexer.DecodeEnumerations(symbols);
break;
}
typeSymbols.Add(current);
current = symbols.NextSymbol();
}
_type = typeSymbols.Join(" ");
if ((_ranges == null) && (_map == null))
{
current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenParentheses)
{
// parse range of unknown type
symbols.PutBack(current);
_ranges = Lexer.DecodeRanges(symbols);
}
else if (current == Symbol.OpenBracket)
{
symbols.PutBack(current);
_map = Lexer.DecodeEnumerations(symbols);
}
else if (current != null)
{
symbols.PutBack(current);
}
}
if (isMacroSyntax)
{
// inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
return;
}
// outside macro Syntax clause we wait for two consecutive linebreaks with a following valid identifier as end condition
Symbol previous = current;
Symbol veryPrevious = null;
while ((current = symbols.NextSymbol()) != null)
{
if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
{
symbols.PutBack(current);
return;
}
veryPrevious = previous;
previous = current;
}
previous.Assert(false, "end of file reached");
}
public string Type
{
get { return _type; }
}
public ValueRanges Ranges
{
get { return _ranges; }
}
public IDictionary<long, string> Map
{
get { return _map; }
}
#region ITypeAssignment Member
public IModule Module
{
get { return _module; }
}
public string Name
{
get { return _name; }
}
#endregion
}
}

View File

@ -0,0 +1,103 @@
using System.Collections.Generic;
namespace Lextm.SharpSnmpLib.Mib.Elements.Types
{
/**
* As this type is used for Counter32 and TimeTicks as well as Unsigned32
* and Gauge32 it incorrectly allows range restrictions of Counter32 and
* TimeTicks. This is ok as currently we do not care about detecting
* incorrect MIBs and this doesn't block the decoding of correct MIBs.
*/
public class UnsignedType : BaseType
{
public enum Types
{
Unsigned32,
Gauge32,
Counter32,
TimeTicks,
Counter64,
}
private Types _type;
private ValueRanges _ranges;
public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
: base(module, name)
{
Types? t = GetExactType(type);
type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
_type = t.Value;
Symbol current = symbols.NextNonEOLSymbol();
if (current == Symbol.OpenParentheses)
{
current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values
symbols.PutBack(current);
_ranges = Lexer.DecodeRanges(symbols);
current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
}
else
{
symbols.PutBack(current);
}
}
public Types Type
{
get { return _type; }
}
public ValueRanges Ranges
{
get { return _ranges; }
}
internal static Types? GetExactType(Symbol symbol)
{
if (symbol == Symbol.Unsigned32)
{
// [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
return Types.Unsigned32;
}
else if (symbol == Symbol.Gauge32)
{
// [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
return Types.Gauge32;
}
else if (symbol == Symbol.Counter32)
{
// [APPLICATION 1] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
return Types.Counter32;
}
else if (symbol == Symbol.TimeTicks)
{
// [APPLICATION 3] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI + RFC1155-SMI
return Types.TimeTicks;
}
else if (symbol == Symbol.Gauge)
{
// [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from RFC1155-SMI
return Types.Gauge32;
}
else if (symbol == Symbol.Counter)
{
// [APPLICATION 1] IMPLICIT INTEGER (0..4294967295) // from RFC1155-SMI
return Types.Counter32;
}
else if (symbol == Symbol.Counter64)
{
// [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615) // from SNMPv2-SMI
return Types.Counter64;
}
return null;
}
internal static bool IsUnsignedType(Symbol symbol)
{
return GetExactType(symbol).HasValue;
}
}
}