Changeset 59ecd4a in mainline for uspace/lib/net/netif/netif.c
- Timestamp:
- 2010-04-04T21:41:47Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5db9084
- Parents:
- 36a75a2 (diff), ee7e82a9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/netif/netif.c
r36a75a2 r59ecd4a 44 44 #include <ipc/services.h> 45 45 46 #include "../err.h" 47 #include "../messages.h" 48 #include "../modules.h" 49 50 #include "../structures/packet/packet.h" 51 #include "../structures/packet/packet_client.h" 52 #include "../structures/measured_strings.h" 53 54 #include "../include/device.h" 55 #include "../include/netif_interface.h" 56 #include "../include/nil_interface.h" 57 58 #include "netif.h" 59 #include "netif_messages.h" 60 #include "netif_module.h" 61 62 /** Network interface module global data. 63 */ 64 extern netif_globals_t netif_globals; 46 #include <net_err.h> 47 #include <net_messages.h> 48 #include <net_modules.h> 49 #include <packet/packet.h> 50 #include <packet/packet_client.h> 51 #include <adt/measured_strings.h> 52 #include <net_device.h> 53 #include <netif_interface.h> 54 #include <nil_interface.h> 55 #include <netif.h> 56 #include <netif_messages.h> 57 #include <netif_module.h> 65 58 66 59 DEVICE_MAP_IMPLEMENT(device_map, device_t) 67 60 68 /** @name Message processing functions 69 */ 70 /*@{*/ 61 /** Network interface global data. 62 */ 63 netif_globals_t netif_globals; 64 65 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){ 66 int result; 67 68 fibril_rwlock_write_lock(&netif_globals.lock); 69 result = netif_probe_message(device_id, irq, io); 70 fibril_rwlock_write_unlock(&netif_globals.lock); 71 return result; 72 } 73 74 int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){ 75 int result; 76 77 fibril_rwlock_write_lock(&netif_globals.lock); 78 result = netif_send_message(device_id, packet, sender); 79 fibril_rwlock_write_unlock(&netif_globals.lock); 80 return result; 81 } 82 83 int netif_start_req(int netif_phone, device_id_t device_id){ 84 ERROR_DECLARE; 85 86 device_ref device; 87 int result; 88 int phone; 89 90 fibril_rwlock_write_lock(&netif_globals.lock); 91 if(ERROR_OCCURRED(find_device(device_id, &device))){ 92 fibril_rwlock_write_unlock(&netif_globals.lock); 93 return ERROR_CODE; 94 } 95 result = netif_start_message(device); 96 if(result > NETIF_NULL){ 97 phone = device->nil_phone; 98 fibril_rwlock_write_unlock(&netif_globals.lock); 99 nil_device_state_msg(phone, device_id, result); 100 return EOK; 101 }else{ 102 fibril_rwlock_write_unlock(&netif_globals.lock); 103 } 104 return result; 105 } 106 107 int netif_stop_req(int netif_phone, device_id_t device_id){ 108 ERROR_DECLARE; 109 110 device_ref device; 111 int result; 112 int phone; 113 114 fibril_rwlock_write_lock(&netif_globals.lock); 115 if(ERROR_OCCURRED(find_device(device_id, &device))){ 116 fibril_rwlock_write_unlock(&netif_globals.lock); 117 return ERROR_CODE; 118 } 119 result = netif_stop_message(device); 120 if(result > NETIF_NULL){ 121 phone = device->nil_phone; 122 fibril_rwlock_write_unlock(&netif_globals.lock); 123 nil_device_state_msg(phone, device_id, result); 124 return EOK; 125 }else{ 126 fibril_rwlock_write_unlock(&netif_globals.lock); 127 } 128 return result; 129 } 130 131 int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){ 132 int res; 133 134 fibril_rwlock_read_lock(&netif_globals.lock); 135 res = netif_get_device_stats(device_id, stats); 136 fibril_rwlock_read_unlock(&netif_globals.lock); 137 return res; 138 } 139 140 int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){ 141 ERROR_DECLARE; 142 143 measured_string_t translation; 144 145 if(!(address && data)){ 146 return EBADMEM; 147 } 148 fibril_rwlock_read_lock(&netif_globals.lock); 149 if(! ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))){ 150 *address = measured_string_copy(&translation); 151 ERROR_CODE = (*address) ? EOK : ENOMEM; 152 } 153 fibril_rwlock_read_unlock(&netif_globals.lock); 154 *data = (** address).value; 155 return ERROR_CODE; 156 } 157 158 int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){ 159 return EOK; 160 } 161 162 int find_device(device_id_t device_id, device_ref * device){ 163 if(! device){ 164 return EBADMEM; 165 } 166 *device = device_map_find(&netif_globals.device_map, device_id); 167 if(! * device){ 168 return ENOENT; 169 } 170 if((** device).state == NETIF_NULL) return EPERM; 171 return EOK; 172 } 173 174 void null_device_stats(device_stats_ref stats){ 175 bzero(stats, sizeof(device_stats_t)); 176 } 71 177 72 178 /** Registers the device notification receiver, the network interface layer module. … … 77 183 * @returns ELIMIT if there is another module registered. 78 184 */ 79 int register_message(device_id_t device_id, int phone); 80 81 /*@}*/ 82 83 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){ 84 int result; 85 86 fibril_rwlock_write_lock(&netif_globals.lock); 87 result = netif_probe_message(device_id, irq, io); 88 fibril_rwlock_write_unlock(&netif_globals.lock); 89 return result; 90 } 91 92 int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){ 93 int result; 94 95 fibril_rwlock_write_lock(&netif_globals.lock); 96 result = netif_send_message(device_id, packet, sender); 97 fibril_rwlock_write_unlock(&netif_globals.lock); 98 return result; 99 } 100 101 int netif_start_req(int netif_phone, device_id_t device_id){ 102 ERROR_DECLARE; 103 104 device_ref device; 105 int result; 106 int phone; 107 108 fibril_rwlock_write_lock(&netif_globals.lock); 109 if(ERROR_OCCURRED(find_device(device_id, &device))){ 110 fibril_rwlock_write_unlock(&netif_globals.lock); 111 return ERROR_CODE; 112 } 113 result = netif_start_message(device); 114 if(result > NETIF_NULL){ 115 phone = device->nil_phone; 116 fibril_rwlock_write_unlock(&netif_globals.lock); 117 nil_device_state_msg(phone, device_id, result); 118 return EOK; 119 }else{ 120 fibril_rwlock_write_unlock(&netif_globals.lock); 121 } 122 return result; 123 } 124 125 int netif_stop_req(int netif_phone, device_id_t device_id){ 126 ERROR_DECLARE; 127 128 device_ref device; 129 int result; 130 int phone; 131 132 fibril_rwlock_write_lock(&netif_globals.lock); 133 if(ERROR_OCCURRED(find_device(device_id, &device))){ 134 fibril_rwlock_write_unlock(&netif_globals.lock); 135 return ERROR_CODE; 136 } 137 result = netif_stop_message(device); 138 if(result > NETIF_NULL){ 139 phone = device->nil_phone; 140 fibril_rwlock_write_unlock(&netif_globals.lock); 141 nil_device_state_msg(phone, device_id, result); 142 return EOK; 143 }else{ 144 fibril_rwlock_write_unlock(&netif_globals.lock); 145 } 146 return result; 147 } 148 149 int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){ 150 int res; 151 152 fibril_rwlock_read_lock(&netif_globals.lock); 153 res = netif_get_device_stats(device_id, stats); 154 fibril_rwlock_read_unlock(&netif_globals.lock); 155 return res; 156 } 157 158 int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){ 159 ERROR_DECLARE; 160 161 measured_string_t translation; 162 163 if(!(address && data)){ 164 return EBADMEM; 165 } 166 fibril_rwlock_read_lock(&netif_globals.lock); 167 if(! ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))){ 168 *address = measured_string_copy(&translation); 169 ERROR_CODE = (*address) ? EOK : ENOMEM; 170 } 171 fibril_rwlock_read_unlock(&netif_globals.lock); 172 *data = (** address).value; 173 return ERROR_CODE; 174 } 175 176 int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){ 177 return EOK; 178 } 179 180 int find_device(device_id_t device_id, device_ref * device){ 181 if(! device){ 182 return EBADMEM; 183 } 184 *device = device_map_find(&netif_globals.device_map, device_id); 185 if(! * device){ 186 return ENOENT; 187 } 188 if((** device).state == NETIF_NULL) return EPERM; 189 return EOK; 190 } 191 192 void null_device_stats(device_stats_ref stats){ 193 bzero(stats, sizeof(device_stats_t)); 194 } 195 196 int register_message(device_id_t device_id, int phone){ 185 static int register_message(device_id_t device_id, int phone){ 197 186 ERROR_DECLARE; 198 187
Note:
See TracChangeset
for help on using the changeset viewer.