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, uint32 type, 82 struct net_protocol_module_info **_module); 83 status_t (*put_domain_receiving_protocol)(struct net_domain *domain, uint32 type); 84 85 // devices 86 status_t (*register_device_deframer)(struct net_device *device, 87 net_deframe_func deframeFunc); 88 status_t (*unregister_device_deframer)(struct net_device *device); 89 90 status_t (*register_domain_device_handler)(struct net_device *device, 91 int32 type, struct net_domain *domain); 92 status_t (*register_device_handler)(struct net_device *device, int32 type, 93 net_receive_func receiveFunc, void *cookie); 94 status_t (*unregister_device_handler)(struct net_device *device, int32 type); 95 96 status_t (*register_device_monitor)(struct net_device *device, 97 struct net_device_monitor *monitor); 98 status_t (*unregister_device_monitor)(struct net_device *device, 99 struct net_device_monitor *monitor); 100 101 status_t (*device_link_changed)(struct net_device *device); 102 status_t (*device_removed)(struct net_device *device); 103 104 status_t (*device_enqueue_buffer)(struct net_device *device, 105 struct net_buffer *buffer); 106 107 // Utility Functions 108 109 // notification 110 status_t (*notify_socket)(struct net_socket *socket, uint8 event, int32 value); 111 112 // checksum 113 uint16 (*checksum)(uint8 *buffer, size_t length); 114 115 // fifo 116 status_t (*init_fifo)(struct net_fifo *fifo, const char *name, size_t maxBytes); 117 void (*uninit_fifo)(struct net_fifo *fifo); 118 status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, struct net_buffer *buffer); 119 ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags, 120 bigtime_t timeout, struct net_buffer **_buffer); 121 status_t (*clear_fifo)(struct net_fifo *fifo); 122 status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *, struct net_socket *, 123 uint8 event, struct net_buffer *); 124 125 // timer 126 void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data); 127 void (*set_timer)(struct net_timer *timer, bigtime_t delay); 128 bool (*cancel_timer)(struct net_timer *timer); 129 bool (*is_timer_active)(struct net_timer *timer); 130 }; 131 132 #endif // NET_STACK_H 133