xref: /haiku/headers/private/net/net_stack.h (revision 8a819b17e4ebb40461954432b6b8cfb29946b32f)
1 /*
2  * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NET_STACK_H
6 #define NET_STACK_H
7 
8 
9 #include <lock.h>
10 #include <util/list.h>
11 
12 #include <module.h>
13 
14 
15 #define NET_STACK_MODULE_NAME "network/stack/v1"
16 
17 struct net_fifo {
18 	benaphore	lock;
19 	sem_id		notify;
20 	int32		waiting;
21 
22 	size_t		max_bytes;
23 	size_t		current_bytes;
24 
25 	struct list	buffers;
26 };
27 
28 typedef void (*net_timer_func)(struct net_timer *timer, void *data);
29 
30 struct net_timer {
31 	struct list_link link;
32 	net_timer_func	hook;
33 	void			*data;
34 	bigtime_t		due;
35 };
36 
37 typedef int32 (*net_deframe_func)(struct net_device *device, struct net_buffer *buffer);
38 typedef status_t (*net_receive_func)(void *cookie, struct net_device *,
39 	struct net_buffer *buffer);
40 
41 enum {
42 	B_DEVICE_GOING_UP = 1,
43 	B_DEVICE_GOING_DOWN,
44 	B_DEVICE_BEING_REMOVED,
45 };
46 
47 struct net_device_monitor {
48 	struct list_link link;
49 	void *cookie;
50 
51 	status_t (*receive)(struct net_device_monitor *monitor,
52 		struct net_buffer *buffer);
53 	void (*event)(struct net_device_monitor *monitor, int32 event);
54 };
55 
56 struct net_stack_module_info {
57 	module_info info;
58 
59 	status_t (*register_domain)(int family, const char *name,
60 					struct net_protocol_module_info *module,
61 					struct net_address_module_info *addressModule,
62 					struct net_domain **_domain);
63 	status_t (*unregister_domain)(struct net_domain *domain);
64 	struct net_domain *(*get_domain)(int family);
65 
66 	status_t (*register_domain_protocols)(int family, int type, int protocol, ...);
67 	status_t (*register_domain_datalink_protocols)(int family, int type, ...);
68 	status_t (*register_domain_receiving_protocol)(int family, int type,
69 					const char *moduleName);
70 
71 	status_t (*get_domain_receiving_protocol)(struct net_domain *domain, uint32 type,
72 					struct net_protocol_module_info **_module);
73 	status_t (*put_domain_receiving_protocol)(struct net_domain *domain, uint32 type);
74 
75 	// devices
76 	status_t (*register_device_deframer)(struct net_device *device,
77 					net_deframe_func deframeFunc);
78 	status_t (*unregister_device_deframer)(struct net_device *device);
79 
80 	status_t (*register_domain_device_handler)(struct net_device *device,
81 					int32 type, struct net_domain *domain);
82 	status_t (*register_device_handler)(struct net_device *device, int32 type,
83 					net_receive_func receiveFunc, void *cookie);
84 	status_t (*unregister_device_handler)(struct net_device *device, int32 type);
85 
86 	status_t (*register_device_monitor)(struct net_device *device,
87 		struct net_device_monitor *monitor);
88 	status_t (*unregister_device_monitor)(struct net_device *device,
89 		struct net_device_monitor *monitor);
90 
91 	status_t (*device_link_changed)(struct net_device *device);
92 	status_t (*device_removed)(struct net_device *device);
93 
94 	// Utility Functions
95 
96 	// notification
97 	status_t	(*notify_socket)(struct net_socket *socket, uint8 event, int32 value);
98 
99 	// checksum
100 	uint16 (*checksum)(uint8 *buffer, size_t length);
101 
102 	// fifo
103 	status_t (*init_fifo)(struct net_fifo *fifo, const char *name, size_t maxBytes);
104 	void (*uninit_fifo)(struct net_fifo *fifo);
105 	status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, struct net_buffer *buffer);
106 	ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags,
107 					bigtime_t timeout, struct net_buffer **_buffer);
108 	status_t (*clear_fifo)(struct net_fifo *fifo);
109 	status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *, struct net_socket *,
110 					uint8 event, struct net_buffer *);
111 
112 	// timer
113 	void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data);
114 	void (*set_timer)(struct net_timer *timer, bigtime_t delay);
115 	bool (*cancel_timer)(struct net_timer *timer);
116 	bool (*is_timer_active)(struct net_timer *timer);
117 };
118 
119 #endif	// NET_STACK_H
120