00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _NIP_NET_IF_H
00032 #define _NIP_NET_IF_H
00033
00034 #include "nip_init.h"
00035 #include "mem.h"
00036 #include "os_core.h"
00037
00038
00039 #ifndef NIP_NET_IF_COUNT
00040
00041 #define NIP_NET_IF_COUNT 1
00042 #endif
00043
00044 #ifndef NIP_NET_IF_TRANS_COUNT
00045
00046
00047 #define NIP_NET_IF_TRANS_COUNT 2
00048 #endif
00049
00050 #define NIP_NET_MAX_TRANSMISSIONS NIP_NET_IF_TRANS_COUNT
00051
00052 #ifndef NIP_MAX_HW_ADDR_SIZE
00053
00054 #define NIP_MAX_HW_ADDR_SIZE 6
00055 #endif
00056
00057 #ifndef NIP_MAX_NET_ADDR_SIZE
00058
00059 #define NIP_MAX_NET_ADDR_SIZE 4
00060 #endif
00061
00062 #ifndef NIP_NET_LOOPBACK_ENABLE
00063
00064 #define NIP_NET_LOOPBACK_ENABLE 1
00065 #endif
00066
00067
00068 #define NIP_NET_NULL_TRANSMISSION NIP_NET_MAX_TRANSMISSIONS
00069
00070
00071 #if ( NIP_NET_MAX_TRANSMISSIONS < 255 )
00072 typedef uint8_t nip_net_trans_id_t;
00073 #elif ( NIP_NET_MAX_TRANSMISSIONS < 65535 )
00074 typedef uint16_t nip_net_trans_id_t;
00075 #else
00076 typedef uint32_t nip_net_trans_id_t;
00077 #endif
00078
00079
00080
00081
00082 #if ( NIP_NET_IF_COUNT < 0xFF )
00083 typedef uint8_t nip_net_if_id_t;
00084 #define NIP_NET_NO_IF 0xFF
00085 #elif ( NIP_NET_IF_COUNT < 0xFFFF )
00086 typedef uint16_t nip_net_if_id_t;
00087 #define NIP_NET_NO_IF 0xFFFF
00088 #else
00089 typedef uint32_t nip_net_if_id_t;
00090 #define NIP_NET_NO_IF 0xFFFFFFFF
00091 #endif
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #define NIP_PHY_IFF_UP 0x01
00102 #define NIP_PHY_IFF_BROADCAST 0x02
00103 #define NIP_PHY_IFF_MULTICAST 0x04
00104 #define NIP_PHY_IFF_NOARP 0x08
00105 #define NIP_PHY_IFF_LOOPBACK 0x10
00106 #define NIP_PHY_IFF_CNT_OVW 0x20
00107 #define NIP_PHY_IFF_CNT_RXE 0x40
00108 #define NIP_PHY_IFF_CNT_TXE 0x80
00109
00110
00111
00112
00113
00114
00115
00116 #ifdef NIP_NET_IF_CNT_OVERRUN
00117 #define NIP_PHY_LOG_OVW(net_if_ptr) net_if_ptr->phy_conf.stats.cnt_overrun++
00118 #else
00119 #define NIP_PHY_LOG_OVW(net_if_ptr)
00120 #endif
00121
00122
00123 #ifdef NIP_NET_IF_CNT_RXE
00124 #define NIP_PHY_LOG_RXE(net_if_ptr) net_if_ptr->phy_conf.stats.cnt_rx_err++
00125 #else
00126 #define NIP_PHY_LOG_RXE(net_if_ptr)
00127 #endif
00128
00129
00130 #ifdef NIP_NET_IF_CNT_TXE
00131 #define NIP_PHY_LOG_TXE(net_if_ptr) net_if_ptr->phy_conf.stats.cnt_tx_err++
00132 #else
00133 #define NIP_PHY_LOG_TXE(net_if_ptr)
00134 #endif
00135
00136
00137
00138
00139
00140 typedef uint8_t nip_phy_if_flags_t;
00141
00142
00143
00144
00145
00146
00147
00148 typedef enum
00149 {
00150 NIP_NET_IF_IDLE,
00151 NIP_NET_IF_RECEIVING,
00152 NIP_NET_IF_ROUTE,
00153 NIP_NET_IF_ROUTING,
00154 NIP_NET_IF_ROUTED,
00155 NIP_NET_IF_RESOLV_ADDR,
00156 NIP_NET_IF_RTS,
00157 NIP_NET_IF_SENDING,
00158 NIP_NET_IF_SEND_HNF,
00159 NIP_NET_IF_SEND_NRT,
00160 NIP_NET_IF_DONE
00161 }
00162 #ifndef DOXYGEN
00163 __attribute__((packed))
00164 #endif
00165 nip_net_trans_status_t;
00166
00167
00168
00169
00170
00171
00172 typedef enum
00173 {
00174 NIP_PHY_IF_OTHER,
00175 NIP_PHY_IF_ETH = 1
00176 }
00177 #ifndef DOXYGEN
00178 __attribute__((packed))
00179 #endif
00180 nip_phy_if_type_t;
00181
00182 typedef union
00183 {
00184
00185 struct
00186 {
00187 uint8_t dst_nw_addr[NIP_MAX_NET_ADDR_SIZE];
00188 uint8_t src_nw_addr[NIP_MAX_NET_ADDR_SIZE];
00189 uint8_t ll_nw_addr[NIP_MAX_NET_ADDR_SIZE];
00190 uint8_t ttl;
00191 uint16_t id;
00192 uint8_t protocol;
00193 }
00194 #ifndef DOXYGEN
00195 __attribute__((packed))
00196 #endif
00197 ip;
00198
00199
00200 struct
00201 {
00202 uint8_t dst_nw_addr[NIP_MAX_NET_ADDR_SIZE];
00203 uint8_t src_nw_addr[NIP_MAX_NET_ADDR_SIZE];
00204 uint16_t dst_port;
00205 uint16_t src_port;
00206 }
00207 #ifndef DOXYGEN
00208 __attribute__((packed))
00209 #endif
00210 tcp;
00211
00212
00213
00214 }
00215 #ifndef DOXYGEN
00216 __attribute__((packed))
00217 #endif
00218 nip_net_if_trans_params_t;
00219
00220
00221 typedef struct
00222 {
00223 uint8_t free_payload:1;
00224 uint8_t reset_status:1;
00225 uint8_t ll_broadcast:1;
00226 uint8_t deliverlocal:1;
00227 uint8_t forward:1;
00228 uint8_t unused:3;
00229 }
00230 #ifndef DOXYGEN
00231 __attribute__((packed))
00232 #endif
00233 nip_net_if_trans_flags_t;
00234
00235
00236 typedef struct
00237 {
00238 nip_net_if_id_t if_id;
00239 nip_net_trans_status_t status;
00240 nip_time_t time;
00241 uint8_t retrans_cnt;
00242 uint16_t header_size;
00243 uint16_t payload_size;
00244 uint16_t payload_off;
00245 nip_mem_handle_t header;
00246 nip_mem_handle_t payload;
00247 nip_net_if_trans_params_t params;
00248 nip_net_if_trans_flags_t flags;
00249 }
00250 #ifndef DOXYGEN
00251 __attribute__((packed))
00252 #endif
00253 nip_net_if_trans_t;
00254
00255
00256 typedef uint16_t nip_net_stats_cnt_t;
00257
00258
00259 typedef struct
00260 {
00261 #ifdef NIP_NET_IF_CNT_OVERRUN
00262 nip_net_stats_cnt_t cnt_overrun;
00263 #endif
00264
00265 #ifdef NIP_NET_IF_CNT_TXE
00266 nip_net_stats_cnt_t cnt_tx_err;
00267 #endif
00268
00269 #ifdef NIP_NET_IF_CNT_RXE
00270 nip_net_stats_cnt_t cnt_rx_err;
00271 #endif
00272
00273 #ifdef NIP_NET_IF_CNT_DISCARDED
00274 nip_net_stats_cnt_t cnt_discarded;
00275 #endif
00276
00277 #ifdef NIP_NET_IF_CNT_RECEIVED
00278 nip_net_stats_cnt_t cnt_received;
00279 #endif
00280
00281 }
00282 #ifndef DOXYGEN
00283 __attribute__((packed))
00284 #endif
00285 nip_net_if_stats_t;
00286
00287
00288
00289
00290
00291
00292 typedef struct
00293 {
00294 nip_phy_if_type_t type;
00295 nip_net_if_stats_t stats;
00296 nip_phy_if_flags_t flags;
00297 uint8_t hw_addr[NIP_MAX_HW_ADDR_SIZE];
00298 uint8_t hw_brdcst_addr[NIP_MAX_HW_ADDR_SIZE];
00299 uint8_t hw_addr_size;
00300 uint16_t rx_bytes;
00301 uint16_t rx_pos;
00302 uint16_t tx_bytes;
00303 uint16_t tx_pos;
00304
00305 nip_success_t (*open)( nip_net_if_id_t net_if_id );
00306
00307
00308
00309
00310
00311
00312
00313 nip_success_t (*close)( nip_net_if_id_t net_if_id );
00314
00315
00316
00317
00318
00319
00320 nip_error_t (*hard_send_init) (nip_net_if_id_t net_if_id, void *ll_target_addr,
00321 uint16_t type, void *daddr, void *saddr, uint16_t len);
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 uint16_t (*hard_send) (nip_net_if_id_t net_if_id, uint8_t* buffer, uint16_t count);
00339
00340
00341
00342
00343
00344
00345 uint16_t (*hard_read) (nip_net_if_id_t net_if_id, uint8_t* buffer, uint16_t count);
00346
00347
00348
00349
00350
00351
00352 nip_success_t (*hard_read_init) ( nip_net_if_id_t net_if_id );
00353
00354
00355
00356
00357 void (*hard_disp_recv)( void );
00358
00359
00360 }
00361 #ifndef DOXYGEN
00362 __attribute__((packed))
00363 #endif
00364 nip_phy_if_t;
00365
00366 typedef enum
00367 {
00368 NIP_IP_CONF_STAT_UNCONFIGURED = 0,
00369 NIP_IP_CONF_STAT_CONFIGURED
00370 }
00371 #ifndef DOXYGEN
00372 __attribute__((packed))
00373 #endif
00374 nip_if_ip_conf_stat_t;
00375
00376
00377 typedef struct nip_if_ip_conf
00378 {
00379 nip_if_ip_conf_stat_t state;
00380 uint8_t addr[4];
00381 uint8_t brdcst_addr[4];
00382 uint8_t subnet_mask[4];
00383 uint8_t std_gateway[4];
00384 #if NIP_DNS_ENABLE == 1
00385 uint8_t name_server[4];
00386 #endif
00387 }
00388 #ifndef DOXYGEN
00389 __attribute__((packed))
00390 #endif
00391 nip_if_ip_conf_t;
00392
00393
00394 typedef struct nip_net_if
00395 {
00396 nip_net_if_id_t id;
00397 nip_if_ip_conf_t ip_conf;
00398 nip_phy_if_t phy_conf;
00399 }
00400 #ifndef DOXYGEN
00401 __attribute__((packed))
00402 #endif
00403 nip_net_if_t;
00404
00405 #define NIP_IP_ADDR( if_id ) nip_net_if_list[if_id].ip_conf.addr
00406
00407 extern nip_net_if_t nip_net_if_list[];
00408 extern nip_net_if_trans_t nip_net_trans_list[];
00409
00410
00411 nip_net_if_id_t nip_net_if_create( nip_phy_if_type_t type );
00412 void nip_net_if_free ( nip_net_if_id_t id );
00413 nip_success_t nip_set_if_flags ( nip_net_if_id_t id, nip_phy_if_flags_t flags);
00414 nip_net_if_t *nip_net_if_ptr ( nip_net_if_id_t );
00415 nip_success_t nip_net_if_up ( nip_net_if_id_t );
00416 nip_success_t nip_net_if_down ( nip_net_if_id_t );
00417 void nip_reset_trans( nip_net_if_trans_t *trans );
00418
00419 #endif
00420