<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.opencircuits.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thai</id>
	<title>OpenCircuits - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.opencircuits.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thai"/>
	<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=Special:Contributions/Thai"/>
	<updated>2026-07-05T19:46:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20875</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20875"/>
		<updated>2011-05-03T18:19:59Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Example SNMP PDU */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;}, {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
* If &amp;lt;sub_oid&amp;gt; == BYTE (0x00) and &amp;lt;info_sub_oid&amp;gt; == BYTE(0xFF), this is the end of infomation traps.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of &amp;lt;name&amp;gt;.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
                              |&amp;lt;--------------------Length--------------------&amp;gt;|&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMP PDU Format===&lt;br /&gt;
* SNMP PDU is is reference to SNMP version 1 (SNMPv1) PDU. &lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
* GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format is shown here.&lt;br /&gt;
   +-------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                               SNMPv1 PDU (GetRequest, GetNextRequest, GetResponse, SetRequest                                       |&lt;br /&gt;
   +------+--------+---------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length |                                             Data of SNMP PDU                                                        |&lt;br /&gt;
   | type |  Data  |                                                                                                                     |&lt;br /&gt;
   +------+--------+---------+---------+---------+---------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length | Request | Error   | Error   |                             VarBind List (Sequence)                                   |&lt;br /&gt;
   | type |  PDU   |   ID    | Status  | Index   +------+--------+--------------------------------+--------------------------------+-----+&lt;br /&gt;
   |      |        |         |         |         | 0x30 | Length |           Varbind 1            |           Varbind 2            | ... |&lt;br /&gt;
   |      |        |(Integer)|(Integer)|(Integer)|      |        |          (Sequence)            |          (Sequence)            | ... | &lt;br /&gt;
   |      |        |         |         |         |      |        +------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
   |      |        |         |         |         |      |        | 0x30 | Len 1 | OID 1 | Value 1 | 0x30 | Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +------+--------+---------+---------+---------+------+--------+------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
                   |                                             |              |&amp;lt;-----Len 1-----&amp;gt;|              |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                   |                                             |&amp;lt;-------------------------------Length--------------------------------&amp;gt;|&lt;br /&gt;
                   |&amp;lt;----------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;| &lt;br /&gt;
* PDU Type is specific type of PDU, PDU Type is a single byte identifier.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field.&lt;br /&gt;
* Data of SNMP PDU is data content in SNMP PDU.&lt;br /&gt;
* Request ID is an Integer that identifies a particular SNMP request. This index is echoed back in the response from the SNMP agent, allowing the SNMP manager to match an incoming response to the appropriate request.&lt;br /&gt;
* Error Status is an Integer set to 0x00 in the request sent by the NMS. The SNMP agent places an error code in this field in the response message if an error occurred processing the request.&lt;br /&gt;
   Some error codes include:&lt;br /&gt;
   +-------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |    Error Status   |                                                                           |&lt;br /&gt;
   +------------+------+                                Description                                |&lt;br /&gt;
   |    Name    | Code |                                                                           |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | noError    | 0x00 | No error occurred.                                                        |&lt;br /&gt;
   | tooBig     | 0x01 | The response to your request was too big to fit into one response.        |&lt;br /&gt;
   | noSuchName | 0x02 | The OID in the request was not found.the OID doesn't exist.               |&lt;br /&gt;
   | badValue   | 0x03 | A data type in the request did not match the data type in the SNMP agent. |&lt;br /&gt;
   | readOnly   | 0x04 | The SNMP manager attempted to set a read-only parameter.                  |&lt;br /&gt;
   | genErr     | 0x05 | General Error (some error other than the ones listed above).              |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID.&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   |    SNMP PDU type   |                            Value                                |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   | SetRequest PDU     | Value is applied to the specified OID of the SNMP agent.        |&lt;br /&gt;
   | GetRequest PDU     | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetNextRequest PDU | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
====[http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch10_03.htm= Trap PDU Format]====&lt;br /&gt;
* The format of the Trap PDU is shown below:&lt;br /&gt;
   +------------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                                                         TRAP SNMPv1 PDU                                                                  |&lt;br /&gt;
   +----+------+------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |PDU |Length|                                             Data of SNMP PDU                                                                 |&lt;br /&gt;
   |type| Data |                                                                                                                              |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+---------------------------------------------------- ------------------------------+&lt;br /&gt;
   |0xA4|Length|Enterprise| Agent |Generic|Specific|Time  |                                VarBind List (Sequence)                            |&lt;br /&gt;
   |    | PDU  |   OID    |Address| Trap  |  Trap  |Stamp +------+--------+------------------------------+------------------------------+-----+&lt;br /&gt;
   |    |      |          |       | Type  | Number |      | 0x30 | Length |           Varbind 1          |         Varbind 22           | ... |&lt;br /&gt;
   |    |      |  (OID)   |       |       |        |      |      |        |          (Sequence)          |         (Sequence)           | ... |&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        +----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        |0x30| Len 1 | OID 1 | Value 1 |0x30| Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+------+--------+----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
                          |                                               |            |&amp;lt;-----Len 1-----&amp;gt;|            |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                          |                                               |&amp;lt;-----------------------------Length------------------------------&amp;gt;|&lt;br /&gt;
                          |&amp;lt;--------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;|&lt;br /&gt;
* PDU type is TRAP PDU = 0xA4.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field. &lt;br /&gt;
* Enterprise OID identifies the type of managed object generating the trap. &lt;br /&gt;
* Agent Address is the IP address of the agent that is sending the trap. &lt;br /&gt;
* [http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch02_06.htm#enettdg-CHP-2-TABLE-8= Generic Trap Type] indicates one of a number of generic trap types.&lt;br /&gt;
   Generic Trap Type has seven values are defined: &lt;br /&gt;
   +------------------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |       Generic Trap Type      |                                                                           |&lt;br /&gt;
   +-----------------------+------+                                Description                                |&lt;br /&gt;
   |         Name          | Code |                                                                           |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | coldStart             | 0x00 | Indicates that the agent has rebooted. All management variables will be   |&lt;br /&gt;
   |                       |      | reset; specifically, Counters and Gauges will be reset to zero (0).       |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | warmStart             | 0x01 | Indicates that the agent has reinitialized itself. None of the management |&lt;br /&gt;
   |                       |      | variables will be reset.                                                  |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkDown              | 0x02 | Sent when an interface on a device goes down. The first variable binding  |&lt;br /&gt;
   |                       |      | identifies which interface went down.                                     |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkUp                | 0x03 | Sent when an interface on a device comes back up. The first variable      | &lt;br /&gt;
   |                       |      | binding identifies which interface came back up.                          |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | authenticationFailure | 0x04 | Indicates that someone has tried to query your agent with an incorrect    |&lt;br /&gt;
   |                       |      | community string; useful in determining if someone is trying to gain      |&lt;br /&gt;
   |                       |      | unauthorized access to one of your devices.                               |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | egpNeighborLoss       | 0x05 | Indicates that an Exterior Gateway Protocol (EGP) neighbor has gone down. |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | enterpriseSpecific    | 0x06 | Indicates that the trap is enterprise-specific. SNMP vendors and users    |&lt;br /&gt;
   |                       |      | define their own traps under the private-enterprise branch of the SMI     |&lt;br /&gt;
   |                       |      | object tree. To process this trap properly, the NMS has to decode the     |&lt;br /&gt;
   |                       |      | specific trap number that is part of the SNMP message.                    |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Specific trap number is a number indicating the specific trap you want to send. If you're sending a generic trap, this parameter is ignored -- you're probably better off setting it to zero.&lt;br /&gt;
* Time stamp is the time elapsed between the last initialization of the network entity and the generation of the trap.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds to be included in the trap.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID&lt;br /&gt;
===Example SNMP Message===&lt;br /&gt;
====GetRequest PDU====&lt;br /&gt;
* The example gets the value of name agent with above MIB file.&lt;br /&gt;
* Community String is &amp;quot;public&amp;quot;&lt;br /&gt;
   +---------+-----------+------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | SNMP    | Type      |                                               0x30                                                   |&lt;br /&gt;
   | message +-----------+------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |         |Length     |                                               0x2B                                                   |&lt;br /&gt;
   |         +-----------+------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |         | Version   |                                               0x02                                                   |&lt;br /&gt;
   |         |           |                                               0x01                                                   |&lt;br /&gt;
   |         |           |                                               0x00                                                   |&lt;br /&gt;
   |         +-----------+------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |         | Community |                                               0x04                                                   |&lt;br /&gt;
   |         |           |                                               0x06                                                   |&lt;br /&gt;
   |         |           |                                               0x70 0x75 0x62 0x6C 0x69 0x63                          |&lt;br /&gt;
   |         +-----------+ -------+--------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         | Data      | SNMPv1 | PDU type     |                       0xA0                                                   |&lt;br /&gt;
   |         |           | PDU    +--------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        | PDU length   |                       0x1E                                                   |&lt;br /&gt;
   |         |           |        + -------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        | Request ID   |                       0x02                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x04                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x37 0x9C 0x57 0x89                                    |&lt;br /&gt;
   |         |           |        + -------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        | Error Status |                       0x02                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x01                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x00                                                   |&lt;br /&gt;
   |         |           |        + -------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        | Error Index  |                       0x02                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x01                                                   |&lt;br /&gt;
   |         |           |        |              |                       0x00                                                   |&lt;br /&gt;
   |         |           |        + -------------+------------------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        | VarBind List |                       0x30                                                   |&lt;br /&gt;
   |         |           |        |              +-----------+------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        |              | Length    |           0x10                                                   |&lt;br /&gt;
   |         |           |        |              +-----------+------------------------------------------------------------------+&lt;br /&gt;
   |         |           |        |              | VarBind 1 |           0x30                                                   |&lt;br /&gt;
   |         |           |        |              |           +---------+--------------------------------------------------------+&lt;br /&gt;
   |         |           |        |              |           | Len 1   | 0x0E                                                   |&lt;br /&gt;
   |         |           |        |              |           +---------+--------------------------------------------------------+&lt;br /&gt;
   |         |           |        |              |           | OID 1   | 0x06                                                   |&lt;br /&gt;
   |         |           |        |              |           |         | 0x0A                                                   |&lt;br /&gt;
   |         |           |        |              |           |         | 0x2B 0x06 0x01 0x04 0x01 0x82 0x99 0x5D 0x02           |&lt;br /&gt;
   |         |           |        |              |           +---------+--------------------------------------------------------+&lt;br /&gt;
   |         |           |        |              |           | Value 1 | 0x05                                                   |&lt;br /&gt;
   |         |           |        |              |           |         | 0x00                                                   |&lt;br /&gt;
   +---------+-----------+--------+--------------+-----------+---------+--------------------------------------------------------+&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20873</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20873"/>
		<updated>2011-05-03T17:35:07Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP's PDU using BER */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;}, {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
* If &amp;lt;sub_oid&amp;gt; == BYTE (0x00) and &amp;lt;info_sub_oid&amp;gt; == BYTE(0xFF), this is the end of infomation traps.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of &amp;lt;name&amp;gt;.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
                              |&amp;lt;--------------------Length--------------------&amp;gt;|&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMP PDU Format===&lt;br /&gt;
* SNMP PDU is is reference to SNMP version 1 (SNMPv1) PDU. &lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
* GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format is shown here.&lt;br /&gt;
   +-------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                               SNMPv1 PDU (GetRequest, GetNextRequest, GetResponse, SetRequest                                       |&lt;br /&gt;
   +------+--------+---------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length |                                             Data of SNMP PDU                                                        |&lt;br /&gt;
   | type |  Data  |                                                                                                                     |&lt;br /&gt;
   +------+--------+---------+---------+---------+---------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length | Request | Error   | Error   |                             VarBind List (Sequence)                                   |&lt;br /&gt;
   | type |  PDU   |   ID    | Status  | Index   +------+--------+--------------------------------+--------------------------------+-----+&lt;br /&gt;
   |      |        |         |         |         | 0x30 | Length |           Varbind 1            |           Varbind 2            | ... |&lt;br /&gt;
   |      |        |(Integer)|(Integer)|(Integer)|      |        |          (Sequence)            |          (Sequence)            | ... | &lt;br /&gt;
   |      |        |         |         |         |      |        +------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
   |      |        |         |         |         |      |        | 0x30 | Len 1 | OID 1 | Value 1 | 0x30 | Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +------+--------+---------+---------+---------+------+--------+------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
                   |                                             |              |&amp;lt;-----Len 1-----&amp;gt;|              |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                   |                                             |&amp;lt;-------------------------------Length--------------------------------&amp;gt;|&lt;br /&gt;
                   |&amp;lt;----------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;| &lt;br /&gt;
* PDU Type is specific type of PDU, PDU Type is a single byte identifier.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field.&lt;br /&gt;
* Data of SNMP PDU is data content in SNMP PDU.&lt;br /&gt;
* Request ID is an Integer that identifies a particular SNMP request. This index is echoed back in the response from the SNMP agent, allowing the SNMP manager to match an incoming response to the appropriate request.&lt;br /&gt;
* Error Status is an Integer set to 0x00 in the request sent by the NMS. The SNMP agent places an error code in this field in the response message if an error occurred processing the request.&lt;br /&gt;
   Some error codes include:&lt;br /&gt;
   +-------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |    Error Status   |                                                                           |&lt;br /&gt;
   +------------+------+                                Description                                |&lt;br /&gt;
   |    Name    | Code |                                                                           |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | noError    | 0x00 | No error occurred.                                                        |&lt;br /&gt;
   | tooBig     | 0x01 | The response to your request was too big to fit into one response.        |&lt;br /&gt;
   | noSuchName | 0x02 | The OID in the request was not found.the OID doesn't exist.               |&lt;br /&gt;
   | badValue   | 0x03 | A data type in the request did not match the data type in the SNMP agent. |&lt;br /&gt;
   | readOnly   | 0x04 | The SNMP manager attempted to set a read-only parameter.                  |&lt;br /&gt;
   | genErr     | 0x05 | General Error (some error other than the ones listed above).              |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID.&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   |    SNMP PDU type   |                            Value                                |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   | SetRequest PDU     | Value is applied to the specified OID of the SNMP agent.        |&lt;br /&gt;
   | GetRequest PDU     | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetNextRequest PDU | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
====[http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch10_03.htm= Trap PDU Format]====&lt;br /&gt;
* The format of the Trap PDU is shown below:&lt;br /&gt;
   +------------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                                                         TRAP SNMPv1 PDU                                                                  |&lt;br /&gt;
   +----+------+------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |PDU |Length|                                             Data of SNMP PDU                                                                 |&lt;br /&gt;
   |type| Data |                                                                                                                              |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+---------------------------------------------------- ------------------------------+&lt;br /&gt;
   |0xA4|Length|Enterprise| Agent |Generic|Specific|Time  |                                VarBind List (Sequence)                            |&lt;br /&gt;
   |    | PDU  |   OID    |Address| Trap  |  Trap  |Stamp +------+--------+------------------------------+------------------------------+-----+&lt;br /&gt;
   |    |      |          |       | Type  | Number |      | 0x30 | Length |           Varbind 1          |         Varbind 22           | ... |&lt;br /&gt;
   |    |      |  (OID)   |       |       |        |      |      |        |          (Sequence)          |         (Sequence)           | ... |&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        +----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        |0x30| Len 1 | OID 1 | Value 1 |0x30| Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+------+--------+----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
                          |                                               |            |&amp;lt;-----Len 1-----&amp;gt;|            |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                          |                                               |&amp;lt;-----------------------------Length------------------------------&amp;gt;|&lt;br /&gt;
                          |&amp;lt;--------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;|&lt;br /&gt;
* PDU type is TRAP PDU = 0xA4.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field. &lt;br /&gt;
* Enterprise OID identifies the type of managed object generating the trap. &lt;br /&gt;
* Agent Address is the IP address of the agent that is sending the trap. &lt;br /&gt;
* [http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch02_06.htm#enettdg-CHP-2-TABLE-8= Generic Trap Type] indicates one of a number of generic trap types.&lt;br /&gt;
   Generic Trap Type has seven values are defined: &lt;br /&gt;
   +------------------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |       Generic Trap Type      |                                                                           |&lt;br /&gt;
   +-----------------------+------+                                Description                                |&lt;br /&gt;
   |         Name          | Code |                                                                           |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | coldStart             | 0x00 | Indicates that the agent has rebooted. All management variables will be   |&lt;br /&gt;
   |                       |      | reset; specifically, Counters and Gauges will be reset to zero (0).       |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | warmStart             | 0x01 | Indicates that the agent has reinitialized itself. None of the management |&lt;br /&gt;
   |                       |      | variables will be reset.                                                  |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkDown              | 0x02 | Sent when an interface on a device goes down. The first variable binding  |&lt;br /&gt;
   |                       |      | identifies which interface went down.                                     |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkUp                | 0x03 | Sent when an interface on a device comes back up. The first variable      | &lt;br /&gt;
   |                       |      | binding identifies which interface came back up.                          |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | authenticationFailure | 0x04 | Indicates that someone has tried to query your agent with an incorrect    |&lt;br /&gt;
   |                       |      | community string; useful in determining if someone is trying to gain      |&lt;br /&gt;
   |                       |      | unauthorized access to one of your devices.                               |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | egpNeighborLoss       | 0x05 | Indicates that an Exterior Gateway Protocol (EGP) neighbor has gone down. |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | enterpriseSpecific    | 0x06 | Indicates that the trap is enterprise-specific. SNMP vendors and users    |&lt;br /&gt;
   |                       |      | define their own traps under the private-enterprise branch of the SMI     |&lt;br /&gt;
   |                       |      | object tree. To process this trap properly, the NMS has to decode the     |&lt;br /&gt;
   |                       |      | specific trap number that is part of the SNMP message.                    |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Specific trap number is a number indicating the specific trap you want to send. If you're sending a generic trap, this parameter is ignored -- you're probably better off setting it to zero.&lt;br /&gt;
* Time stamp is the time elapsed between the last initialization of the network entity and the generation of the trap.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds to be included in the trap.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID&lt;br /&gt;
===Example SNMP PDU===&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20872</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20872"/>
		<updated>2011-05-03T17:22:58Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP PDU Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
                              |&amp;lt;--------------------Length--------------------&amp;gt;|&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMP PDU Format===&lt;br /&gt;
* SNMP PDU is is reference to SNMP version 1 (SNMPv1) PDU. &lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
* GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format is shown here.&lt;br /&gt;
   +-------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                               SNMPv1 PDU (GetRequest, GetNextRequest, GetResponse, SetRequest                                       |&lt;br /&gt;
   +------+--------+---------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length |                                             Data of SNMP PDU                                                        |&lt;br /&gt;
   | type |  Data  |                                                                                                                     |&lt;br /&gt;
   +------+--------+---------+---------+---------+---------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length | Request | Error   | Error   |                             VarBind List (Sequence)                                   |&lt;br /&gt;
   | type |  PDU   |   ID    | Status  | Index   +------+--------+--------------------------------+--------------------------------+-----+&lt;br /&gt;
   |      |        |         |         |         | 0x30 | Length |           Varbind 1            |           Varbind 2            | ... |&lt;br /&gt;
   |      |        |(Integer)|(Integer)|(Integer)|      |        |          (Sequence)            |          (Sequence)            | ... | &lt;br /&gt;
   |      |        |         |         |         |      |        +------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
   |      |        |         |         |         |      |        | 0x30 | Len 1 | OID 1 | Value 1 | 0x30 | Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +------+--------+---------+---------+---------+------+--------+------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
                   |                                             |              |&amp;lt;-----Len 1-----&amp;gt;|              |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                   |                                             |&amp;lt;-------------------------------Length--------------------------------&amp;gt;|&lt;br /&gt;
                   |&amp;lt;----------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;| &lt;br /&gt;
* PDU Type is specific type of PDU, PDU Type is a single byte identifier.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field.&lt;br /&gt;
* Data of SNMP PDU is data content in SNMP PDU.&lt;br /&gt;
* Request ID is an Integer that identifies a particular SNMP request. This index is echoed back in the response from the SNMP agent, allowing the SNMP manager to match an incoming response to the appropriate request.&lt;br /&gt;
* Error Status is an Integer set to 0x00 in the request sent by the NMS. The SNMP agent places an error code in this field in the response message if an error occurred processing the request.&lt;br /&gt;
   Some error codes include:&lt;br /&gt;
   +-------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |    Error Status   |                                                                           |&lt;br /&gt;
   +------------+------+                                Description                                |&lt;br /&gt;
   |    Name    | Code |                                                                           |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | noError    | 0x00 | No error occurred.                                                        |&lt;br /&gt;
   | tooBig     | 0x01 | The response to your request was too big to fit into one response.        |&lt;br /&gt;
   | noSuchName | 0x02 | The OID in the request was not found.the OID doesn't exist.               |&lt;br /&gt;
   | badValue   | 0x03 | A data type in the request did not match the data type in the SNMP agent. |&lt;br /&gt;
   | readOnly   | 0x04 | The SNMP manager attempted to set a read-only parameter.                  |&lt;br /&gt;
   | genErr     | 0x05 | General Error (some error other than the ones listed above).              |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID.&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   |    SNMP PDU type   |                            Value                                |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   | SetRequest PDU     | Value is applied to the specified OID of the SNMP agent.        |&lt;br /&gt;
   | GetRequest PDU     | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetNextRequest PDU | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
====[http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch10_03.htm= Trap PDU Format]====&lt;br /&gt;
* The format of the Trap PDU is shown below:&lt;br /&gt;
   +------------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                                                         TRAP SNMPv1 PDU                                                                  |&lt;br /&gt;
   +----+------+------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |PDU |Length|                                             Data of SNMP PDU                                                                 |&lt;br /&gt;
   |type| Data |                                                                                                                              |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+---------------------------------------------------- ------------------------------+&lt;br /&gt;
   |0xA4|Length|Enterprise| Agent |Generic|Specific|Time  |                                VarBind List (Sequence)                            |&lt;br /&gt;
   |    | PDU  |   OID    |Address| Trap  |  Trap  |Stamp +------+--------+------------------------------+------------------------------+-----+&lt;br /&gt;
   |    |      |          |       | Type  | Number |      | 0x30 | Length |           Varbind 1          |         Varbind 22           | ... |&lt;br /&gt;
   |    |      |  (OID)   |       |       |        |      |      |        |          (Sequence)          |         (Sequence)           | ... |&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        +----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
   |    |      |          |       |       |        |      |      |        |0x30| Len 1 | OID 1 | Value 1 |0x30| Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +----+------+----------+-------+-------+--------+------+------+--------+----+-------+-------+---------+----+-------+-------+---------+-----+&lt;br /&gt;
                          |                                               |            |&amp;lt;-----Len 1-----&amp;gt;|            |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                          |                                               |&amp;lt;-----------------------------Length------------------------------&amp;gt;|&lt;br /&gt;
                          |&amp;lt;--------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;|&lt;br /&gt;
* PDU type is TRAP PDU = 0xA4.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field. &lt;br /&gt;
* Enterprise OID identifies the type of managed object generating the trap. &lt;br /&gt;
* Agent Address is the IP address of the agent that is sending the trap. &lt;br /&gt;
* [http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch02_06.htm#enettdg-CHP-2-TABLE-8= Generic Trap Type] indicates one of a number of generic trap types.&lt;br /&gt;
   Generic Trap Type has seven values are defined: &lt;br /&gt;
   +------------------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |       Generic Trap Type      |                                                                           |&lt;br /&gt;
   +-----------------------+------+                                Description                                |&lt;br /&gt;
   |         Name          | Code |                                                                           |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | coldStart             | 0x00 | Indicates that the agent has rebooted. All management variables will be   |&lt;br /&gt;
   |                       |      | reset; specifically, Counters and Gauges will be reset to zero (0).       |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | warmStart             | 0x01 | Indicates that the agent has reinitialized itself. None of the management |&lt;br /&gt;
   |                       |      | variables will be reset.                                                  |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkDown              | 0x02 | Sent when an interface on a device goes down. The first variable binding  |&lt;br /&gt;
   |                       |      | identifies which interface went down.                                     |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | linkUp                | 0x03 | Sent when an interface on a device comes back up. The first variable      | &lt;br /&gt;
   |                       |      | binding identifies which interface came back up.                          |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | authenticationFailure | 0x04 | Indicates that someone has tried to query your agent with an incorrect    |&lt;br /&gt;
   |                       |      | community string; useful in determining if someone is trying to gain      |&lt;br /&gt;
   |                       |      | unauthorized access to one of your devices.                               |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | egpNeighborLoss       | 0x05 | Indicates that an Exterior Gateway Protocol (EGP) neighbor has gone down. |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | enterpriseSpecific    | 0x06 | Indicates that the trap is enterprise-specific. SNMP vendors and users    |&lt;br /&gt;
   |                       |      | define their own traps under the private-enterprise branch of the SMI     |&lt;br /&gt;
   |                       |      | object tree. To process this trap properly, the NMS has to decode the     |&lt;br /&gt;
   |                       |      | specific trap number that is part of the SNMP message.                    |&lt;br /&gt;
   +-----------------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Specific trap number is a number indicating the specific trap you want to send. If you're sending a generic trap, this parameter is ignored -- you're probably better off setting it to zero.&lt;br /&gt;
* Time stamp is the time elapsed between the last initialization of the network entity and the generation of the trap.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds to be included in the trap.&lt;br /&gt;
** Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
*** Value is the value of OID&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20870</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20870"/>
		<updated>2011-05-03T16:28:40Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMPv1 PDU Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
                              |&amp;lt;--------------------Length--------------------&amp;gt;|&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMP PDU Format===&lt;br /&gt;
* SNMP PDU is is reference to SNMP version 1 (SNMPv1) PDU. &lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
* GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format is shown here.&lt;br /&gt;
   +-------------------------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   |                               SNMPv1 PDU (GetRequest, GetNextRequest, GetResponse, SetRequest                                       |&lt;br /&gt;
   +------+--------+---------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length |                                             Data of SNMP PDU                                                        |&lt;br /&gt;
   | type |  Data  |                                                                                                                     |&lt;br /&gt;
   +------+--------+---------------------------------------------------------------------------------------------------------------------+&lt;br /&gt;
   | PDU  | Length | Request | Error   | Error   |                             VarBind List (Sequence)                                   |&lt;br /&gt;
   | type |  PDU   |   ID    | Status  | Index   +------+--------+--------------------------------+--------------------------------+-----+&lt;br /&gt;
   |      |        |         |         |         | 0x30 | Length |           Varbind 1            |           Varbind 2            | ... |&lt;br /&gt;
   |      |        |(Integer)|(Integer)|(Integer)|      |        |          (Sequence)            |          (Sequence)            | ... | &lt;br /&gt;
   |      |        |         |         |         |      |        +------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
   |      |        |         |         |         |      |        | 0x30 | Len 1 | OID 1 | Value 1 | 0x30 | Len 2 | OID 1 | Value 2 | ... |&lt;br /&gt;
   +------+--------+---------+---------+---------+------+--------+------+-------+-------+---------+------+-------+-------+---------+-----+&lt;br /&gt;
                   |                                             |              |&amp;lt;-----Len 1-----&amp;gt;|              |&amp;lt;-----Len 2-----&amp;gt;|     |&lt;br /&gt;
                   |                                             |&amp;lt;-------------------------------Length--------------------------------&amp;gt;|&lt;br /&gt;
                   |&amp;lt;----------------------------------------------Lenght PDU-----------------------------------------------------------&amp;gt;| &lt;br /&gt;
* PDU Type is specific type of PDU, PDU Type is a single byte identifier.&lt;br /&gt;
* Length Data is a number bytes of Data of SNMP PDU field.&lt;br /&gt;
* Data of SNMP PDU is data content in SNMP PDU.&lt;br /&gt;
* Request ID is an Integer that identifies a particular SNMP request. This index is echoed back in the response from the SNMP agent, allowing the SNMP manager to match an incoming response to the appropriate request.&lt;br /&gt;
* Error Status is an Integer set to 0x00 in the request sent by the NMS. The SNMP agent places an error code in this field in the response message if an error occurred processing the request.&lt;br /&gt;
   Some error codes include:&lt;br /&gt;
   +-------------------+---------------------------------------------------------------------------+&lt;br /&gt;
   |    Error Status   |                                                                           |&lt;br /&gt;
   +------------+------+                                Description                                |&lt;br /&gt;
   |    Name    | Code |                                                                           |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
   | noError    | 0x00 | No error occurred.                                                        |&lt;br /&gt;
   | tooBig     | 0x01 | The response to your request was too big to fit into one response.        |&lt;br /&gt;
   | noSuchName | 0x02 | The OID in the request was not found.the OID doesn't exist.               |&lt;br /&gt;
   | badValue   | 0x03 | A data type in the request did not match the data type in the SNMP agent. |&lt;br /&gt;
   | readOnly   | 0x04 | The SNMP manager attempted to set a read-only parameter.                  |&lt;br /&gt;
   | genErr     | 0x05 | General Error (some error other than the ones listed above).              |&lt;br /&gt;
   +------------+------+---------------------------------------------------------------------------+&lt;br /&gt;
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.&lt;br /&gt;
* Varbind List is a Sequence of Varbinds.&lt;br /&gt;
* Varbind is a Sequence of two fields, an OID and the value of OID.&lt;br /&gt;
* OID is an Object Identifier that points to a particular parameter in the SNMP agent.&lt;br /&gt;
* Value is the value of OID.&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   |    SNMP PDU type   |                            Value                                |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
   | SetRequest PDU     | Value is applied to the specified OID of the SNMP agent.        |&lt;br /&gt;
   | GetRequest PDU     | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetNextRequest PDU | Value is a Null that acts as a placeholder for the return data. |&lt;br /&gt;
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |&lt;br /&gt;
   +--------------------+-----------------------------------------------------------------+&lt;br /&gt;
====Trap PDU Format====&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20869</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20869"/>
		<updated>2011-05-03T15:31:12Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP Message Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
                              |&amp;lt;--------------------Length--------------------&amp;gt;|&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMPv1 PDU Format===&lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
====Trap PDU Format====&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20868</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20868"/>
		<updated>2011-05-03T15:20:24Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP Message Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+----------------+------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMPv1 PDU Format===&lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
====Trap PDU Format====&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20867</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20867"/>
		<updated>2011-05-03T15:09:29Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP Message Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+-----------------------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMPv1 PDU Format===&lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
====Trap PDU Format====&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20866</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20866"/>
		<updated>2011-05-03T15:08:44Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Build SNMP's PDU using BER */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[http://www.rane.com/note161.html=Build SNMP's PDU using BER]==&lt;br /&gt;
* SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU. &lt;br /&gt;
* The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.&lt;br /&gt;
* SNMPv1 PDU have five different PDU types:GetRequest,  GetNextRequest, GetResponse, SetRequest and Trap.&lt;br /&gt;
* Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.&lt;br /&gt;
===ASN.1 data types===&lt;br /&gt;
* ASN.1 data types fall into two categories: primitive and complex.&lt;br /&gt;
* ASN.1 data types is used to build SNMP messages.&lt;br /&gt;
** ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.&lt;br /&gt;
** ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.&lt;br /&gt;
&lt;br /&gt;
===[http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBgQFjAA&amp;amp;url=http%3A%2F%2Fwww.itu.int%2FITU-T%2Fstudygroups%2Fcom17%2Flanguages%2FX.690-0207.pdf&amp;amp;rct=j&amp;amp;q=x.690-0207&amp;amp;ei=cde_TcrvJouMvQOm5-jABA&amp;amp;usg=AFQjCNGYmD4USBwcWoeHoRFZ3zdP39kosw&amp;amp;cad=rja=Basic Encoding Rules (BER)]===&lt;br /&gt;
* BER has three parts: Type, Length and Data field.&lt;br /&gt;
   BER format: &lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
      | Type | Length | Data |&lt;br /&gt;
      +------+--------+------+&lt;br /&gt;
&lt;br /&gt;
* Type field is single byte identifier.&lt;br /&gt;
   '''Constructing byte Data type.'''&lt;br /&gt;
   Format of byte Data type&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
      |  | |     +&lt;br /&gt;
      +--+-+-----+&lt;br /&gt;
       2  1   5&lt;br /&gt;
   Bits 8 and 7 shall be encoded to represent the class of Data type follow table:&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      |      Class       | Bit 8 | Bit 7 |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
      | Universal        |   0   |   0   |&lt;br /&gt;
      | Application      |   0   |   1   |&lt;br /&gt;
      | Context-specific |   1   |   0   |&lt;br /&gt;
      | Private          |   1   |   1   |&lt;br /&gt;
      +------------------+-------+-------+&lt;br /&gt;
   Bit 6 is encoded data is Primitive or Constructed follow table:&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      | Bit 6 |   Type      |&lt;br /&gt;
      +-------+-------------+&lt;br /&gt;
      |   0   | Primitive   |&lt;br /&gt;
      |   1   | Constructed |&lt;br /&gt;
      +-------+-------------+ &lt;br /&gt;
   Bits 5 to 1 encode the number of Data type as a integer number.     &lt;br /&gt;
&lt;br /&gt;
   '''Data type identifier in SNMP'''&lt;br /&gt;
      '''Data type'''                 '''Identifier'''      '''Note'''&lt;br /&gt;
      Integer                      0x02         Primitive ASN.1 types&lt;br /&gt;
      Octet String                 0x04         Primitive ASN.1 types  &lt;br /&gt;
      Null                         0x05         Primitive ASN.1 types&lt;br /&gt;
      Object identifier            0x06         Primitive ASN.1 types&lt;br /&gt;
      Sequence                     0x30         Constructed ASN.1 types&lt;br /&gt;
      IpAddress                    0x40         Primitive SNMP application types&lt;br /&gt;
      Counter                      0x41         Primitive SNMP application types&lt;br /&gt;
      Gauge                        0x42         Primitive SNMP application types&lt;br /&gt;
      TimeTicks                    0x43         Primitive SNMP application types &lt;br /&gt;
      Opaque                       0x44         Primitive SNMP application types&lt;br /&gt;
      NsapAddress                  0x45         Primitive SNMP application types&lt;br /&gt;
      GetRequest PDU               0xA0         Context-specific Constructed SNMP types&lt;br /&gt;
      GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types&lt;br /&gt;
      GetResponse PDU              0xA2         Context-specific Constructed SNMP types&lt;br /&gt;
      SetRequest PDU               0xA3         Context-specific Constructed SNMP types&lt;br /&gt;
      Trap PDU                     0xA4         Context-specific Constructed SNMP types&lt;br /&gt;
* Length field is the number of bytes in Data field.&lt;br /&gt;
** Length field is used either the short form or the long form as a option depend on Data field.&lt;br /&gt;
*** The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
*** The long form, Length field shall consists of an initial octet and  one or more subsequent octets.&lt;br /&gt;
**** The initial octet is encoded as follows:&lt;br /&gt;
***** Bit 8 shall be one.&lt;br /&gt;
***** Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.&lt;br /&gt;
***** The value 0xFF shall not be used.&lt;br /&gt;
**** Subsequent octets:&lt;br /&gt;
***** From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.&lt;br /&gt;
* Data field is actual data content.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
   Actual Data is an integer, the value 100 can be encode as:&lt;br /&gt;
   The short form:&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | Type | Length | Data  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
      | 0x02 |  0x01  | 0x64  |&lt;br /&gt;
      +------+--------+-------+&lt;br /&gt;
   The long form:&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | Type |  Length   | Data  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
      | 0x02 | 0x81 0x01 | 0x64  |&lt;br /&gt;
      +------+-----------+-------+&lt;br /&gt;
===SNMP Message Format===&lt;br /&gt;
* SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.&lt;br /&gt;
   SNMP Message Format use BER.&lt;br /&gt;
      +------------------------------------------------------------------------+&lt;br /&gt;
      |                      SNMP Message (Sequence type)                      |&lt;br /&gt;
      +------+-----------------------------------------------------------------+&lt;br /&gt;
      | Type | Length of Data |                      Data                      |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
      | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      &lt;br /&gt;
      |      |                |  (Integer)  |    (Octet String)     |          |&lt;br /&gt;
      +------+----------------+-------------+-----------------------+----------+&lt;br /&gt;
* Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).&lt;br /&gt;
* SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.&lt;br /&gt;
* SNMP Community String is an Octet String to add security to Agents.&lt;br /&gt;
* SNMP PDU is SNMP verion 1 (SNMPv1) PDU.&lt;br /&gt;
&lt;br /&gt;
===SNMPv1 PDU Format===&lt;br /&gt;
====GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format====&lt;br /&gt;
====Trap PDU Format====&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_trap_example.jpg&amp;diff=20852</id>
		<title>File:Snmp mib binary trap example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_trap_example.jpg&amp;diff=20852"/>
		<updated>2011-05-03T06:49:08Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary trap example.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=20851</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=20851"/>
		<updated>2011-05-03T06:44:37Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=20850</id>
		<title>File:Snmp mib binary example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=20850"/>
		<updated>2011-05-03T06:43:14Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary example.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20837</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20837"/>
		<updated>2011-05-02T17:40:38Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Binary File .bin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;}, {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
* If &amp;lt;sub_oid&amp;gt; == BYTE (0x00) and &amp;lt;info_sub_oid&amp;gt; == BYTE(0xFF), this is the end of infomation traps.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of &amp;lt;name&amp;gt;.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_trap_example.jpg&amp;diff=20836</id>
		<title>File:Snmp mib binary trap example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_trap_example.jpg&amp;diff=20836"/>
		<updated>2011-05-02T17:38:54Z</updated>

		<summary type="html">&lt;p&gt;Thai: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20835</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20835"/>
		<updated>2011-05-02T17:38:27Z</updated>

		<summary type="html">&lt;p&gt;Thai: /*  field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;}, {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
* If &amp;lt;sub_oid&amp;gt; == BYTE (0x00) and &amp;lt;info_sub_oid&amp;gt; == BYTE(0xFF), this is the end of infomation traps.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20834</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20834"/>
		<updated>2011-05-02T17:35:17Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Binary File Format .bin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;}, {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20833</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20833"/>
		<updated>2011-05-02T17:33:52Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Binary File .bin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is [dataType] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;_trap.bin====&lt;br /&gt;
* The corresponding binary file is &amp;lt;name&amp;gt;_trap.bin and it has data describe in  table below:&lt;br /&gt;
** '''enterp''' is &amp;lt;enterprise_oid&amp;gt; fields.&lt;br /&gt;
** '''sibl_ep''' is &amp;lt;sibling_enterprise&amp;gt; fields.&lt;br /&gt;
** '''index_ep''' is &amp;lt;enterprise_index&amp;gt; fields.&lt;br /&gt;
** '''spec_id''' is [specific_trap_number] fields.&lt;br /&gt;
** '''sibl_sid''' is [sibling_specific_trap] fields.&lt;br /&gt;
** '''num_var''' is [number_varbinds] fields.&lt;br /&gt;
** '''id_var''' is [id_varbind] fields.&lt;br /&gt;
[[File:Snmp mib binary trap example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20832</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20832"/>
		<updated>2011-05-02T17:25:35Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [dataType], [dataLen], [data] fields */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its first-child to last-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType] field====&lt;br /&gt;
*If this record is a leaf&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;_trap.bin===&lt;br /&gt;
* The binary file store TRAP information. It is generated by mib2bin tool. Agents will read binary file to get information of TRAP when something bad occurs.&lt;br /&gt;
* In the binary file, A enterprise OID is stored first, followed by its first specific trap number and ID (this ID is match with ID of leaf in &amp;lt;name&amp;gt;.bin) data bindings to be included in this trap to last specific trap number and ID data bindings to be included it. Next, the structure of next this enterprise is stored. This structure is repeated until all enterprise in MIB file is stored.&lt;br /&gt;
* The format of enterprise in &amp;lt;name&amp;gt;_trap.bin&lt;br /&gt;
   &amp;lt;enterprise_oid&amp;gt;&amp;lt;sibling_enterprise&amp;gt;&amp;lt;enterprise_index&amp;gt;[specific_trap_number][sibling_specific_trap][number_varbinds][id_varbind]...&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present.&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the trap.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;enterprise_oid&amp;gt; field====&lt;br /&gt;
* Enterprise oid is full oid of enterprise trap that want to send in MIB file.&lt;br /&gt;
* The format of enterprise oid. &lt;br /&gt;
   &amp;lt;sub_oid&amp;gt; &amp;lt;info_sub_oid&amp;gt; ... &lt;br /&gt;
* where:&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;sub_oid&amp;gt;:&amp;lt;/font&amp;gt; is same format of &amp;lt;oid&amp;gt; field in MIB file.&lt;br /&gt;
**   &amp;lt;font color=red&amp;gt;&amp;lt;info_sub_oid&amp;gt;:&amp;lt;/font&amp;gt; Information of sub_oid.&lt;br /&gt;
   &amp;lt;info_sub_oid&amp;gt; format:&lt;br /&gt;
      bit        when (set = 1)&lt;br /&gt;
      0          the first sub_oid in enterprise&lt;br /&gt;
      1          no use&lt;br /&gt;
      2          no use&lt;br /&gt;
      3          no use&lt;br /&gt;
      4          sub_oid is a parent&lt;br /&gt;
      5          no use&lt;br /&gt;
      6          no use&lt;br /&gt;
      7          the last sub_oid in enterprise&lt;br /&gt;
====&amp;lt;sibling_enterprise&amp;gt; field====&lt;br /&gt;
* Point to next enterprise OID.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====&amp;lt;enterprise_index&amp;gt; field====&lt;br /&gt;
* Index of enterprise OID traps in &amp;lt;name&amp;gt;_trap.bin file.&lt;br /&gt;
* Size of &amp;lt;enterprise_index&amp;gt; is 1 byte.&lt;br /&gt;
====[specific_trap_number] field====&lt;br /&gt;
* If the trap is sent is specific trap, specific trap number is a number indicting specific trap.&lt;br /&gt;
* specific trap number is integer in little-endian format.&lt;br /&gt;
====[sibling_specific_trap] field====&lt;br /&gt;
* Point to next specific trap.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
====[number_varbinds] field====&lt;br /&gt;
* A number of data bindings to be included in the specific trap.&lt;br /&gt;
* Size of [number_varbinds] is 1 byte.&lt;br /&gt;
====[id_varbind] field====&lt;br /&gt;
* [id_varbind] define data bindings (OID and value of OID leaf) that is included specific trap.&lt;br /&gt;
* [id_varbind] is reference to id of the leaf oid in &amp;lt;name&amp;gt;.bin.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File &amp;lt;name&amp;gt;.bin====&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''type''' is type of oid's data that is indicating by id field.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=20831</id>
		<title>File:Snmp mib binary example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=20831"/>
		<updated>2011-05-02T16:55:19Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary example.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_oid_tree_example.jpg&amp;diff=20777</id>
		<title>File:Snmp mib oid tree example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_oid_tree_example.jpg&amp;diff=20777"/>
		<updated>2011-04-28T17:34:36Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib oid tree example.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20764</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20764"/>
		<updated>2011-04-27T17:44:12Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Convert MIB to Binary File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format &amp;lt;name&amp;gt;.bin===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File====&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''defval''' is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20763</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20763"/>
		<updated>2011-04-27T17:41:44Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Convert MIB to Binary File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo_trap.bin+ foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
      An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File====&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''defval''' is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20762</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=20762"/>
		<updated>2011-04-27T17:40:48Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Convert MIB to Binary File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html SNMP's PDU using BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build SNMP API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script.&lt;br /&gt;
* Tools to create ASN.1 MIB Script&lt;br /&gt;
** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] (Now using).&lt;br /&gt;
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin foo_trap.bin+ foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_trap.bin''' is the binary file storing information of TRAP of MIB. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. &lt;br /&gt;
It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset]/[distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;IndexNumber&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;} ...]&lt;br /&gt;
* where:&lt;br /&gt;
** fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
** fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
** fields in braces ({ }) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* The microchip format only supports OIDs upto 255. The following is an workaround to store OID greater than 255.&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   An OID is a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero;&lt;br /&gt;
   bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the OID. Conceptually, these groups of bits are&lt;br /&gt;
   concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of &lt;br /&gt;
   the last octet. The OID shall be encoded in the fewest possible octets, that is, the leading octet of the OID shall not have the value 0x80.&lt;br /&gt;
   &lt;br /&gt;
* Example:&lt;br /&gt;
    The OID               encode of OID in binary file (hex)&lt;br /&gt;
       4                         BYTE(0x04)&lt;br /&gt;
       1                         BYTE(0x01)&lt;br /&gt;
     36061                      BYTE(0x80+ 0x02) BYTE(0x80 + 0x19) BYTE(0x5D)&lt;br /&gt;
    The OID = 36061 is decoded by 0x02*0x80*0x80 + 0x19*0x80 + 0x5D&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node has sibling node&lt;br /&gt;
   1          Node has default data&lt;br /&gt;
   2          Node is sequence &lt;br /&gt;
   3          Node is readable&lt;br /&gt;
   4          Node is a parent&lt;br /&gt;
   5          Node is writable &lt;br /&gt;
   6          Node is able to modify&lt;br /&gt;
   7          Node has sibling field (in IndexNodeInfo this bit indicate that Indexes is imply)&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* In little-endian format.&lt;br /&gt;
* The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* The tool supports the following base data types defined in SNMPv1:&lt;br /&gt;
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647.&lt;br /&gt;
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets.&lt;br /&gt;
** '''Gauge''': Nonnegative integers that can increase or decrease but retain the maximum value reached. The limit of 2^32 -1.&lt;br /&gt;
** '''TimeTicks''': A hundredth of a second since some event. The limit of 2^32 -1.&lt;br /&gt;
** '''Counter''': Nonnegative integers that increase until they reach a maximum value (2^32 -1); then, the integers return to zero.&lt;br /&gt;
** '''DisplayString''': a special case of the octet string type where all the bytes are printable ASCII characters, include formatting characters such as CR and LF, and the C programming language string terminator character zero.&lt;br /&gt;
** '''IpAddress''': A four byte octet string in network order.&lt;br /&gt;
** '''NetworkAddress''': Used to indicate an address choice from one of the possible protocol families. Currently, only IP addresses are supported. &lt;br /&gt;
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib.&lt;br /&gt;
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node.&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;IndexNumber&amp;gt;}] and [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;IndexDataType&amp;gt;}] fields====&lt;br /&gt;
* If this record is sequence (an order list of objects), &lt;br /&gt;
** &amp;lt;IndexNumber&amp;gt; is the number of INDEXes in sequence.&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is id of index node in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index node&lt;br /&gt;
** &amp;lt;IndexDataType&amp;gt;: is data type of index node&lt;br /&gt;
* See [http://www.simpleweb.org/w/images/9/91/Tutorial_Slides_Smi.pdf example] of accessing data in a table&lt;br /&gt;
* Example: &lt;br /&gt;
** '''trap''' node is a sequence to inform the NMS of a significant event (an extraordinary event has occurred at an agent) asynchronously. This sequence has two INDEXes, so we have:&lt;br /&gt;
      &amp;lt;IndexNumber&amp;gt; = 0x02&lt;br /&gt;
      with the 1st INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x05&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0x28&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x02&lt;br /&gt;
      with the 2nd INDEX:&lt;br /&gt;
          &amp;lt;IndexCount&amp;gt; = 0x08&lt;br /&gt;
          &amp;lt;IndexNodeInfo&amp;gt; = 0xA4&lt;br /&gt;
          &amp;lt;IndexDataType&amp;gt; = 0x04&lt;br /&gt;
   In this example, '''trap''' is a table which has 4 columns: &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
      &amp;lt;font color=blue&amp;gt;trapReceiverNumber (1)&amp;lt;/font&amp;gt;, trapEnabled (2), trapReceiverIPAddress (3), &amp;lt;font color=blue&amp;gt;trapCommunity(4)&amp;lt;/font&amp;gt;. &lt;br /&gt;
   Each significant event will be a row defined in the '''trap''' table. &lt;br /&gt;
   &lt;br /&gt;
   This example has two INDEXes: the 1st INDEX node is trapCommunity (4) and the 2nd INDEX node trapReceiverNumber (1) &lt;br /&gt;
   Each INDEX is a node, so it has OID, info, data type.&lt;br /&gt;
   The 1st INDEX node is trapCommunity, which has id = 5, info is 0x28 and data type is INTEGER (0x02). so&lt;br /&gt;
          IndexCount = 0x04&lt;br /&gt;
          IndexNodeInfo = 0x28&lt;br /&gt;
          IndexDataType = 0x02&lt;br /&gt;
   The 2nd INDEX node is trapReceiverNumber, which has id = 8, info is 0xA4 and data type is DisplayString (0x04). so&lt;br /&gt;
          IndexCount = 0x01&lt;br /&gt;
          IndexNodeInfo = 0xA4&lt;br /&gt;
          IndexDataType = 0x04&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
====OID Tree====&lt;br /&gt;
* An example OID tree is given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
====Binary File====&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
** '''oid''' is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
** '''info''' is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
** '''dist''' is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
** '''id''' is [id] fields.&lt;br /&gt;
** '''defval''' is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
** '''index''' is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illustrated in the diagram below:&lt;br /&gt;
** The black arrow lines represent the OID tree structure.&lt;br /&gt;
** The red and green lines represent pointers to data.&lt;br /&gt;
** The dist field points to next sibling record. After parent record is it's children.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
==Build SNMP's PDU using BER==&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19817</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19817"/>
		<updated>2010-10-05T17:24:59Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;:&amp;amp;#32;change integer in little-endian format.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19816</id>
		<title>File:Snmp mib binary example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19816"/>
		<updated>2010-10-05T17:24:06Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary example.jpg&amp;quot;:&amp;amp;#32;change integer in little-endian format.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19790</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19790"/>
		<updated>2010-10-02T15:12:08Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;:&amp;amp;#32;The last node's distant offset is set to 0x00000000&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19789</id>
		<title>File:Snmp mib binary example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19789"/>
		<updated>2010-10-02T15:10:33Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary example.jpg&amp;quot;:&amp;amp;#32;The last node's distant offset is set to 0x00000000&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19788</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19788"/>
		<updated>2010-10-02T14:53:42Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Create ASN.1 MIB Script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
   read Understanding SNMPv1 MIBs section in [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to know a MIB moduled for snmp(ASN.1 MIB Script).&lt;br /&gt;
   List tool's to create ASN.1 MIB Script:&lt;br /&gt;
      [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse].&lt;br /&gt;
      [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files].&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
   distant offset point to next node sibling (that's &amp;quot;NULL&amp;quot; node).It's little-endian.&lt;br /&gt;
   To parse easier, The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
   The tool support types:&lt;br /&gt;
      INTEGER&lt;br /&gt;
      OCTETSTRING&lt;br /&gt;
      Gauge&lt;br /&gt;
      TimeTicks&lt;br /&gt;
      Counter&lt;br /&gt;
      DisplayString (ascii string)&lt;br /&gt;
      IpAddress&lt;br /&gt;
      Opaque&lt;br /&gt;
      SEQUENCE&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
   Sequence is An ordered list of objects, somewhat like a struct in the C language.&lt;br /&gt;
   Type of objects in sequence is same type of node&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19786</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19786"/>
		<updated>2010-09-30T17:40:21Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [{}] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
   distant offset point to next node sibling (that's &amp;quot;NULL&amp;quot; node).It's little-endian.&lt;br /&gt;
   To parse easier, The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
   The tool support types:&lt;br /&gt;
      INTEGER&lt;br /&gt;
      OCTETSTRING&lt;br /&gt;
      Gauge&lt;br /&gt;
      TimeTicks&lt;br /&gt;
      Counter&lt;br /&gt;
      DisplayString (ascii string)&lt;br /&gt;
      IpAddress&lt;br /&gt;
      Opaque&lt;br /&gt;
      SEQUENCE&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
   Sequence is An ordered list of objects, somewhat like a struct in the C language.&lt;br /&gt;
   Type of objects in sequence is same type of node&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19785</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19785"/>
		<updated>2010-09-30T17:03:31Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [dataType], [dataLen], [data] fields */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
   distant offset point to next node sibling (that's &amp;quot;NULL&amp;quot; node).It's little-endian.&lt;br /&gt;
   To parse easier, The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
   The tool support types:&lt;br /&gt;
      INTEGER&lt;br /&gt;
      OCTETSTRING&lt;br /&gt;
      Gauge&lt;br /&gt;
      TimeTicks&lt;br /&gt;
      Counter&lt;br /&gt;
      DisplayString (ascii string)&lt;br /&gt;
      IpAddress&lt;br /&gt;
      Opaque&lt;br /&gt;
      SEQUENCE&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19784</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19784"/>
		<updated>2010-09-30T16:42:19Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [siblingOffset] field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
   distant offset point to next node sibling (that's &amp;quot;NULL&amp;quot; node).It's little-endian.&lt;br /&gt;
   To parse easier, The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
   siblingOffset and distantSiblingOffset in this format is same function (point to next node sibling). &lt;br /&gt;
   They're only differences:&lt;br /&gt;
      siblingOffset use with leaf node.&lt;br /&gt;
      distantSiblingOffset use with node.&lt;br /&gt;
   so it's same value.&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19783</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19783"/>
		<updated>2010-09-30T15:56:54Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [distantSiblingOffset] field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
   distant offset point to next node sibling (that's &amp;quot;NULL&amp;quot; node).It's little-endian.&lt;br /&gt;
   To parse easier, The last node's distant offset is set to 0x00000000.&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19780</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19780"/>
		<updated>2010-09-28T17:38:02Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
   don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
   This is picture with higher resolution.&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19779</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19779"/>
		<updated>2010-09-28T17:35:51Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;:&amp;amp;#32;id fields's size is changed 1 byte to 4 bytes.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19778</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19778"/>
		<updated>2010-09-28T17:32:47Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;:&amp;amp;#32;id fields's size is changed 1 byte to 4 bytes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19777</id>
		<title>File:Snmp mib binary example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_example.jpg&amp;diff=19777"/>
		<updated>2010-09-28T17:29:53Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary example.jpg&amp;quot;:&amp;amp;#32;id fields's size is changed 1 byte to 4 bytes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19776</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19776"/>
		<updated>2010-09-28T17:23:11Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* [id] field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
   don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
   leaf means child, but child doesn't mean leaf. &lt;br /&gt;
   the comment fixed.&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19775</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19775"/>
		<updated>2010-09-28T17:20:17Z</updated>

		<summary type="html">&lt;p&gt;Thai: /*  field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
   don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a leaf)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19774</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19774"/>
		<updated>2010-09-28T17:17:05Z</updated>

		<summary type="html">&lt;p&gt;Thai: /*  field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
   don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
   This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
   char(x) that's mean get ascii of x.&lt;br /&gt;
   char(16) is used to separate two oids.&lt;br /&gt;
   char(255) is determined that oid geater than 254.&lt;br /&gt;
   &amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a child)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19773</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19773"/>
		<updated>2010-09-28T17:16:15Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Create Microchip Custom MIB Script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
   don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
char(x) that's mean get ascii of x.&lt;br /&gt;
char(16) is used to separate two oids.&lt;br /&gt;
char(255) is determined that oid geater than 254.&lt;br /&gt;
&amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a child)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19772</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19772"/>
		<updated>2010-09-28T17:15:01Z</updated>

		<summary type="html">&lt;p&gt;Thai: /*  field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
This is an workaround to store oids, but this isn't a standard representation or the microchip format.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
char(x) that's mean get ascii of x.&lt;br /&gt;
char(16) is used to separate two oids.&lt;br /&gt;
char(255) is determined that oid geater than 254.&lt;br /&gt;
&amp;quot;length of oid_i&amp;quot; is length string of oid_i that's converted base 255.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a child)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19771</id>
		<title>SNMP MIB Implementation</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=SNMP_MIB_Implementation&amp;diff=19771"/>
		<updated>2010-09-28T16:40:47Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* Create Microchip Custom MIB Script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describe how to generate a MIB (Management Information Base) for SNMP agent.&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
# Create a Microchip Custom MIB script '''snmp.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure.&lt;br /&gt;
# Convert foo.mib to binary file using '''mib2bin'''&lt;br /&gt;
# Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
# Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
# Build binary MIB file reader library.&lt;br /&gt;
# Build functions service oid tree.&lt;br /&gt;
# Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create Microchip Custom MIB Script==&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Is this file needed?&amp;lt;/font&amp;gt;&lt;br /&gt;
don't needed creat Microchip MIB script. &lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If so any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create ASN.1 MIB Script==&lt;br /&gt;
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;Any tutorial to create this file?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abstract Syntax Notation===&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert MIB to Binary File==&lt;br /&gt;
* mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs.&lt;br /&gt;
                                 MIB compiler tools: '''mib2bin'''&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + foo.h + foo_data.h&lt;br /&gt;
&lt;br /&gt;
* Syntax to use mib2bin tool:&lt;br /&gt;
   '''mib2bin &amp;lt;MIBfile&amp;gt;...&lt;br /&gt;
* where MIBfile file is ASN.1 format file. MIBfile = &amp;lt;name&amp;gt;.&amp;lt;type&amp;gt;&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;_data.h''' is C header file storing information of OID tree.  This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory.&lt;br /&gt;
** '''&amp;lt;name&amp;gt;.h''' is C header file storing ID that's reference to function service of OID.&lt;br /&gt;
* Note: &lt;br /&gt;
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution.&lt;br /&gt;
** If the three files exist, mib2bin tool will overwrite the files.&lt;br /&gt;
&lt;br /&gt;
===Binary File Format===&lt;br /&gt;
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request.&lt;br /&gt;
* In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored.&lt;br /&gt;
* A parent or child is a record. Single record of binary file have format:&lt;br /&gt;
  &amp;lt;oid&amp;gt;, &amp;lt;nodeInfo&amp;gt;, &lt;br /&gt;
  [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], &lt;br /&gt;
  [{&amp;lt;index_number&amp;gt;},{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;} ...]&lt;br /&gt;
  &lt;br /&gt;
  where:&lt;br /&gt;
  fields indicated by angle brackets (&amp;lt; &amp;gt;) are always present&lt;br /&gt;
  fields in square brackets ([ ]) are optional depending on characteristics of the current node.&lt;br /&gt;
  fields in braces ({}) are optional but always occur together.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;oid&amp;gt; field====&lt;br /&gt;
* Format of OID:&lt;br /&gt;
   oid1 char(16)&lt;br /&gt;
   oid2 char(16)&lt;br /&gt;
   ....&lt;br /&gt;
* if oid_i &amp;lt; 254: oid_i = char (oid_i)&lt;br /&gt;
* else oid_i = char(255) + char(length of oid_i) + oid_i (base on 255) + char(16)&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;If this a standard representation, or is a workaround of the microchip format?&amp;lt;/font&amp;gt;&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What does char(.) mean?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;nodeInfo&amp;gt; field====&lt;br /&gt;
* information of node&lt;br /&gt;
   bit        when (set = 1)&lt;br /&gt;
   0          Node is a parent (0: node is a child)&lt;br /&gt;
   1          Node is sequence&lt;br /&gt;
   2          Node is readable&lt;br /&gt;
   3          Node is writable&lt;br /&gt;
   4          Node is able to create&lt;br /&gt;
   5          Node has default data&lt;br /&gt;
   6          (if node is sequence, this is mean implied index node)&lt;br /&gt;
   7          always set 1&lt;br /&gt;
&lt;br /&gt;
====[id] field====&lt;br /&gt;
* If this record is leaf, id that's reference to function services the record.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;leaf means child?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[distantSiblingOffset] field====&lt;br /&gt;
* If this record is a node [distantSiblingOffset] is enabled. Point to next node sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;root node should have no sibling. How come the example (below) has a distant offset BC000000? Also, is it big-endian or little-endian?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[siblingOffset] field====&lt;br /&gt;
* If this record is a leaf [siblingOffset] is enabled. Point to next leaf sibling.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;I can see some child nodes in the example, but the table does not have any siblingOffset, can you explain?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[dataType], [dataLen], [data] fields====&lt;br /&gt;
* If this record is a leaf and has default data&lt;br /&gt;
** [dataType] is type of leaf's data.&lt;br /&gt;
** [dataLen] is length of data.&lt;br /&gt;
** [data] is data on string.&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;How many dataType does it support?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====[{&amp;lt;index_number&amp;gt;}]====&lt;br /&gt;
* If this record is sequence, index_number is number of INDEXes in sequence.&lt;br /&gt;
** [{&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;}]&lt;br /&gt;
* If this record is sequence&lt;br /&gt;
** &amp;lt;IndexCount&amp;gt;: is index of INDEX in table&lt;br /&gt;
** &amp;lt;IndexNodeInfo&amp;gt;: is info of index_node&lt;br /&gt;
** &amp;lt;indexDataType&amp;gt;: is data type of index_node&lt;br /&gt;
* &amp;lt;font color=red&amp;gt;What kind of data will be a sequence node?&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
* The example mchip.txt describe the OID tree given below: &lt;br /&gt;
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
* The corresponding binary file is mchip.bin and it has data describe in  table below:&lt;br /&gt;
[[File:Snmp mib binary example.jpg | thumb | center | 900px]]&lt;br /&gt;
&lt;br /&gt;
   OID is &amp;lt;oid&amp;gt; fields.&lt;br /&gt;
   Info is &amp;lt;nodeInfo&amp;gt; fields.&lt;br /&gt;
   Dist is [distantSiblingOffset]/[siblingOffset] fields.&lt;br /&gt;
   Id is [id] fields.&lt;br /&gt;
   Defval is data fields, include [dataType], [dataLen], [data] fields.&lt;br /&gt;
   Index is index fields of sequence, include [{index_number} , {&amp;lt;IndexCount&amp;gt;, &amp;lt;IndexNodeInfo&amp;gt;, &amp;lt;indexDataType&amp;gt;, ...}].&lt;br /&gt;
&lt;br /&gt;
* The detail description of mchip.bin is illuminated by structure diagram below &amp;lt;font color=red&amp;gt;can you upload a picture with higher resolution?&amp;lt;/font&amp;gt;:&lt;br /&gt;
[[File:Snmp mib binary detail example.jpg]]&lt;br /&gt;
&lt;br /&gt;
   The hidden linear is oid tree structure.&lt;br /&gt;
   The red and green continue linear is pointer  of data.&lt;br /&gt;
   The dist field point to next sibling record. After parent record is it's children.&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19770</id>
		<title>File:Snmp mib binary detail example.jpg</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=File:Snmp_mib_binary_detail_example.jpg&amp;diff=19770"/>
		<updated>2010-09-28T13:57:55Z</updated>

		<summary type="html">&lt;p&gt;Thai: uploaded a new version of &amp;quot;File:Snmp mib binary detail example.jpg&amp;quot;:&amp;amp;#32;mib structure on diagram&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=UIP&amp;diff=19648</id>
		<title>UIP</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=UIP&amp;diff=19648"/>
		<updated>2010-08-23T15:48:24Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* To-Do List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describes how to use uIP (a Light-weight TCP/IP stack) for developing ethernet applications for 8/16-bit embedded system (see [{{SERVER}}/Ethernet_Module Ethernet_Module]).&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.&lt;br /&gt;
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Bug List==&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from buffalo router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from main router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been &amp;quot;reset&amp;quot;, and the connection is ok again.&lt;br /&gt;
*SMTP&lt;br /&gt;
**some router cannot used SMTP module&lt;br /&gt;
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function&lt;br /&gt;
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
*32kB constant limitations&lt;br /&gt;
**see if webserver can be stored in flash in file system&lt;br /&gt;
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]&lt;br /&gt;
**porting snmp to uip&lt;br /&gt;
**reference to lwip&lt;br /&gt;
**a API(or any method) to let other system to talk to our device OR by scpi, modbus&lt;br /&gt;
*https by SSL&lt;br /&gt;
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)&lt;br /&gt;
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Porting==&lt;br /&gt;
===CVS Repository===&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Attribute !! Value&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Host || uip-stack.cvs.sourceforge.net&lt;br /&gt;
|-&lt;br /&gt;
| Repository Path || /cvsroot/uip-stack&lt;br /&gt;
|-&lt;br /&gt;
| Connection Type || pserver&lt;br /&gt;
|-&lt;br /&gt;
| User || anonymous&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Patches===&lt;br /&gt;
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]&lt;br /&gt;
*uip-patch-1.0-01.diff (minimal)&lt;br /&gt;
**'''uip.c'''&lt;br /&gt;
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869&lt;br /&gt;
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)&lt;br /&gt;
**'''uip.h'''&lt;br /&gt;
***Change line 1070 to&amp;lt;br&amp;gt;#      define HTONS(n) (u16_t)(((((u16_t) (n)) &amp;lt;&amp;lt; 8)&amp;amp;0xff00) | ((((u16_t) (n)) &amp;gt;&amp;gt; 8)&amp;amp;0x00ff))&lt;br /&gt;
**'''psock.c'''&lt;br /&gt;
***Change line 188 to&amp;lt;br&amp;gt;s-&amp;gt;sendptr = (u8_t*) buf;&lt;br /&gt;
***Change lines 276, 303 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)(psock-&amp;gt;bufptr), psock-&amp;gt;bufsize);&lt;br /&gt;
***Change line 334 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)buffer, buffersize);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
*Include the following files to use the uIP stack&lt;br /&gt;
**timer.c&lt;br /&gt;
**uip.c&lt;br /&gt;
**uip_arp.c&lt;br /&gt;
**psock.c&lt;br /&gt;
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.&lt;br /&gt;
*uip-config.h: configuration for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uIP Ethernet Application==&lt;br /&gt;
*The following applications are modified from the demo applications in uIP.&lt;br /&gt;
&lt;br /&gt;
===DHCP Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dhcpc_8bit dhcpc_8bit]&lt;br /&gt;
*Enable UDP in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_UDP             1&lt;br /&gt;
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_BUFFER_SIZE     1536&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Web Server===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=webserver_8bit webserver_8bit]&lt;br /&gt;
====add-on====&lt;br /&gt;
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.&lt;br /&gt;
   GET /index.html HTTP/1.1&lt;br /&gt;
   GET /abc.shtml HTTP/1.1&lt;br /&gt;
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.&lt;br /&gt;
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request&lt;br /&gt;
   GET /abc.shtml?val=500.0&amp;amp;button=Set HTTP/1.1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Resolver===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dns_resolv_8bit dns_resolv_8bit]&lt;br /&gt;
*The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address. It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.&lt;br /&gt;
*When a hostname has been resolved (or found to be non-existant), the resolver code calls a callback function called resolv_found() that must be implemented by the module that uses the resolver.&lt;br /&gt;
*Router Setting&lt;br /&gt;
**Special attention should be paid to router setting, when the DNS Server address is acquired by DHCP.&lt;br /&gt;
**The DNS Resolver module assumes that the DNS server can support DNS TYPE of ANY, MX, CNAME and A. See http://www.networksorcery.com/enp/protocol/dns.htm for definitions of these options.&lt;br /&gt;
*In case the router itself does not support these options, the router should be set to deliver a DNS Server address which support these options.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SMTP Mail Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=smtpc_8bit smtpc_8bit]&lt;br /&gt;
*The SMTP client searches the ip address of the mail server by a DNS call. It then logins to the server with the email account name and address using AUTH LOGIN. If login is successful, the mail is sent to the list of recipients.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SNMP Agent (Not implemented yet)===&lt;br /&gt;
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]&lt;br /&gt;
*It belongs to the Application Layer, as in HTTP.&lt;br /&gt;
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.&lt;br /&gt;
&lt;br /&gt;
====Components in a SNMP System====&lt;br /&gt;
*Network Management Station (NMS)&lt;br /&gt;
**This is a client, initiating SNMP communication.&lt;br /&gt;
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.&lt;br /&gt;
*SNMP Agents&lt;br /&gt;
**These are servers, responding to one or multiple NMS requests.&lt;br /&gt;
*Management Information Base (MIB)&lt;br /&gt;
**A special collection of variables managed by the SNMP agents.&lt;br /&gt;
**MIB has a tree-like structure.&lt;br /&gt;
**An Object Identifier (OID) is given for each node.&lt;br /&gt;
**Data are stored at the end-nodes.&lt;br /&gt;
**Private variables may be constructed under the &amp;quot;enterprise&amp;quot; sub-tree.&lt;br /&gt;
**The OID for &amp;quot;enterprise&amp;quot; can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].&lt;br /&gt;
&lt;br /&gt;
====Abstract Syntax Notation====&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
====To-Do List====&lt;br /&gt;
*Build MIB file.&lt;br /&gt;
**Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
**Build MIB compiler tool to compile MIB file to binary file (store tree structure: oid, id, data type, value, position) and C header file (store id to determine a function service the oid).&lt;br /&gt;
**Build MIB converter tool to convert binary MIB file to C header file (embedded to code). Note: binary MIB file can store in MMC/SD card (don't need MIB converter tool).&lt;br /&gt;
&lt;br /&gt;
                                 [https://www.ee.buu.ac.th/~acitl/EthernetMini/MCHPTCPStack%203.75/mib2bib.exe MIB compiler tools]&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + oid.h (store ID that's reference to function service of OID)&lt;br /&gt;
  &lt;br /&gt;
                                 MIB converter tools&lt;br /&gt;
  foo.bin                  -----------------------------------&amp;gt; foo.h (store the structure of OID tree)&lt;br /&gt;
&lt;br /&gt;
*Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
*Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
*Build binary MIB file reader library.&lt;br /&gt;
*Build functions service oid tree.&lt;br /&gt;
*Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
===uIP===&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Download Download]&lt;br /&gt;
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]&lt;br /&gt;
===lwIP===&lt;br /&gt;
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]&lt;br /&gt;
*[http://www.nongnu.org/lwip/ Documentation]&lt;br /&gt;
===HTML===&lt;br /&gt;
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript&lt;br /&gt;
===SNMP===&lt;br /&gt;
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents&lt;br /&gt;
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number&lt;br /&gt;
*[http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ASN.1]: Abstract Syntax Notation One (ASN.1):Specification of basic notation&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=UIP&amp;diff=19647</id>
		<title>UIP</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=UIP&amp;diff=19647"/>
		<updated>2010-08-23T15:47:20Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* To-Do List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describes how to use uIP (a Light-weight TCP/IP stack) for developing ethernet applications for 8/16-bit embedded system (see [{{SERVER}}/Ethernet_Module Ethernet_Module]).&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.&lt;br /&gt;
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Bug List==&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from buffalo router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from main router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been &amp;quot;reset&amp;quot;, and the connection is ok again.&lt;br /&gt;
*SMTP&lt;br /&gt;
**some router cannot used SMTP module&lt;br /&gt;
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function&lt;br /&gt;
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
*32kB constant limitations&lt;br /&gt;
**see if webserver can be stored in flash in file system&lt;br /&gt;
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]&lt;br /&gt;
**porting snmp to uip&lt;br /&gt;
**reference to lwip&lt;br /&gt;
**a API(or any method) to let other system to talk to our device OR by scpi, modbus&lt;br /&gt;
*https by SSL&lt;br /&gt;
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)&lt;br /&gt;
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Porting==&lt;br /&gt;
===CVS Repository===&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Attribute !! Value&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Host || uip-stack.cvs.sourceforge.net&lt;br /&gt;
|-&lt;br /&gt;
| Repository Path || /cvsroot/uip-stack&lt;br /&gt;
|-&lt;br /&gt;
| Connection Type || pserver&lt;br /&gt;
|-&lt;br /&gt;
| User || anonymous&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Patches===&lt;br /&gt;
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]&lt;br /&gt;
*uip-patch-1.0-01.diff (minimal)&lt;br /&gt;
**'''uip.c'''&lt;br /&gt;
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869&lt;br /&gt;
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)&lt;br /&gt;
**'''uip.h'''&lt;br /&gt;
***Change line 1070 to&amp;lt;br&amp;gt;#      define HTONS(n) (u16_t)(((((u16_t) (n)) &amp;lt;&amp;lt; 8)&amp;amp;0xff00) | ((((u16_t) (n)) &amp;gt;&amp;gt; 8)&amp;amp;0x00ff))&lt;br /&gt;
**'''psock.c'''&lt;br /&gt;
***Change line 188 to&amp;lt;br&amp;gt;s-&amp;gt;sendptr = (u8_t*) buf;&lt;br /&gt;
***Change lines 276, 303 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)(psock-&amp;gt;bufptr), psock-&amp;gt;bufsize);&lt;br /&gt;
***Change line 334 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)buffer, buffersize);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
*Include the following files to use the uIP stack&lt;br /&gt;
**timer.c&lt;br /&gt;
**uip.c&lt;br /&gt;
**uip_arp.c&lt;br /&gt;
**psock.c&lt;br /&gt;
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.&lt;br /&gt;
*uip-config.h: configuration for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uIP Ethernet Application==&lt;br /&gt;
*The following applications are modified from the demo applications in uIP.&lt;br /&gt;
&lt;br /&gt;
===DHCP Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dhcpc_8bit dhcpc_8bit]&lt;br /&gt;
*Enable UDP in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_UDP             1&lt;br /&gt;
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_BUFFER_SIZE     1536&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Web Server===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=webserver_8bit webserver_8bit]&lt;br /&gt;
====add-on====&lt;br /&gt;
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.&lt;br /&gt;
   GET /index.html HTTP/1.1&lt;br /&gt;
   GET /abc.shtml HTTP/1.1&lt;br /&gt;
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.&lt;br /&gt;
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request&lt;br /&gt;
   GET /abc.shtml?val=500.0&amp;amp;button=Set HTTP/1.1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Resolver===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dns_resolv_8bit dns_resolv_8bit]&lt;br /&gt;
*The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address. It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.&lt;br /&gt;
*When a hostname has been resolved (or found to be non-existant), the resolver code calls a callback function called resolv_found() that must be implemented by the module that uses the resolver.&lt;br /&gt;
*Router Setting&lt;br /&gt;
**Special attention should be paid to router setting, when the DNS Server address is acquired by DHCP.&lt;br /&gt;
**The DNS Resolver module assumes that the DNS server can support DNS TYPE of ANY, MX, CNAME and A. See http://www.networksorcery.com/enp/protocol/dns.htm for definitions of these options.&lt;br /&gt;
*In case the router itself does not support these options, the router should be set to deliver a DNS Server address which support these options.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SMTP Mail Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=smtpc_8bit smtpc_8bit]&lt;br /&gt;
*The SMTP client searches the ip address of the mail server by a DNS call. It then logins to the server with the email account name and address using AUTH LOGIN. If login is successful, the mail is sent to the list of recipients.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SNMP Agent (Not implemented yet)===&lt;br /&gt;
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]&lt;br /&gt;
*It belongs to the Application Layer, as in HTTP.&lt;br /&gt;
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.&lt;br /&gt;
&lt;br /&gt;
====Components in a SNMP System====&lt;br /&gt;
*Network Management Station (NMS)&lt;br /&gt;
**This is a client, initiating SNMP communication.&lt;br /&gt;
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.&lt;br /&gt;
*SNMP Agents&lt;br /&gt;
**These are servers, responding to one or multiple NMS requests.&lt;br /&gt;
*Management Information Base (MIB)&lt;br /&gt;
**A special collection of variables managed by the SNMP agents.&lt;br /&gt;
**MIB has a tree-like structure.&lt;br /&gt;
**An Object Identifier (OID) is given for each node.&lt;br /&gt;
**Data are stored at the end-nodes.&lt;br /&gt;
**Private variables may be constructed under the &amp;quot;enterprise&amp;quot; sub-tree.&lt;br /&gt;
**The OID for &amp;quot;enterprise&amp;quot; can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].&lt;br /&gt;
&lt;br /&gt;
====Abstract Syntax Notation====&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
====To-Do List====&lt;br /&gt;
*Build MIB file.&lt;br /&gt;
**Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
**Build MIB compiler tool to compile MIB file to binary file (store tree structure: oid, id, data type, value, position) and C header file (store id to determine a function service the oid).&lt;br /&gt;
&lt;br /&gt;
        MIB scripts to foo.bin + oid.h &lt;br /&gt;
**Build MIB converter tool to convert binary MIB file to C header file (embedded to code). Note: binary MIB file can store in MMC/SD card (don't need MIB converter tool).&lt;br /&gt;
&lt;br /&gt;
                                 [https://www.ee.buu.ac.th/~acitl/EthernetMini/MCHPTCPStack%203.75/mib2bib.exe MIB compiler tools]&lt;br /&gt;
  [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format)   -----------------------------------&amp;gt; foo.bin + oid.h (store ID that's reference to function service of OID)&lt;br /&gt;
  &lt;br /&gt;
                                 MIB converter tools&lt;br /&gt;
  foo.bin                  -----------------------------------&amp;gt; foo.h (store the structure of OID tree)&lt;br /&gt;
&lt;br /&gt;
*Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
*Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
*Build binary MIB file reader library.&lt;br /&gt;
*Build functions service oid tree.&lt;br /&gt;
*Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
===uIP===&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Download Download]&lt;br /&gt;
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]&lt;br /&gt;
===lwIP===&lt;br /&gt;
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]&lt;br /&gt;
*[http://www.nongnu.org/lwip/ Documentation]&lt;br /&gt;
===HTML===&lt;br /&gt;
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript&lt;br /&gt;
===SNMP===&lt;br /&gt;
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents&lt;br /&gt;
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number&lt;br /&gt;
*[http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ASN.1]: Abstract Syntax Notation One (ASN.1):Specification of basic notation&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=UIP&amp;diff=19619</id>
		<title>UIP</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=UIP&amp;diff=19619"/>
		<updated>2010-08-04T16:36:24Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* To-Do List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describes how to use uIP (a Light-weight TCP/IP stack) for developing ethernet applications for 8/16-bit embedded system (see [{{SERVER}}/Ethernet_Module Ethernet_Module]).&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.&lt;br /&gt;
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Bug List==&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from buffalo router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from main router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been &amp;quot;reset&amp;quot;, and the connection is ok again.&lt;br /&gt;
*SMTP&lt;br /&gt;
**some router cannot used SMTP module&lt;br /&gt;
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function&lt;br /&gt;
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
*32kB constant limitations&lt;br /&gt;
**see if webserver can be stored in flash in file system&lt;br /&gt;
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]&lt;br /&gt;
**porting snmp to uip&lt;br /&gt;
**reference to lwip&lt;br /&gt;
**a API(or any method) to let other system to talk to our device OR by scpi, modbus&lt;br /&gt;
*https by SSL&lt;br /&gt;
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)&lt;br /&gt;
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Porting==&lt;br /&gt;
===CVS Repository===&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Attribute !! Value&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Host || uip-stack.cvs.sourceforge.net&lt;br /&gt;
|-&lt;br /&gt;
| Repository Path || /cvsroot/uip-stack&lt;br /&gt;
|-&lt;br /&gt;
| Connection Type || pserver&lt;br /&gt;
|-&lt;br /&gt;
| User || anonymous&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Patches===&lt;br /&gt;
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]&lt;br /&gt;
*uip-patch-1.0-01.diff (minimal)&lt;br /&gt;
**'''uip.c'''&lt;br /&gt;
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869&lt;br /&gt;
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)&lt;br /&gt;
**'''uip.h'''&lt;br /&gt;
***Change line 1070 to&amp;lt;br&amp;gt;#      define HTONS(n) (u16_t)(((((u16_t) (n)) &amp;lt;&amp;lt; 8)&amp;amp;0xff00) | ((((u16_t) (n)) &amp;gt;&amp;gt; 8)&amp;amp;0x00ff))&lt;br /&gt;
**'''psock.c'''&lt;br /&gt;
***Change line 188 to&amp;lt;br&amp;gt;s-&amp;gt;sendptr = (u8_t*) buf;&lt;br /&gt;
***Change lines 276, 303 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)(psock-&amp;gt;bufptr), psock-&amp;gt;bufsize);&lt;br /&gt;
***Change line 334 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)buffer, buffersize);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
*Include the following files to use the uIP stack&lt;br /&gt;
**timer.c&lt;br /&gt;
**uip.c&lt;br /&gt;
**uip_arp.c&lt;br /&gt;
**psock.c&lt;br /&gt;
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.&lt;br /&gt;
*uip-config.h: configuration for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uIP Ethernet Application==&lt;br /&gt;
*The following applications are modified from the demo applications in uIP.&lt;br /&gt;
&lt;br /&gt;
===DHCP Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dhcpc_8bit dhcpc_8bit]&lt;br /&gt;
*Enable UDP in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_UDP             1&lt;br /&gt;
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_BUFFER_SIZE     1536&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Web Server===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=webserver_8bit webserver_8bit]&lt;br /&gt;
====add-on====&lt;br /&gt;
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.&lt;br /&gt;
   GET /index.html HTTP/1.1&lt;br /&gt;
   GET /abc.shtml HTTP/1.1&lt;br /&gt;
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.&lt;br /&gt;
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request&lt;br /&gt;
   GET /abc.shtml?val=500.0&amp;amp;button=Set HTTP/1.1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Resolver===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dns_resolv_8bit dns_resolv_8bit]&lt;br /&gt;
*The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address. It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.&lt;br /&gt;
*When a hostname has been resolved (or found to be non-existant), the resolver code calls a callback function called resolv_found() that must be implemented by the module that uses the resolver.&lt;br /&gt;
*Router Setting&lt;br /&gt;
**Special attention should be paid to router setting, when the DNS Server address is acquired by DHCP.&lt;br /&gt;
**The DNS Resolver module assumes that the DNS server can support DNS TYPE of ANY, MX, CNAME and A. See http://www.networksorcery.com/enp/protocol/dns.htm for definitions of these options.&lt;br /&gt;
*In case the router itself does not support these options, the router should be set to deliver a DNS Server address which support these options.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SMTP Mail Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=smtpc_8bit smtpc_8bit]&lt;br /&gt;
*The SMTP client searches the ip address of the mail server by a DNS call. It then logins to the server with the email account name and address using AUTH LOGIN. If login is successful, the mail is sent to the list of recipients.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SNMP Agent (Not implemented yet)===&lt;br /&gt;
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]&lt;br /&gt;
*It belongs to the Application Layer, as in HTTP.&lt;br /&gt;
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.&lt;br /&gt;
&lt;br /&gt;
====Components in a SNMP System====&lt;br /&gt;
*Network Management Station (NMS)&lt;br /&gt;
**This is a client, initiating SNMP communication.&lt;br /&gt;
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.&lt;br /&gt;
*SNMP Agents&lt;br /&gt;
**These are servers, responding to one or multiple NMS requests.&lt;br /&gt;
*Management Information Base (MIB)&lt;br /&gt;
**A special collection of variables managed by the SNMP agents.&lt;br /&gt;
**MIB has a tree-like structure.&lt;br /&gt;
**An Object Identifier (OID) is given for each node.&lt;br /&gt;
**Data are stored at the end-nodes.&lt;br /&gt;
**Private variables may be constructed under the &amp;quot;enterprise&amp;quot; sub-tree.&lt;br /&gt;
**The OID for &amp;quot;enterprise&amp;quot; can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].&lt;br /&gt;
&lt;br /&gt;
====Abstract Syntax Notation====&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
====To-Do List====&lt;br /&gt;
*Build MIB file.&lt;br /&gt;
**Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
**Build MIB compiler tool to compile MIB file to binary file (store tree structure: oid, id, data type, value, position) and C header file (store id to determine a function service the oid).&lt;br /&gt;
**Build MIB converter tool to convert binary MIB file to C header file (embedded to code). Note: binary MIB file can store in MMC/SD card (don't need MIB converter tool).&lt;br /&gt;
*Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
*Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
*Build binary MIB file reader library.&lt;br /&gt;
*Build functions service oid tree.&lt;br /&gt;
*Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
===uIP===&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Download Download]&lt;br /&gt;
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]&lt;br /&gt;
===lwIP===&lt;br /&gt;
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]&lt;br /&gt;
*[http://www.nongnu.org/lwip/ Documentation]&lt;br /&gt;
===HTML===&lt;br /&gt;
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript&lt;br /&gt;
===SNMP===&lt;br /&gt;
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents&lt;br /&gt;
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number&lt;br /&gt;
*[http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ASN.1]: Abstract Syntax Notation One (ASN.1):Specification of basic notation&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=UIP&amp;diff=19618</id>
		<title>UIP</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=UIP&amp;diff=19618"/>
		<updated>2010-08-04T15:28:53Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP Agent (Not implemented yet) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describes how to use uIP (a Light-weight TCP/IP stack) for developing ethernet applications for 8/16-bit embedded system (see [{{SERVER}}/Ethernet_Module Ethernet_Module]).&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.&lt;br /&gt;
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Bug List==&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from buffalo router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from main router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been &amp;quot;reset&amp;quot;, and the connection is ok again.&lt;br /&gt;
*SMTP&lt;br /&gt;
**some router cannot used SMTP module&lt;br /&gt;
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function&lt;br /&gt;
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
*32kB constant limitations&lt;br /&gt;
**see if webserver can be stored in flash in file system&lt;br /&gt;
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]&lt;br /&gt;
**porting snmp to uip&lt;br /&gt;
**reference to lwip&lt;br /&gt;
**a API(or any method) to let other system to talk to our device OR by scpi, modbus&lt;br /&gt;
*https by SSL&lt;br /&gt;
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)&lt;br /&gt;
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Porting==&lt;br /&gt;
===CVS Repository===&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Attribute !! Value&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Host || uip-stack.cvs.sourceforge.net&lt;br /&gt;
|-&lt;br /&gt;
| Repository Path || /cvsroot/uip-stack&lt;br /&gt;
|-&lt;br /&gt;
| Connection Type || pserver&lt;br /&gt;
|-&lt;br /&gt;
| User || anonymous&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Patches===&lt;br /&gt;
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]&lt;br /&gt;
*uip-patch-1.0-01.diff (minimal)&lt;br /&gt;
**'''uip.c'''&lt;br /&gt;
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869&lt;br /&gt;
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)&lt;br /&gt;
**'''uip.h'''&lt;br /&gt;
***Change line 1070 to&amp;lt;br&amp;gt;#      define HTONS(n) (u16_t)(((((u16_t) (n)) &amp;lt;&amp;lt; 8)&amp;amp;0xff00) | ((((u16_t) (n)) &amp;gt;&amp;gt; 8)&amp;amp;0x00ff))&lt;br /&gt;
**'''psock.c'''&lt;br /&gt;
***Change line 188 to&amp;lt;br&amp;gt;s-&amp;gt;sendptr = (u8_t*) buf;&lt;br /&gt;
***Change lines 276, 303 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)(psock-&amp;gt;bufptr), psock-&amp;gt;bufsize);&lt;br /&gt;
***Change line 334 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)buffer, buffersize);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
*Include the following files to use the uIP stack&lt;br /&gt;
**timer.c&lt;br /&gt;
**uip.c&lt;br /&gt;
**uip_arp.c&lt;br /&gt;
**psock.c&lt;br /&gt;
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.&lt;br /&gt;
*uip-config.h: configuration for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uIP Ethernet Application==&lt;br /&gt;
*The following applications are modified from the demo applications in uIP.&lt;br /&gt;
&lt;br /&gt;
===DHCP Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dhcpc_8bit dhcpc_8bit]&lt;br /&gt;
*Enable UDP in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_UDP             1&lt;br /&gt;
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_BUFFER_SIZE     1536&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Web Server===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=webserver_8bit webserver_8bit]&lt;br /&gt;
====add-on====&lt;br /&gt;
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.&lt;br /&gt;
   GET /index.html HTTP/1.1&lt;br /&gt;
   GET /abc.shtml HTTP/1.1&lt;br /&gt;
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.&lt;br /&gt;
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request&lt;br /&gt;
   GET /abc.shtml?val=500.0&amp;amp;button=Set HTTP/1.1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Resolver===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dns_resolv_8bit dns_resolv_8bit]&lt;br /&gt;
*The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address. It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.&lt;br /&gt;
*When a hostname has been resolved (or found to be non-existant), the resolver code calls a callback function called resolv_found() that must be implemented by the module that uses the resolver.&lt;br /&gt;
*Router Setting&lt;br /&gt;
**Special attention should be paid to router setting, when the DNS Server address is acquired by DHCP.&lt;br /&gt;
**The DNS Resolver module assumes that the DNS server can support DNS TYPE of ANY, MX, CNAME and A. See http://www.networksorcery.com/enp/protocol/dns.htm for definitions of these options.&lt;br /&gt;
*In case the router itself does not support these options, the router should be set to deliver a DNS Server address which support these options.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SMTP Mail Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=smtpc_8bit smtpc_8bit]&lt;br /&gt;
*The SMTP client searches the ip address of the mail server by a DNS call. It then logins to the server with the email account name and address using AUTH LOGIN. If login is successful, the mail is sent to the list of recipients.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SNMP Agent (Not implemented yet)===&lt;br /&gt;
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]&lt;br /&gt;
*It belongs to the Application Layer, as in HTTP.&lt;br /&gt;
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.&lt;br /&gt;
&lt;br /&gt;
====Components in a SNMP System====&lt;br /&gt;
*Network Management Station (NMS)&lt;br /&gt;
**This is a client, initiating SNMP communication.&lt;br /&gt;
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.&lt;br /&gt;
*SNMP Agents&lt;br /&gt;
**These are servers, responding to one or multiple NMS requests.&lt;br /&gt;
*Management Information Base (MIB)&lt;br /&gt;
**A special collection of variables managed by the SNMP agents.&lt;br /&gt;
**MIB has a tree-like structure.&lt;br /&gt;
**An Object Identifier (OID) is given for each node.&lt;br /&gt;
**Data are stored at the end-nodes.&lt;br /&gt;
**Private variables may be constructed under the &amp;quot;enterprise&amp;quot; sub-tree.&lt;br /&gt;
**The OID for &amp;quot;enterprise&amp;quot; can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].&lt;br /&gt;
&lt;br /&gt;
====Abstract Syntax Notation====&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
====To-Do List====&lt;br /&gt;
*Build MIB file.&lt;br /&gt;
**Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation].&lt;br /&gt;
**Build MIB compiler tool to compile MIB file to binary file (store tree structure: oid, id, data type, value, position) and C header file (store id to determine a function service the oid).&lt;br /&gt;
**Build MIB converter tool to convert binary MIB file to C header file (embedded to code). Note: binary MIB file can store in MMC/SD card (don't need MIB converter tool).&lt;br /&gt;
*Build [http://www.vijaymukhi.com/vmis/ber.htm BER] (Base encoding rules) encoder and decoder library to process data that's transfer between NMS and agents.&lt;br /&gt;
*Build snmp API use BER format on [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port).&lt;br /&gt;
*Build binary MIB file reader library.&lt;br /&gt;
*Build functions service oid tree.&lt;br /&gt;
*Merge MIB ANS.1 file to NMS.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
===uIP===&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Download Download]&lt;br /&gt;
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]&lt;br /&gt;
===lwIP===&lt;br /&gt;
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]&lt;br /&gt;
*[http://www.nongnu.org/lwip/ Documentation]&lt;br /&gt;
===HTML===&lt;br /&gt;
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript&lt;br /&gt;
===SNMP===&lt;br /&gt;
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents&lt;br /&gt;
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number&lt;br /&gt;
*[http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ASN.1]: Abstract Syntax Notation One (ASN.1):Specification of basic notation&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
	<entry>
		<id>http://www.opencircuits.com/index.php?title=UIP&amp;diff=19617</id>
		<title>UIP</title>
		<link rel="alternate" type="text/html" href="http://www.opencircuits.com/index.php?title=UIP&amp;diff=19617"/>
		<updated>2010-08-04T13:05:06Z</updated>

		<summary type="html">&lt;p&gt;Thai: /* SNMP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki describes how to use uIP (a Light-weight TCP/IP stack) for developing ethernet applications for 8/16-bit embedded system (see [{{SERVER}}/Ethernet_Module Ethernet_Module]).&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.&lt;br /&gt;
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Bug List==&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from buffalo router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
*DHCP&lt;br /&gt;
**dhcp client fault from main router&lt;br /&gt;
**occasionally cannot access webserver with dhcp&lt;br /&gt;
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been &amp;quot;reset&amp;quot;, and the connection is ok again.&lt;br /&gt;
*SMTP&lt;br /&gt;
**some router cannot used SMTP module&lt;br /&gt;
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function&lt;br /&gt;
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
*32kB constant limitations&lt;br /&gt;
**see if webserver can be stored in flash in file system&lt;br /&gt;
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]&lt;br /&gt;
**porting snmp to uip&lt;br /&gt;
**reference to lwip&lt;br /&gt;
**a API(or any method) to let other system to talk to our device OR by scpi, modbus&lt;br /&gt;
*https by SSL&lt;br /&gt;
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)&lt;br /&gt;
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Porting==&lt;br /&gt;
===CVS Repository===&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Attribute !! Value&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Host || uip-stack.cvs.sourceforge.net&lt;br /&gt;
|-&lt;br /&gt;
| Repository Path || /cvsroot/uip-stack&lt;br /&gt;
|-&lt;br /&gt;
| Connection Type || pserver&lt;br /&gt;
|-&lt;br /&gt;
| User || anonymous&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Patches===&lt;br /&gt;
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]&lt;br /&gt;
*uip-patch-1.0-01.diff (minimal)&lt;br /&gt;
**'''uip.c'''&lt;br /&gt;
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869&lt;br /&gt;
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)&lt;br /&gt;
**'''uip.h'''&lt;br /&gt;
***Change line 1070 to&amp;lt;br&amp;gt;#      define HTONS(n) (u16_t)(((((u16_t) (n)) &amp;lt;&amp;lt; 8)&amp;amp;0xff00) | ((((u16_t) (n)) &amp;gt;&amp;gt; 8)&amp;amp;0x00ff))&lt;br /&gt;
**'''psock.c'''&lt;br /&gt;
***Change line 188 to&amp;lt;br&amp;gt;s-&amp;gt;sendptr = (u8_t*) buf;&lt;br /&gt;
***Change lines 276, 303 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)(psock-&amp;gt;bufptr), psock-&amp;gt;bufsize);&lt;br /&gt;
***Change line 334 to&amp;lt;br&amp;gt;buf_setup(&amp;amp;psock-&amp;gt;buf, (u8_t*)buffer, buffersize);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
*Include the following files to use the uIP stack&lt;br /&gt;
**timer.c&lt;br /&gt;
**uip.c&lt;br /&gt;
**uip_arp.c&lt;br /&gt;
**psock.c&lt;br /&gt;
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.&lt;br /&gt;
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.&lt;br /&gt;
*uip-config.h: configuration for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uIP Ethernet Application==&lt;br /&gt;
*The following applications are modified from the demo applications in uIP.&lt;br /&gt;
&lt;br /&gt;
===DHCP Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dhcpc_8bit dhcpc_8bit]&lt;br /&gt;
*Enable UDP in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_UDP             1&lt;br /&gt;
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in &amp;quot;uip-config.h&amp;quot;&lt;br /&gt;
      #define UIP_CONF_BUFFER_SIZE     1536&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Web Server===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=webserver_8bit webserver_8bit]&lt;br /&gt;
====add-on====&lt;br /&gt;
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.&lt;br /&gt;
   GET /index.html HTTP/1.1&lt;br /&gt;
   GET /abc.shtml HTTP/1.1&lt;br /&gt;
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.&lt;br /&gt;
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request&lt;br /&gt;
   GET /abc.shtml?val=500.0&amp;amp;button=Set HTTP/1.1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Resolver===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=dns_resolv_8bit dns_resolv_8bit]&lt;br /&gt;
*The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address. It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.&lt;br /&gt;
*When a hostname has been resolved (or found to be non-existant), the resolver code calls a callback function called resolv_found() that must be implemented by the module that uses the resolver.&lt;br /&gt;
*Router Setting&lt;br /&gt;
**Special attention should be paid to router setting, when the DNS Server address is acquired by DHCP.&lt;br /&gt;
**The DNS Resolver module assumes that the DNS server can support DNS TYPE of ANY, MX, CNAME and A. See http://www.networksorcery.com/enp/protocol/dns.htm for definitions of these options.&lt;br /&gt;
*In case the router itself does not support these options, the router should be set to deliver a DNS Server address which support these options.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SMTP Mail Client===&lt;br /&gt;
*Use project [http://chungyan5.no-ip.org/vc/?root=smtpc_8bit smtpc_8bit]&lt;br /&gt;
*The SMTP client searches the ip address of the mail server by a DNS call. It then logins to the server with the email account name and address using AUTH LOGIN. If login is successful, the mail is sent to the list of recipients.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SNMP Agent (Not implemented yet)===&lt;br /&gt;
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]&lt;br /&gt;
*It belongs to the Application Layer, as in HTTP.&lt;br /&gt;
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.&lt;br /&gt;
&lt;br /&gt;
====Components in a SNMP System====&lt;br /&gt;
*Network Management Station (NMS)&lt;br /&gt;
**This is a client, initiating SNMP communication.&lt;br /&gt;
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.&lt;br /&gt;
*SNMP Agents&lt;br /&gt;
**These are servers, responding to one or multiple NMS requests.&lt;br /&gt;
*Management Information Base (MIB)&lt;br /&gt;
**A special collection of variables managed by the SNMP agents.&lt;br /&gt;
**MIB has a tree-like structure.&lt;br /&gt;
**An Object Identifier (OID) is given for each node.&lt;br /&gt;
**Data are stored at the end-nodes.&lt;br /&gt;
**Private variables may be constructed under the &amp;quot;enterprise&amp;quot; sub-tree.&lt;br /&gt;
**The OID for &amp;quot;enterprise&amp;quot; can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].&lt;br /&gt;
&lt;br /&gt;
====Abstract Syntax Notation====&lt;br /&gt;
*Each MIB variable contains several attributes, such as data type, access type and object identifier.&lt;br /&gt;
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
===uIP===&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]&lt;br /&gt;
*[http://www.sics.se/~adam/uip/index.php/Download Download]&lt;br /&gt;
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]&lt;br /&gt;
===lwIP===&lt;br /&gt;
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]&lt;br /&gt;
*[http://www.nongnu.org/lwip/ Documentation]&lt;br /&gt;
===HTML===&lt;br /&gt;
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript&lt;br /&gt;
===SNMP===&lt;br /&gt;
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents&lt;br /&gt;
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number&lt;br /&gt;
*[http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ASN.1]: Abstract Syntax Notation One (ASN.1):Specification of basic notation&lt;/div&gt;</summary>
		<author><name>Thai</name></author>
		
	</entry>
</feed>