xref: /haiku/headers/private/net/net_stack.h (revision a7028ce6802b20c7fea03c8b4defa0770a50b850)
1 /*
2  * Copyright 2006, 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_buffer *buffer);
39 
40 struct net_stack_module_info {
41 	module_info info;
42 
43 	status_t (*register_domain)(int family, const char *name,
44 					struct net_protocol_module_info *module,
45 					struct net_address_module_info *addressModule,
46 					struct net_domain **_domain);
47 	status_t (*unregister_domain)(struct net_domain *domain);
48 	struct net_domain *(*get_domain)(int family);
49 
50 	status_t (*register_domain_protocols)(int family, int type, int protocol, ...);
51 	status_t (*register_domain_datalink_protocols)(int family, int type, ...);
52 	status_t (*register_domain_receiving_protocol)(int family, int type,
53 					const char *moduleName);
54 
55 	status_t (*get_domain_receiving_protocol)(struct net_domain *domain, uint32 type,
56 					struct net_protocol_module_info **_module);
57 	status_t (*put_domain_receiving_protocol)(struct net_domain *domain, uint32 type);
58 
59 	// devices
60 	status_t (*register_device_deframer)(struct net_device *device,
61 					net_deframe_func deframeFunc);
62 	status_t (*unregister_device_deframer)(struct net_device *device);
63 
64 	status_t (*register_domain_device_handler)(struct net_device *device,
65 					int32 type, struct net_domain *domain);
66 	status_t (*register_device_handler)(struct net_device *device, int32 type,
67 					net_receive_func receiveFunc, void *cookie);
68 	status_t (*unregister_device_handler)(struct net_device *device, int32 type);
69 
70 	status_t (*register_device_monitor)(struct net_device *device,
71 					net_receive_func receiveFunc, void *cookie);
72 	status_t (*unregister_device_monitor)(struct net_device *device,
73 					net_receive_func receiveFunc, void *cookie);
74 
75 	status_t (*device_removed)(struct net_device *device);
76 
77 	// Utility Functions
78 
79 	// notification
80 	status_t	(*notify_socket)(struct net_socket *socket, uint8 event, int32 value);
81 
82 	// checksum
83 	uint16 (*checksum)(uint8 *buffer, size_t length);
84 
85 	// fifo
86 	status_t (*init_fifo)(struct net_fifo *fifo, const char *name, size_t maxBytes);
87 	void (*uninit_fifo)(struct net_fifo *fifo);
88 	status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, struct net_buffer *buffer);
89 	ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags,
90 					bigtime_t timeout, struct net_buffer **_buffer);
91 	status_t (*clear_fifo)(struct net_fifo *fifo);
92 
93 	// timer
94 	void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data);
95 	void (*set_timer)(struct net_timer *timer, bigtime_t delay);
96 };
97 
98 #endif	// NET_STACK_H
99