Changeset 24ab58b3 in mainline for uspace/lib/net
- Timestamp:
- 2010-04-06T11:41:48Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 14f1db0
- Parents:
- 4dd8529
- Location:
- uspace/lib/net
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/il/ip_remote.c
r4dd8529 r24ab58b3 28 28 29 29 /** @addtogroup ip 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * IP interface implementation for standalone remote modules. 35 * @see ip_interface.h 36 * @see il_interface.h 34 * 35 * IP interface implementation for standalone remote modules. 36 * 37 * @see ip_interface.h 38 * @see il_interface.h 39 * 37 40 */ 38 41 … … 48 51 #include <ip_messages.h> 49 52 50 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){ 51 return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr); 53 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, 54 in_addr_t netmask, in_addr_t gateway) 55 { 56 return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, 57 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, 58 (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr); 52 59 } 53 60 54 int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){ 55 return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver); 61 int ip_bind_service(services_t service, int protocol, services_t me, 62 async_client_conn_t receiver, tl_received_msg_t tl_received_msg) 63 { 64 return (int) bind_service(service, (ipcarg_t) protocol, me, service, 65 receiver); 56 66 } 57 67 58 int ip_connect_module(services_t service){ 68 int ip_connect_module(services_t service) 69 { 59 70 return connect_to_service(SERVICE_IP); 60 71 } 61 72 62 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){ 73 int ip_device_req(int ip_phone, device_id_t device_id, services_t service) 74 { 63 75 return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service); 64 76 } 65 77 66 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){ 67 aid_t message_id; 68 ipcarg_t result; 78 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, 79 const struct sockaddr *destination, socklen_t addrlen, 80 device_id_t *device_id, ip_pseudo_header_ref *header, size_t *headerlen) 81 { 82 if ((!destination) || (addrlen == 0)) 83 return EINVAL; 84 85 if ((!device_id) || (header) || (headerlen)) 86 return EBADMEM; 87 88 *header = NULL; 89 69 90 ipc_call_t answer; 70 71 if(!(destination && (addrlen > 0))){ 72 return EINVAL; 73 } 74 if(!(device_id && header && headerlen)){ 75 return EBADMEM; 76 } 77 78 *header = NULL; 79 message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer); 80 if((async_data_write_start(ip_phone, destination, addrlen) == EOK) 81 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK) 82 && (*headerlen > 0)){ 91 aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, 92 (ipcarg_t) protocol, &answer); 93 94 if ((async_data_write_start(ip_phone, destination, addrlen) == EOK) 95 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK) 96 && (*headerlen > 0)) { 83 97 *header = (ip_pseudo_header_ref) malloc(*headerlen); 84 if (*header){85 if (async_data_read_start(ip_phone, * header, * headerlen) != EOK){98 if (*header) { 99 if (async_data_read_start(ip_phone, *header, *headerlen) != EOK) 86 100 free(*header); 87 }88 101 } 89 102 } 103 104 ipcarg_t result; 90 105 async_wait_for(message_id, &result); 91 92 if ((result != EOK) && (*header)){106 107 if ((result != EOK) && (*header)) 93 108 free(*header); 94 }else{109 else 95 110 *device_id = IPC_GET_DEVICE(&answer); 96 }111 97 112 return (int) result; 98 113 } 99 114 100 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){ 101 return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension); 115 int ip_packet_size_req(int ip_phone, device_id_t device_id, 116 packet_dimension_ref packet_dimension) 117 { 118 return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, 119 packet_dimension); 102 120 } 103 121 104 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){ 105 return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error); 122 int ip_received_error_msg(int ip_phone, device_id_t device_id, 123 packet_t packet, services_t target, services_t error) 124 { 125 return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, 126 packet_get_id(packet), target, error); 106 127 } 107 128 108 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){ 109 return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error); 129 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, 130 services_t sender, services_t error) 131 { 132 return generic_send_msg(ip_phone, NET_IL_SEND, device_id, 133 packet_get_id(packet), sender, error); 110 134 } 111 135 112 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){ 113 return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr); 136 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway) 137 { 138 return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, 139 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr); 114 140 } 115 141 -
uspace/lib/net/include/netif.h
r4dd8529 r24ab58b3 129 129 extern packet_t netif_packet_get_1(size_t content); 130 130 131 /** Processes the netif module messages. 132 * @param[in] callid The message identifier. 133 * @param[in] call The message parameters. 134 * @param[out] answer The message answer parameters. 135 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 136 * @returns EOK on success. 137 * @returns ENOTSUP if the message is not known. 138 * @returns Other error codes as defined for each specific module message function. 139 * @see netif_interface.h 140 * @see IS_NET_NETIF_MESSAGE() 131 /** Process the netif module messages. 132 * 133 * @param[in] name Module name. 134 * @param[in] callid The message identifier. 135 * @param[in] call The message parameters. 136 * @param[out] answer The message answer parameters. 137 * @param[out] answer_count The last parameter for the actual answer 138 * in the answer parameter. 139 * 140 * @return EOK on success. 141 * @return ENOTSUP if the message is not known. 142 * @return Other error codes as defined for each specific module message function. 143 * 144 * @see netif_interface.h 145 * @see IS_NET_NETIF_MESSAGE() 146 * 141 147 */ 142 extern int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 148 extern int netif_message(const char *, ipc_callid_t, ipc_call_t *, 149 ipc_call_t *, int *); 143 150 144 151 /** Initializes the netif module. -
uspace/lib/net/include/netif_nil_bundle.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int netif_nil_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int netif_nil_module_start(async_client_conn_t client_connection);39 extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int netif_nil_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/include/netif_standalone.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int netif_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int netif_module_start(async_client_conn_t client_connection);39 extern int netif_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int netif_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/include/nil_module.h
r4dd8529 r24ab58b3 42 42 43 43 /** Module initialization. 44 * Is called by the module_start() function. 45 * @param[in] net_phone The networking moduel phone. 46 * @returns EOK on success. 47 * @returns Other error codes as defined for each specific module initialize function. 44 * 45 * Is called by the module_start() function. 46 * 47 * @param[in] net_phone The networking moduel phone. 48 * 49 * @return EOK on success. 50 * @return Other error codes as defined for each specific module initialize function. 51 * 48 52 */ 49 extern int nil_initialize(int net_phone);53 extern int nil_initialize(int); 50 54 51 55 /** Message processing function. 52 * @param[in] callid The message identifier. 53 * @param[in] call The message parameters. 54 * @param[out] answer The message answer parameters. 55 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 56 * @returns EOK on success. 57 * @returns ENOTSUP if the message is not known. 58 * @returns Other error codes as defined for each specific module message function. 59 * @see nil_interface.h 60 * @see IS_NET_NIL_MESSAGE() 56 * 57 * @param[in] name Module name. 58 * @param[in] callid The message identifier. 59 * @param[in] call The message parameters. 60 * @param[out] answer The message answer parameters. 61 * @param[out] answer_count The last parameter for the actual answer 62 * in the answer parameter. 63 * 64 * @return EOK on success. 65 * @return ENOTSUP if the message is not known. 66 * @return Other error codes as defined for each specific 67 * module message function. 68 * 69 * @see nil_interface.h 70 * @see IS_NET_NIL_MESSAGE() 71 * 61 72 */ 62 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 73 extern int nil_message(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *, 74 int *); 63 75 64 76 #endif -
uspace/lib/net/include/nil_standalone.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int nil_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int nil_module_start(async_client_conn_t client_connection);39 extern int nil_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int nil_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/netif/netif.c
r4dd8529 r24ab58b3 176 176 } 177 177 178 /** Registers the device notification receiver, the network interface layer module. 179 * @param[in] device_id The device identifier. 180 * @param[in] phone The network interface layer module phone. 181 * @returns EOK on success. 182 * @returns ENOENT if there is no such device. 183 * @returns ELIMIT if there is another module registered. 184 */ 185 static int register_message(device_id_t device_id, int phone){ 186 ERROR_DECLARE; 187 178 /** Register the device notification receiver, the network interface layer module. 179 * 180 * @param[in] name Module name. 181 * @param[in] device_id The device identifier. 182 * @param[in] phone The network interface layer module phone. 183 * 184 * @return EOK on success. 185 * @return ENOENT if there is no such device. 186 * @return ELIMIT if there is another module registered. 187 * 188 */ 189 static int register_message(const char *name, device_id_t device_id, int phone) 190 { 191 ERROR_DECLARE; 192 188 193 device_ref device; 189 190 194 ERROR_PROPAGATE(find_device(device_id, &device)); 191 if(device->nil_phone > 0) {195 if(device->nil_phone > 0) 192 196 return ELIMIT; 193 }197 194 198 device->nil_phone = phone; 195 printf("New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone); 196 return EOK; 197 } 198 199 int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 200 ERROR_DECLARE; 201 199 printf("%s: Receiver of device %d registered (phone: %d)\n", 200 name, device->device_id, device->nil_phone); 201 return EOK; 202 } 203 204 int netif_message(const char *name, ipc_callid_t callid, ipc_call_t *call, 205 ipc_call_t *answer, int *answer_count) 206 { 207 ERROR_DECLARE; 208 202 209 size_t length; 203 210 device_stats_t stats; 204 211 packet_t packet; 205 212 measured_string_t address; 206 207 // printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST); 213 208 214 *answer_count = 0; 209 215 switch(IPC_GET_METHOD(*call)){ … … 211 217 return EOK; 212 218 case NET_NETIF_PROBE: 213 return netif_probe_req(0, IPC_GET_DEVICE(call), NETIF_GET_IRQ(call), NETIF_GET_IO(call)); 219 return netif_probe_req(0, IPC_GET_DEVICE(call), 220 NETIF_GET_IRQ(call), NETIF_GET_IO(call)); 214 221 case IPC_M_CONNECT_TO_ME: 215 222 fibril_rwlock_write_lock(&netif_globals.lock); 216 ERROR_CODE = register_message(IPC_GET_DEVICE(call), IPC_GET_PHONE(call)); 223 ERROR_CODE = register_message(name, IPC_GET_DEVICE(call), 224 IPC_GET_PHONE(call)); 217 225 fibril_rwlock_write_unlock(&netif_globals.lock); 218 226 return ERROR_CODE; 219 227 case NET_NETIF_SEND: 220 ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, &packet, IPC_GET_PACKET(call))); 221 return netif_send_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_SENDER(call)); 228 ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, 229 &packet, IPC_GET_PACKET(call))); 230 return netif_send_msg(0, IPC_GET_DEVICE(call), packet, 231 IPC_GET_SENDER(call)); 222 232 case NET_NETIF_START: 223 233 return netif_start_req(0, IPC_GET_DEVICE(call)); 224 234 case NET_NETIF_STATS: 225 235 fibril_rwlock_read_lock(&netif_globals.lock); 226 if (! ERROR_OCCURRED(async_data_read_receive(&callid, &length))){227 if (length < sizeof(device_stats_t)){236 if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) { 237 if (length < sizeof(device_stats_t)) 228 238 ERROR_CODE = EOVERFLOW; 229 }else{ 230 if(! ERROR_OCCURRED(netif_get_device_stats(IPC_GET_DEVICE(call), &stats))){ 231 ERROR_CODE = async_data_read_finalize(callid, &stats, sizeof(device_stats_t)); 232 } 239 else { 240 if (!ERROR_OCCURRED(netif_get_device_stats( 241 IPC_GET_DEVICE(call), &stats))) 242 ERROR_CODE = async_data_read_finalize(callid, &stats, 243 sizeof(device_stats_t)); 233 244 } 234 245 } … … 239 250 case NET_NETIF_GET_ADDR: 240 251 fibril_rwlock_read_lock(&netif_globals.lock); 241 if(! ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), &address))){ 252 if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), 253 &address))) 242 254 ERROR_CODE = measured_strings_reply(&address, 1); 243 }244 255 fibril_rwlock_read_unlock(&netif_globals.lock); 245 256 return ERROR_CODE; 246 257 } 258 247 259 return netif_specific_message(callid, call, answer, answer_count); 248 260 } -
uspace/lib/net/netif/netif_nil_bundle.c
r4dd8529 r24ab58b3 45 45 #include <netif.h> 46 46 47 /** Distributes the messages between the module parts. 48 * @param[in] callid The message identifier. 49 * @param[in] call The message parameters. 50 * @param[out] answer The message answer parameters. 51 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 52 * @returns EOK on success. 53 * @returns ENOTSUP if the message is not known. 54 * @returns Other error codes as defined for each specific module message function. 47 /** Distribute the messages between the module parts. 48 * 49 * @param[in] name Module name. 50 * @param[in] callid The message identifier. 51 * @param[in] call The message parameters. 52 * @param[out] answer The message answer parameters. 53 * @param[out] answer_count The last parameter for the actual 54 * answer in the answer parameter. 55 * 56 * @return EOK on success. 57 * @return ENOTSUP if the message is not known. 58 * @return Other error codes as defined for each specific module message function. 59 * 55 60 */ 56 int netif_nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 57 if(IS_NET_NIL_MESSAGE(call) || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)){ 58 return nil_message(callid, call, answer, answer_count); 59 }else{ 60 return netif_message(callid, call, answer, answer_count); 61 } 61 int netif_nil_module_message(const char *name, ipc_callid_t callid, 62 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 63 { 64 if (IS_NET_NIL_MESSAGE(call) 65 || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)) 66 return nil_message(name, callid, call, answer, answer_count); 67 else 68 return netif_message(name, callid, call, answer, answer_count); 62 69 } 63 70 -
uspace/lib/net/netif/netif_standalone.c
r4dd8529 r24ab58b3 41 41 #include <netif_standalone.h> 42 42 43 /** Delegates the messages to the netif_message() function. 44 * @param[in] callid The message identifier. 45 * @param[in] call The message parameters. 46 * @param[out] answer The message answer parameters. 47 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 48 * @returns EOK on success. 49 * @returns ENOTSUP if the message is not known. 50 * @returns Other error codes as defined for each specific module message function. 43 /** Delegate the messages to the netif_message() function. 44 * 45 * @param[in] name Module name. 46 * @param[in] callid The message identifier. 47 * @param[in] call The message parameters. 48 * @param[out] answer The message answer parameters. 49 * @param[out] answer_count The last parameter for the actual answer 50 * in the answer parameter. 51 * 52 * @return EOK on success. 53 * @return ENOTSUP if the message is not known. 54 * @return Other error codes as defined for each specific module message function. 55 * 51 56 */ 52 int netif_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 53 return netif_message(callid, call, answer, answer_count); 57 int netif_module_message(const char *name, ipc_callid_t callid, 58 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 59 { 60 return netif_message(name, callid, call, answer, answer_count); 54 61 } 55 62
Note:
See TracChangeset
for help on using the changeset viewer.