ip.h

Go to the documentation of this file.
00001 /*##############################################################################
00002 
00003 nIP - nano IP stack
00004 
00005 File        : ip.h
00006 
00007 Description : Internet Protocol
00008 
00009 Copyright notice:
00010 
00011 Copyright (C) 2005 -
00012 Andreas Dittrich, dittrich@informatik.hu-berlin.de
00013 Jon Kowal, kowal@informatik.hu-berlin.de
00014 
00015 This program is free software; you can redistribute it and/or
00016 modify it under the terms of the GNU General Public License
00017 as published by the Free Software Foundation; either version 2
00018 of the License, or (at your option) any later version.
00019 
00020 This program is distributed in the hope that it will be useful,
00021 but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00023 GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License
00026 along with this program; if not, write to the Free Software
00027 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00028 
00029 ##############################################################################*/
00030 
00031 #ifndef _NIP_IP_H
00032  #define _NIP_IP_H
00033 
00034 #include "nip_init.h"
00035 #include "net_if.h"
00036 
00037 /** activate this option to disable memory management for icmp */
00038 // #define NIP_ICMP_TEST_NO_MEM_MGR
00039 
00040 
00041 #define NIP_IP_DEFAULT_HEADER_SIZE  20
00042 #define NIP_IP_DEFAULT_VERSION      4
00043 #define NIP_IP_TTL  64
00044 
00045 #define NIP_IGMP_MAX_REPORT_DELAY  10
00046 
00047 #ifndef NIP_IP_MAX_HOST_GROUPS
00048         #define NIP_IP_MAX_HOST_GROUPS  1
00049 #endif
00050 
00051 #if NIP_IP_MAX_HOST_GROUPS <= 255
00052 typedef uint8_t  nip_host_group_id_t;
00053 #elif NIP_IP_MAX_HOST_GRUOPS <= 65536
00054 typedef uint16_t nip_host_group_id_t;
00055 #else
00056 typedef uint32_t nip_host_group_id_t;
00057 #endif
00058 
00059 
00060 /** \name IP protocol types */
00061 /** see "Assigned Numbers" RFC for complete list */
00062 //@{
00063 #define NIP_IP_PROTO_ICMP    01
00064 #define NIP_IP_PROTO_IGMP    02
00065 #define NIP_IP_PROTO_IP      04
00066 #define NIP_IP_PROTO_TCP     06
00067 #define NIP_IP_PROTO_UDP     17
00068 //@}
00069 
00070 
00071 typedef uint8_t nip_ip_addr[4];
00072 
00073 
00074 struct IP_HEADER{
00075         unsigned int     ihl:4;     // 4-Bit version, 4-Bit header length
00076         unsigned int     version:4;
00077         uint8_t     tos;       // type of servive
00078         uint16_t    total_length;
00079         uint16_t    id;
00080         uint16_t    frag_offset;
00081         uint8_t     ttl;
00082         uint8_t     protocol;
00083         uint16_t    checksum;
00084         nip_ip_addr src_addr;
00085         nip_ip_addr dst_addr;
00086 }
00087 #ifndef DOXYGEN
00088 __attribute__((packed))
00089 #endif
00090 ;
00091 
00092 typedef enum
00093 {
00094         NIP_ICMP_T_ECHO_REP          = 0,
00095         NIP_ICMP_T_DST_UNREACH       = 3 ,
00096         NIP_ICMP_T_SRC_QUENCH        = 4,
00097         NIP_ICMP_T_ECHO_REQ          = 8,
00098         NIP_ICMP_T_ROUTER_ADV        = 9 ,
00099         NIP_ICMP_T_ROUTER_SOL        = 10,
00100         NIP_ICMP_T_TIME_EXCEED       = 11,
00101         NIP_ICMP_T_PARAM_PROBL       = 12,
00102         NIP_ICMP_T_TIMESTAMP         = 13,
00103         NIP_ICMP_T_TIMESTAMP_REP     = 14,
00104         NIP_ICMP_T_ADDR_MASK_REQ     = 15,
00105         NIP_ICMP_T_ADDR_MASK_REP     = 18,
00106         NIP_ICMP_T_TRACEROUTE        = 30,
00107         NIP_ICMP_T_DATAGRAM_CONV_ERR = 31,
00108         NIP_ICMP_T_MOBILE_HOST_REDIR = 32,
00109         NIP_ICMP_T_IPV6_WHERE_ARE_U  = 33,
00110         NIP_ICMP_T_IPV6_I_AM_HERE    = 34,
00111         NIP_ICMP_T_MOBILE_REG_REQ    = 35,
00112         NIP_ICMP_T_MOBILE_REG_RES    = 36,
00113         NIP_ICMP_T_DOMAIN_NAME_REQ   = 37,
00114         NIP_ICMP_T_DOMAIN_NAME_REP   = 38,
00115         NIP_ICMP_T_SKIP              = 39,
00116         NIP_ICMP_T_PHOTURIS          = 40
00117 }
00118 #ifndef DOXYGEN
00119 __attribute__((packed))
00120 #endif
00121 nip_icmp_type_t;
00122 
00123 struct ICMP_HEADER{
00124         nip_icmp_type_t type;
00125         uint8_t  code;
00126         uint16_t checksum;
00127         uint16_t id;
00128         uint16_t seq;
00129 }
00130 #ifndef DOXYGEN
00131 __attribute__((packed))
00132 #endif
00133 ;
00134 
00135 typedef enum
00136 {
00137         NIP_IP_GROUP_NON = 0,  /** Membership configuration unused */
00138         NIP_IP_GROUP_DELAYING, /** Notify network about host group membership*/
00139         NIP_IP_GROUP_IDLE,     /** Group membership in use */
00140 } nip_ip_group_membership_stat_t;
00141 
00142 
00143 struct nip_ip_group_membership
00144 {
00145 
00146         uint8_t addr[4];         /**< host group address */
00147         uint8_t member_cnt;      /**< number of members who subscribed to the group*/
00148         nip_net_if_id_t if_id;   /**< network interface to receive multicasts on */
00149         #if NIP_IGMP_ENABLE == 1
00150         nip_time_t      t_report;/**< time at which to report in DELAYING state */
00151         #endif
00152         nip_ip_group_membership_stat_t state;
00153 }
00154 #ifndef DOXYGEN
00155 __attribute__((packed))
00156 #endif
00157 ;
00158 
00159 #define NIP_IGMP_VERTYPE_QUERY  0x11
00160 #define NIP_IGMP_VERTYPE_REPORT 0x12
00161 
00162 struct nip_igmp_msg
00163 {
00164         uint8_t  ver_type;
00165         uint8_t  unused;
00166         uint16_t checksum;
00167         uint8_t  addr[4];
00168 }
00169 #ifndef DOXYGEN
00170 __attribute__((packed))
00171 #endif
00172 ;
00173 
00174 void nip_ip_disp_receive( void );
00175 void nip_ip_disp_send( void );
00176 
00177 extern uint8_t nip_ip_localhost[4];
00178 extern uint8_t nip_ip_broadcast[4];
00179 extern uint8_t nip_ip_null[4];
00180 
00181 void nip_ip_addr_set     ( nip_net_if_id_t if_id, uint8_t *addr );
00182 void nip_ip_subnet_set   ( nip_net_if_id_t if_id, uint8_t *mask );
00183 void nip_ip_addr_autoconf( nip_net_if_id_t if_id );
00184 
00185 nip_net_if_trans_t *nip_ip_route( uint8_t *target_addr, nip_net_if_id_t if_id,
00186         nip_net_if_trans_t *trans );
00187 
00188 nip_error_t nip_ip_join_host_group( nip_net_if_id_t if_id, uint8_t *addr );
00189 void nip_ip_disp_check_group( void );
00190 void nip_igmp_disp_receive( void );
00191 void nip_ip_query_groups( nip_net_if_id_t if_id );
00192 
00193 void nip_ip_up( nip_net_if_id_t if_id );
00194 void nip_ip_down( nip_net_if_id_t if_id );
00195 
00196 #endif /* _NIP_IP_H */

Generated on Thu Jul 10 01:09:29 2008 for NIP by  doxygen 1.5.5