adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 1 | #ifndef __UIP_FW_H__ |
| 2 | #define __UIP_FW_H__ |
| 3 | |
| 4 | /** |
| 5 | * Representation of a uIP network interface. |
| 6 | */ |
| 7 | struct uip_fw_netif { |
| 8 | struct uip_fw_netif *next; /**< Pointer to the next interface when |
| 9 | linked in a list. */ |
| 10 | u16_t ipaddr[2]; /**< The IP address of this interface. */ |
| 11 | u16_t netmask[2]; /**< The netmask of the interface. */ |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 12 | u8_t (* output)(void); |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 13 | /**< A pointer to the function that |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 14 | sends a packet. */ |
| 15 | }; |
| 16 | |
| 17 | /** |
| 18 | * Intantiating macro for a uIP network interface. |
| 19 | * |
| 20 | * Example: |
| 21 | \code |
| 22 | struct uip_fw_netif slipnetif = |
| 23 | {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)}; |
| 24 | \endcode |
| 25 | * \param ip1,ip2,ip3,ip4 The IP address of the network interface. |
| 26 | * |
| 27 | * \param nm1,nm2,nm3,nm4 The netmask of the network interface. |
| 28 | * |
| 29 | * \param outputfunc A pointer to the output function of the network interface. |
| 30 | * |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 31 | * \hideinitializer |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 32 | */ |
| 33 | #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \ |
| 34 | NULL, \ |
| 35 | {HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \ |
| 36 | {HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \ |
| 37 | outputfunc |
| 38 | |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Set the IP address of a network interface. |
| 41 | * |
| 42 | * \param netif A pointer to the uip_fw_netif structure for the network interface. |
| 43 | * |
| 44 | * \param addr A pointer to an IP address. |
| 45 | * |
| 46 | * \hideinitializer |
| 47 | */ |
| 48 | #define uip_fw_setipaddr(netif, addr) \ |
| 49 | do { (netif)->ipaddr[0] = ((u16_t *)(addr))[0]; \ |
| 50 | (netif)->ipaddr[1] = ((u16_t *)(addr))[1]; } while(0) |
| 51 | /** |
| 52 | * Set the netmask of a network interface. |
| 53 | * |
| 54 | * \param netif A pointer to the uip_fw_netif structure for the network interface. |
| 55 | * |
| 56 | * \param addr A pointer to an IP address representing the netmask. |
| 57 | * |
| 58 | * \hideinitializer |
| 59 | */ |
| 60 | #define uip_fw_setnetmask(netif, addr) \ |
| 61 | do { (netif)->netmask[0] = ((u16_t *)(addr))[0]; \ |
| 62 | (netif)->netmask[1] = ((u16_t *)(addr))[1]; } while(0) |
| 63 | |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 64 | void uip_fw_init(void); |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 65 | u8_t uip_fw_forward(void); |
| 66 | u8_t uip_fw_output(void); |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 67 | void uip_fw_register(struct uip_fw_netif *netif); |
| 68 | void uip_fw_default(struct uip_fw_netif *netif); |
adamdunkels | 048a33f | 2004-02-16 20:48:53 +0000 | [diff] [blame^] | 69 | void uip_fw_periodic(void); |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 70 | |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * A non-error message that indicates that a packet should be |
| 74 | * processed locally. |
| 75 | * |
| 76 | * \hideinitializer |
| 77 | */ |
| 78 | #define UIP_FW_LOCAL 0 |
| 79 | |
| 80 | /** |
| 81 | * A non-error message that indicates that something went OK. |
| 82 | * |
| 83 | * \hideinitializer |
| 84 | */ |
| 85 | #define UIP_FW_OK 0 |
| 86 | |
| 87 | /** |
| 88 | * A non-error message that indicates that a packet was forwarded. |
| 89 | * |
| 90 | * \hideinitializer |
| 91 | */ |
| 92 | #define UIP_FW_FORWARDED 1 |
| 93 | |
| 94 | /** |
| 95 | * A non-error message that indicates that a zero-length packet |
| 96 | * transmission was attempted, and that no packet was sent. |
| 97 | * |
| 98 | * \hideinitializer |
| 99 | */ |
| 100 | #define UIP_FW_ZEROLEN 2 |
| 101 | |
| 102 | /** |
| 103 | * An error message that indicates that a packet that was too large |
| 104 | * for the outbound network interface was detected. |
| 105 | * |
| 106 | * \hideinitializer |
| 107 | */ |
| 108 | #define UIP_FW_TOOLARGE 3 |
| 109 | |
| 110 | /** |
| 111 | * An error message that indicates that no suitable interface could be |
| 112 | * found for an outbound packet. |
| 113 | * |
| 114 | * \hideinitializer |
| 115 | */ |
| 116 | #define UIP_FW_NOROUTE 4 |
| 117 | |
| 118 | /** |
| 119 | * An error message that indicates that a packet that should be |
| 120 | * forwarded or output was dropped. |
| 121 | * |
| 122 | * \hideinitializer |
| 123 | */ |
| 124 | #define UIP_FW_DROPPED 5 |
| 125 | |
adamdunkels | 048a33f | 2004-02-16 20:48:53 +0000 | [diff] [blame^] | 126 | |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 127 | #endif /* __UIP_FW_H__ */ |