2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
12 #include <util/list.h>
15 #define NET_STACK_MODULE_NAME "network/stack/v1"
18 struct net_address_module_info
;
19 struct net_protocol_module_info
;
21 typedef struct net_buffer net_buffer
;
22 typedef struct net_device net_device
;
23 typedef struct net_domain net_domain
;
24 typedef struct net_socket net_socket
;
29 typedef struct net_fifo
{
40 typedef void (*net_timer_func
)(struct net_timer
* timer
, void* data
);
42 typedef struct net_timer
{
43 struct list_link link
;
50 typedef status_t (*net_deframe_func
)(net_device
* device
, net_buffer
* buffer
);
51 typedef status_t (*net_receive_func
)(void* cookie
, net_device
* device
,
55 B_DEVICE_GOING_UP
= 1,
57 B_DEVICE_BEING_REMOVED
,
60 typedef struct net_device_monitor
{
61 struct list_link link
;
64 status_t (*receive
)(struct net_device_monitor
* monitor
,
65 struct net_buffer
* buffer
);
66 void (*event
)(struct net_device_monitor
* monitor
, int32 event
);
69 typedef struct ancillary_data_header
{
73 } ancillary_data_header
;
75 typedef struct ancillary_data_container ancillary_data_container
;
78 #define B_NET_FRAME_TYPE(super, sub) (((int32)(super) << 16) | (sub))
79 // Use this when registering a device handler, see net/if_types.h for
80 // the possible "super" values. Input values are in host byte order.
85 B_NET_FRAME_TYPE_IPV4
= 0x0001,
86 B_NET_FRAME_TYPE_IPV6
= 0x0002,
87 B_NET_FRAME_TYPE_IPX
= 0x0003,
88 B_NET_FRAME_TYPE_APPLE_TALK
= 0x0004,
90 B_NET_FRAME_TYPE_ALL
= 0x0000
94 struct net_stack_module_info
{
97 status_t (*register_domain
)(int family
, const char* name
,
98 struct net_protocol_module_info
* module
,
99 struct net_address_module_info
* addressModule
,
100 net_domain
** _domain
);
101 status_t (*unregister_domain
)(net_domain
* domain
);
102 net_domain
* (*get_domain
)(int family
);
104 status_t (*register_domain_protocols
)(int family
, int type
, int protocol
,
106 status_t (*register_domain_datalink_protocols
)(int family
, int type
,
108 status_t (*register_domain_receiving_protocol
)(int family
, int type
,
109 const char* moduleName
);
111 status_t (*get_domain_receiving_protocol
)(net_domain
* domain
,
112 uint32 type
, struct net_protocol_module_info
** _module
);
113 status_t (*put_domain_receiving_protocol
)(net_domain
* domain
,
117 status_t (*register_device_deframer
)(net_device
* device
,
118 net_deframe_func deframeFunc
);
119 status_t (*unregister_device_deframer
)(net_device
* device
);
121 status_t (*register_domain_device_handler
)(net_device
* device
,
122 int32 type
, net_domain
* domain
);
123 status_t (*register_device_handler
)(net_device
* device
,
124 int32 type
, net_receive_func receiveFunc
, void* cookie
);
125 status_t (*unregister_device_handler
)(net_device
* device
, int32 type
);
127 status_t (*register_device_monitor
)(net_device
* device
,
128 struct net_device_monitor
* monitor
);
129 status_t (*unregister_device_monitor
)(net_device
* device
,
130 struct net_device_monitor
* monitor
);
132 status_t (*device_link_changed
)(net_device
* device
);
133 status_t (*device_removed
)(net_device
* device
);
135 status_t (*device_enqueue_buffer
)(net_device
* device
,
141 status_t (*notify_socket
)(net_socket
* socket
, uint8 event
, int32 value
);
144 uint16 (*checksum
)(uint8
* buffer
, size_t length
);
147 status_t (*init_fifo
)(net_fifo
* fifo
, const char* name
, size_t maxBytes
);
148 void (*uninit_fifo
)(net_fifo
* fifo
);
149 status_t (*fifo_enqueue_buffer
)(net_fifo
* fifo
, net_buffer
* buffer
);
150 ssize_t (*fifo_dequeue_buffer
)(net_fifo
* fifo
, uint32 flags
,
151 bigtime_t timeout
, net_buffer
** _buffer
);
152 status_t (*clear_fifo
)(net_fifo
* fifo
);
153 status_t (*fifo_socket_enqueue_buffer
)(net_fifo
* fifo
,
154 net_socket
* socket
, uint8 event
, net_buffer
* buffer
);
157 void (*init_timer
)(net_timer
* timer
, net_timer_func hook
,
159 void (*set_timer
)(net_timer
* timer
, bigtime_t delay
);
160 bool (*cancel_timer
)(net_timer
* timer
);
161 status_t (*wait_for_timer
)(net_timer
* timer
);
162 bool (*is_timer_active
)(net_timer
* timer
);
163 bool (*is_timer_running
)(net_timer
* timer
);
166 bool (*is_syscall
)(void);
167 bool (*is_restarted_syscall
)(void);
168 void (*store_syscall_restart_timeout
)(bigtime_t timeout
);
169 bigtime_t (*restore_syscall_restart_timeout
)(void);
172 ancillary_data_container
* (*create_ancillary_data_container
)();
173 void (*delete_ancillary_data_container
)(
174 ancillary_data_container
* container
);
175 status_t (*add_ancillary_data
)(ancillary_data_container
* container
,
176 const ancillary_data_header
* header
, const void* data
,
177 void (*destructor
)(const ancillary_data_header
*, void*),
178 void** _allocatedData
);
179 status_t (*remove_ancillary_data
)(ancillary_data_container
* container
,
180 void* data
, bool destroy
);
181 void* (*move_ancillary_data
)(ancillary_data_container
* from
,
182 ancillary_data_container
* to
);
183 void* (*next_ancillary_data
)(ancillary_data_container
* container
,
184 void* previousData
, ancillary_data_header
* _header
);
188 #endif // NET_STACK_H