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 18 struct net_address_module_info; 19 struct net_protocol_module_info; 20 21 struct net_buffer; 22 struct net_device; 23 struct net_domain; 24 struct net_socket; 25 struct net_timer; 26 27 struct net_fifo { 28 benaphore lock; 29 sem_id notify; 30 int32 waiting; 31 32 size_t max_bytes; 33 size_t current_bytes; 34 35 struct list buffers; 36 }; 37 38 typedef void (*net_timer_func)(struct net_timer *timer, void *data); 39 40 struct net_timer { 41 struct list_link link; 42 net_timer_func hook; 43 void *data; 44 bigtime_t due; 45 }; 46 47 typedef int32 (*net_deframe_func)(struct net_device *device, struct net_buffer *buffer); 48 typedef status_t (*net_receive_func)(void *cookie, struct net_device *, 49 struct net_buffer *buffer); 50 51 enum { 52 B_DEVICE_GOING_UP = 1, 53 B_DEVICE_GOING_DOWN, 54 B_DEVICE_BEING_REMOVED, 55 }; 56 57 struct net_device_monitor { 58 struct list_link link; 59 void *cookie; 60 61 status_t (*receive)(struct net_device_monitor *monitor, 62 struct net_buffer *buffer); 63 void (*event)(struct net_device_monitor *monitor, int32 event); 64 }; 65 66 struct net_stack_module_info { 67 module_info info; 68 69 status_t (*register_domain)(int family, const char *name, 70 struct net_protocol_module_info *module, 71 struct net_address_module_info *addressModule, 72 struct net_domain **_domain); 73 status_t (*unregister_domain)(struct net_domain *domain); 74 struct net_domain *(*get_domain)(int family); 75 76 status_t (*register_domain_protocols)(int family, int type, int protocol, ...); 77 status_t (*register_domain_datalink_protocols)(int family, int type, ...); 78 status_t (*register_domain_receiving_protocol)(int family, int type, 79 const char *moduleName); 80 81 status_t (*get_domain_receiving_protocol)(struct net_domain *domain, 82 uint32 type, struct net_protocol_module_info **_module); 83 status_t (*put_domain_receiving_protocol)(struct net_domain *domain, 84 uint32 type); 85 86 // devices 87 status_t (*register_device_deframer)(struct net_device *device, 88 net_deframe_func deframeFunc); 89 status_t (*unregister_device_deframer)(struct net_device *device); 90 91 status_t (*register_domain_device_handler)(struct net_device *device, 92 int32 type, struct net_domain *domain); 93 status_t (*register_device_handler)(struct net_device *device, int32 type, 94 net_receive_func receiveFunc, void *cookie); 95 status_t (*unregister_device_handler)(struct net_device *device, int32 type); 96 97 status_t (*register_device_monitor)(struct net_device *device, 98 struct net_device_monitor *monitor); 99 status_t (*unregister_device_monitor)(struct net_device *device, 100 struct net_device_monitor *monitor); 101 102 status_t (*device_link_changed)(struct net_device *device); 103 status_t (*device_removed)(struct net_device *device); 104 105 status_t (*device_enqueue_buffer)(struct net_device *device, 106 struct net_buffer *buffer); 107 108 // Utility Functions 109 110 // notification 111 status_t (*notify_socket)(struct net_socket *socket, uint8 event, 112 int32 value); 113 114 // checksum 115 uint16 (*checksum)(uint8 *buffer, size_t length); 116 117 // fifo 118 status_t (*init_fifo)(struct net_fifo *fifo, const char *name, 119 size_t maxBytes); 120 void (*uninit_fifo)(struct net_fifo *fifo); 121 status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, 122 struct net_buffer *buffer); 123 ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags, 124 bigtime_t timeout, struct net_buffer **_buffer); 125 status_t (*clear_fifo)(struct net_fifo *fifo); 126 status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *fifo, 127 struct net_socket *socket, uint8 event, 128 struct net_buffer *buffer); 129 130 // timer 131 void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data); 132 void (*set_timer)(struct net_timer *timer, bigtime_t delay); 133 bool (*cancel_timer)(struct net_timer *timer); 134 bool (*is_timer_active)(struct net_timer *timer); 135 }; 136 137 #endif // NET_STACK_H 138