Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 56792a2 in mainline


Ignore:
Timestamp:
2012-02-27T19:52:41Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1cc8b42
Parents:
962f03b
Message:

Read MAC address from NIC.

Location:
uspace/srv/ethip
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/ethip/arp.c

    r962f03b r56792a2  
    4646#include "std.h"
    4747
    48 #define MY_ETH_ADDR 0xaafeedfaceee
    49 
    5048static int arp_send_packet(ethip_nic_t *nic, arp_eth_packet_t *packet);
    5149
     
    7371
    7472                        reply.opcode = aop_reply;
    75                         reply.sender_hw_addr.addr = MY_ETH_ADDR;
     73                        reply.sender_hw_addr = nic->mac_addr;
    7674                        reply.sender_proto_addr = laddr->addr;
    7775                        reply.target_hw_addr = packet.sender_hw_addr;
  • uspace/srv/ethip/ethip.c

    r962f03b r56792a2  
    177177
    178178        frame.dest.addr = 0xdeeedeeedeee;
    179         frame.src.addr =  0xaadeadbeeffe;
     179        frame.src       = nic->mac_addr;
    180180        frame.etype_len = ETYPE_IP;
    181181        frame.data = sdu->data;
  • uspace/srv/ethip/ethip.h

    r962f03b r56792a2  
    4444#include <sys/types.h>
    4545
    46 typedef struct ethip_nic {
    47         link_t nic_list;
    48         service_id_t svc_id;
    49         char *svc_name;
    50         async_sess_t *sess;
    51 
    52         iplink_srv_t iplink;
    53         service_id_t iplink_sid;
    54 
    55         /** List of IP addresses configured on this link */
    56         list_t addr_list; /* of ethip_link_addr_t */
    57 } ethip_nic_t;
    58 
    5946typedef struct {
    6047        link_t addr_list;
     
    6754        uint64_t addr;
    6855} mac48_addr_t;
     56
     57typedef struct ethip_nic {
     58        link_t nic_list;
     59        service_id_t svc_id;
     60        char *svc_name;
     61        async_sess_t *sess;
     62
     63        iplink_srv_t iplink;
     64        service_id_t iplink_sid;
     65
     66        /** MAC address */
     67        mac48_addr_t mac_addr;
     68        /** List of IP addresses configured on this link */
     69        list_t addr_list; /* of ethip_link_addr_t */
     70} ethip_nic_t;
    6971
    7072/** Ethernet frame */
  • uspace/srv/ethip/ethip_nic.c

    r962f03b r56792a2  
    4848#include "ethip.h"
    4949#include "ethip_nic.h"
     50#include "pdu.h"
    5051
    5152static int ethip_nic_open(service_id_t sid);
     
    152153        int rc;
    153154        bool in_list = false;
     155        nic_address_t nic_address;
    154156
    155157        log_msg(LVL_DEBUG, "ethip_nic_open()");
     
    187189                goto error;
    188190
     191        rc = nic_get_address(nic->sess, &nic_address);
     192        if (rc != EOK) {
     193                log_msg(LVL_ERROR, "Error getting MAC address of NIC '%s'.",
     194                    nic->svc_name);
     195                goto error;
     196        }
     197
     198        mac48_decode(nic_address.address, &nic->mac_addr);
     199
    189200        rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE);
    190201        if (rc != EOK) {
    191                 log_msg(LVL_ERROR, "Failed activating NIC '%s'.",
     202                log_msg(LVL_ERROR, "Error activating NIC '%s'.",
    192203                    nic->svc_name);
    193204                goto error;
    194205        }
    195206
    196         log_msg(LVL_DEBUG, "Initialized IP link service.");
     207        log_msg(LVL_DEBUG, "Initialized IP link service, MAC = 0x%" PRIx64,
     208            nic->mac_addr.addr);
    197209
    198210        return EOK;
  • uspace/srv/ethip/pdu.c

    r962f03b r56792a2  
    4646#include "pdu.h"
    4747
    48 static void mac48_encode(mac48_addr_t *addr, void *buf);
    49 static void mac48_decode(void *data, mac48_addr_t *addr);
    50 
    5148#define MAC48_BYTES 6
    5249
     
    116113}
    117114
    118 static void mac48_encode(mac48_addr_t *addr, void *buf)
     115void mac48_encode(mac48_addr_t *addr, void *buf)
    119116{
    120117        uint64_t val;
     
    127124}
    128125
    129 static void mac48_decode(void *data, mac48_addr_t *addr)
     126void mac48_decode(void *data, mac48_addr_t *addr)
    130127{
    131128        uint64_t val;
  • uspace/srv/ethip/pdu.h

    r962f03b r56792a2  
    4242extern int eth_pdu_encode(eth_frame_t *, void **, size_t *);
    4343extern int eth_pdu_decode(void *, size_t, eth_frame_t *);
     44extern void mac48_encode(mac48_addr_t *, void *);
     45extern void mac48_decode(void *, mac48_addr_t *);
    4446extern int arp_pdu_encode(arp_eth_packet_t *, void **, size_t *);
    4547extern int arp_pdu_decode(void *, size_t, arp_eth_packet_t *);
     48
    4649
    4750#endif
Note: See TracChangeset for help on using the changeset viewer.