Changes in uspace/srv/net/ethip/ethip_nic.c [96c0b7b:02a09ed] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip_nic.c
r96c0b7b r02a09ed 37 37 #include <adt/list.h> 38 38 #include <async.h> 39 #include < bool.h>39 #include <stdbool.h> 40 40 #include <errno.h> 41 41 #include <fibril_synch.h> … … 68 68 rc = loc_category_get_id("nic", &iplink_cat, IPC_FLAG_BLOCKING); 69 69 if (rc != EOK) { 70 log_msg(L VL_ERROR, "Failed resolving category 'nic'.");70 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed resolving category 'nic'."); 71 71 fibril_mutex_unlock(ðip_discovery_lock); 72 72 return ENOENT; … … 75 75 rc = loc_category_get_svcs(iplink_cat, &svcs, &count); 76 76 if (rc != EOK) { 77 log_msg(L VL_ERROR, "Failed getting list of IP links.");77 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed getting list of IP links."); 78 78 fibril_mutex_unlock(ðip_discovery_lock); 79 79 return EIO; … … 93 93 94 94 if (!already_known) { 95 log_msg(L VL_DEBUG, "Found NIC '%lu'",95 log_msg(LOG_DEFAULT, LVL_DEBUG, "Found NIC '%lu'", 96 96 (unsigned long) svcs[i]); 97 97 rc = ethip_nic_open(svcs[i]); 98 98 if (rc != EOK) 99 log_msg(L VL_ERROR, "Could not open NIC.");99 log_msg(LOG_DEFAULT, LVL_ERROR, "Could not open NIC."); 100 100 } 101 101 } … … 110 110 111 111 if (nic == NULL) { 112 log_msg(L VL_ERROR, "Failed allocating NIC structure. "112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. " 113 113 "Out of memory."); 114 114 return NULL; … … 121 121 } 122 122 123 static ethip_link_addr_t *ethip_nic_addr_new(i plink_srv_addr_t *addr)123 static ethip_link_addr_t *ethip_nic_addr_new(inet_addr_t *addr) 124 124 { 125 125 ethip_link_addr_t *laddr = calloc(1, sizeof(ethip_link_addr_t)); 126 127 126 if (laddr == NULL) { 128 log_msg(L VL_ERROR, "Failed allocating NIC address structure. "127 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC address structure. " 129 128 "Out of memory."); 130 129 return NULL; 131 130 } 132 131 133 132 link_initialize(&laddr->addr_list); 134 laddr->addr.ipv4 = addr->ipv4; 133 laddr->addr = *addr; 134 135 135 return laddr; 136 136 } … … 150 150 static int ethip_nic_open(service_id_t sid) 151 151 { 152 ethip_nic_t *nic;153 int rc;154 152 bool in_list = false; 155 153 nic_address_t nic_address; 156 157 log_msg(L VL_DEBUG, "ethip_nic_open()");158 nic = ethip_nic_new();154 155 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_open()"); 156 ethip_nic_t *nic = ethip_nic_new(); 159 157 if (nic == NULL) 160 158 return ENOMEM; 161 162 rc = loc_service_get_name(sid, &nic->svc_name);163 if (rc != EOK) { 164 log_msg(L VL_ERROR, "Failed getting service name.");165 goto error; 166 } 167 159 160 int rc = loc_service_get_name(sid, &nic->svc_name); 161 if (rc != EOK) { 162 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed getting service name."); 163 goto error; 164 } 165 168 166 nic->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 0); 169 167 if (nic->sess == NULL) { 170 log_msg(L VL_ERROR, "Failed connecting '%s'", nic->svc_name);171 goto error; 172 } 173 168 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed connecting '%s'", nic->svc_name); 169 goto error; 170 } 171 174 172 nic->svc_id = sid; 175 173 176 174 rc = nic_callback_create(nic->sess, ethip_nic_cb_conn, nic); 177 175 if (rc != EOK) { 178 log_msg(L VL_ERROR, "Failed creating callback connection "176 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating callback connection " 179 177 "from '%s'", nic->svc_name); 180 178 goto error; 181 179 } 182 180 183 log_msg(L VL_DEBUG, "Opened NIC '%s'", nic->svc_name);181 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened NIC '%s'", nic->svc_name); 184 182 list_append(&nic->nic_list, ðip_nic_list); 185 183 in_list = true; … … 191 189 rc = nic_get_address(nic->sess, &nic_address); 192 190 if (rc != EOK) { 193 log_msg(L VL_ERROR, "Error getting MAC address of NIC '%s'.",191 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting MAC address of NIC '%s'.", 194 192 nic->svc_name); 195 193 goto error; 196 194 } 197 198 mac48_decode(nic_address.address, &nic->mac_addr);195 196 addr48(nic_address.address, nic->mac_addr); 199 197 200 198 rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE); 201 199 if (rc != EOK) { 202 log_msg(L VL_ERROR, "Error activating NIC '%s'.",200 log_msg(LOG_DEFAULT, LVL_ERROR, "Error activating NIC '%s'.", 203 201 nic->svc_name); 204 202 goto error; 205 203 } 206 204 207 log_msg(LVL_DEBUG, "Initialized IP link service, MAC = 0x%" PRIx64, 208 nic->mac_addr.addr); 205 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,"); 209 206 210 207 return EOK; … … 227 224 ipc_call_t *call) 228 225 { 229 log_msg(L VL_DEBUG, "ethip_nic_addr_changed()");226 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed()"); 230 227 async_answer_0(callid, ENOTSUP); 231 228 } … … 238 235 size_t size; 239 236 240 log_msg(L VL_DEBUG, "ethip_nic_received() nic=%p", nic);237 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_received() nic=%p", nic); 241 238 242 239 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 243 240 if (rc != EOK) { 244 log_msg(L VL_DEBUG, "data_write_accept() failed");241 log_msg(LOG_DEFAULT, LVL_DEBUG, "data_write_accept() failed"); 245 242 return; 246 243 } 247 244 248 log_msg(L VL_DEBUG, "Ethernet PDU contents (%zu bytes)",245 log_msg(LOG_DEFAULT, LVL_DEBUG, "Ethernet PDU contents (%zu bytes)", 249 246 size); 250 247 251 log_msg(L VL_DEBUG, "call ethip_received");248 log_msg(LOG_DEFAULT, LVL_DEBUG, "call ethip_received"); 252 249 rc = ethip_received(&nic->iplink, data, size); 253 log_msg(L VL_DEBUG, "free data");250 log_msg(LOG_DEFAULT, LVL_DEBUG, "free data"); 254 251 free(data); 255 252 256 log_msg(L VL_DEBUG, "ethip_nic_received() done, rc=%d", rc);253 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_received() done, rc=%d", rc); 257 254 async_answer_0(callid, rc); 258 255 } … … 261 258 ipc_call_t *call) 262 259 { 263 log_msg(L VL_DEBUG, "ethip_nic_device_state()");260 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_device_state()"); 264 261 async_answer_0(callid, ENOTSUP); 265 262 } … … 269 266 ethip_nic_t *nic = (ethip_nic_t *)arg; 270 267 271 log_msg(L VL_DEBUG, "ethnip_nic_cb_conn()");268 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethnip_nic_cb_conn()"); 272 269 273 270 while (true) { … … 298 295 int ethip_nic_discovery_start(void) 299 296 { 300 int rc; 301 302 rc = loc_register_cat_change_cb(ethip_nic_cat_change_cb); 303 if (rc != EOK) { 304 log_msg(LVL_ERROR, "Failed registering callback for NIC " 297 int rc = loc_register_cat_change_cb(ethip_nic_cat_change_cb); 298 if (rc != EOK) { 299 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering callback for NIC " 305 300 "discovery (%d).", rc); 306 301 return rc; 307 302 } 308 303 309 304 return ethip_nic_check_new(); 310 305 } … … 312 307 ethip_nic_t *ethip_nic_find_by_iplink_sid(service_id_t iplink_sid) 313 308 { 314 log_msg(L VL_DEBUG, "ethip_nic_find_by_iplink_sid(%u)",309 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid(%u)", 315 310 (unsigned) iplink_sid); 316 311 317 312 list_foreach(ethip_nic_list, link) { 318 log_msg(L VL_DEBUG, "ethip_nic_find_by_iplink_sid - element");313 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - element"); 319 314 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t, 320 315 nic_list); 321 316 322 317 if (nic->iplink_sid == iplink_sid) { 323 log_msg(L VL_DEBUG, "ethip_nic_find_by_iplink_sid - found %p", nic);318 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - found %p", nic); 324 319 return nic; 325 320 } 326 321 } 327 322 328 log_msg(L VL_DEBUG, "ethip_nic_find_by_iplink_sid - not found");323 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - not found"); 329 324 return NULL; 330 325 } … … 333 328 { 334 329 int rc; 335 log_msg(L VL_DEBUG, "ethip_nic_send(size=%zu)", size);330 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_send(size=%zu)", size); 336 331 rc = nic_send_frame(nic->sess, data, size); 337 log_msg(L VL_DEBUG, "nic_send_frame -> %d", rc);332 log_msg(LOG_DEFAULT, LVL_DEBUG, "nic_send_frame -> %d", rc); 338 333 return rc; 339 334 } 340 335 341 int ethip_nic_addr_add(ethip_nic_t *nic, iplink_srv_addr_t *addr) 342 { 343 ethip_link_addr_t *laddr; 344 345 log_msg(LVL_DEBUG, "ethip_nic_addr_add()"); 346 laddr = ethip_nic_addr_new(addr); 336 int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr) 337 { 338 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_add()"); 339 340 ethip_link_addr_t *laddr = ethip_nic_addr_new(addr); 347 341 if (laddr == NULL) 348 342 return ENOMEM; 349 343 350 344 list_append(&laddr->addr_list, &nic->addr_list); 351 345 return EOK; 352 346 } 353 347 354 int ethip_nic_addr_remove(ethip_nic_t *nic, iplink_srv_addr_t *addr) 355 { 356 ethip_link_addr_t *laddr; 357 358 log_msg(LVL_DEBUG, "ethip_nic_addr_remove()"); 359 360 laddr = ethip_nic_addr_find(nic, addr); 348 int ethip_nic_addr_remove(ethip_nic_t *nic, inet_addr_t *addr) 349 { 350 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_remove()"); 351 352 ethip_link_addr_t *laddr = ethip_nic_addr_find(nic, addr); 361 353 if (laddr == NULL) 362 354 return ENOENT; 363 355 364 356 list_remove(&laddr->addr_list); 365 357 ethip_link_addr_delete(laddr); … … 368 360 369 361 ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *nic, 370 i plink_srv_addr_t *addr)371 { 372 log_msg(L VL_DEBUG, "ethip_nic_addr_find()");373 362 inet_addr_t *addr) 363 { 364 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_find()"); 365 374 366 list_foreach(nic->addr_list, link) { 375 367 ethip_link_addr_t *laddr = list_get_instance(link, 376 368 ethip_link_addr_t, addr_list); 377 378 if ( addr->ipv4 == laddr->addr.ipv4)369 370 if (inet_addr_compare(addr, &laddr->addr)) 379 371 return laddr; 380 372 } 381 373 382 374 return NULL; 383 375 }
Note:
See TracChangeset
for help on using the changeset viewer.