Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/ethip/pdu.c

    r02a09ed rf0a2720  
    6262
    6363        hdr = (eth_header_t *)data;
    64         addr48(frame->src, hdr->src);
    65         addr48(frame->dest, hdr->dest);
     64        mac48_encode(&frame->src, hdr->src);
     65        mac48_encode(&frame->dest, hdr->dest);
    6666        hdr->etype_len = host2uint16_t_be(frame->etype_len);
    6767
     
    6969            frame->size);
    7070
    71         log_msg(LOG_DEFAULT, LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size);
     71        log_msg(LVL_DEBUG, "Encoding Ethernet frame "
     72            "src=%" PRIx64 " dest=%" PRIx64 " etype=%x",
     73            frame->src.addr, frame->dest.addr, frame->etype_len);
     74        log_msg(LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size);
    7275
    7376        *rdata = data;
     
    8184        eth_header_t *hdr;
    8285
    83         log_msg(LOG_DEFAULT, LVL_DEBUG, "eth_pdu_decode()");
     86        log_msg(LVL_DEBUG, "eth_pdu_decode()");
    8487
    8588        if (size < sizeof(eth_header_t)) {
    86                 log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
     89                log_msg(LVL_DEBUG, "PDU too short (%zu)", size);
    8790                return EINVAL;
    8891        }
     
    9598                return ENOMEM;
    9699
    97         addr48(hdr->src, frame->src);
    98         addr48(hdr->dest, frame->dest);
     100        mac48_decode(hdr->src, &frame->src);
     101        mac48_decode(hdr->dest, &frame->dest);
    99102        frame->etype_len = uint16_t_be2host(hdr->etype_len);
    100103
     
    102105            frame->size);
    103106
    104         log_msg(LOG_DEFAULT, LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size);
    105 
    106         return EOK;
     107        log_msg(LVL_DEBUG, "Decoding Ethernet frame "
     108            "src=%" PRIx64 " dest=%" PRIx64 " etype=%x",
     109            frame->src.addr, frame->dest.addr, frame->etype_len);
     110        log_msg(LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size);
     111
     112        return EOK;
     113}
     114
     115void mac48_encode(mac48_addr_t *addr, void *buf)
     116{
     117        uint64_t val;
     118        uint8_t *bbuf = (uint8_t *)buf;
     119        int i;
     120
     121        val = addr->addr;
     122        for (i = 0; i < MAC48_BYTES; i++)
     123                bbuf[i] = (val >> (8 * (MAC48_BYTES - i - 1))) & 0xff;
     124}
     125
     126void mac48_decode(void *data, mac48_addr_t *addr)
     127{
     128        uint64_t val;
     129        uint8_t *bdata = (uint8_t *)data;
     130        int i;
     131
     132        val = 0;
     133        for (i = 0; i < MAC48_BYTES; i++)
     134                val |= (uint64_t)bdata[i] << (8 * (MAC48_BYTES - i - 1));
     135
     136        addr->addr = val;
    107137}
    108138
     
    115145        uint16_t fopcode;
    116146
    117         log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_pdu_encode()");
     147        log_msg(LVL_DEBUG, "arp_pdu_encode()");
    118148
    119149        size = sizeof(arp_eth_packet_fmt_t);
     
    138168        pfmt->proto_addr_size = IPV4_ADDR_SIZE;
    139169        pfmt->opcode = host2uint16_t_be(fopcode);
    140         addr48(packet->sender_hw_addr, pfmt->sender_hw_addr);
     170        mac48_encode(&packet->sender_hw_addr, pfmt->sender_hw_addr);
    141171        pfmt->sender_proto_addr =
    142             host2uint32_t_be(packet->sender_proto_addr);
    143         addr48(packet->target_hw_addr, pfmt->target_hw_addr);
     172            host2uint32_t_be(packet->sender_proto_addr.ipv4);
     173        mac48_encode(&packet->target_hw_addr, pfmt->target_hw_addr);
    144174        pfmt->target_proto_addr =
    145             host2uint32_t_be(packet->target_proto_addr);
     175            host2uint32_t_be(packet->target_proto_addr.ipv4);
    146176
    147177        *rdata = data;
     
    155185        arp_eth_packet_fmt_t *pfmt;
    156186
    157         log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_pdu_decode()");
     187        log_msg(LVL_DEBUG, "arp_pdu_decode()");
    158188
    159189        if (size < sizeof(arp_eth_packet_fmt_t)) {
    160                 log_msg(LOG_DEFAULT, LVL_DEBUG, "ARP PDU too short (%zu)", size);
     190                log_msg(LVL_DEBUG, "ARP PDU too short (%zu)", size);
    161191                return EINVAL;
    162192        }
     
    165195
    166196        if (uint16_t_be2host(pfmt->hw_addr_space) != AHRD_ETHERNET) {
    167                 log_msg(LOG_DEFAULT, LVL_DEBUG, "HW address space != %u (%" PRIu16 ")",
     197                log_msg(LVL_DEBUG, "HW address space != %u (%" PRIu16 ")",
    168198                    AHRD_ETHERNET, uint16_t_be2host(pfmt->hw_addr_space));
    169199                return EINVAL;
     
    171201
    172202        if (uint16_t_be2host(pfmt->proto_addr_space) != 0x0800) {
    173                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")",
     203                log_msg(LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")",
    174204                    ETYPE_IP, uint16_t_be2host(pfmt->proto_addr_space));
    175205                return EINVAL;
     
    177207
    178208        if (pfmt->hw_addr_size != ETH_ADDR_SIZE) {
    179                 log_msg(LOG_DEFAULT, LVL_DEBUG, "HW address size != %zu (%zu)",
     209                log_msg(LVL_DEBUG, "HW address size != %zu (%zu)",
    180210                    (size_t)ETH_ADDR_SIZE, (size_t)pfmt->hw_addr_size);
    181211                return EINVAL;
     
    183213
    184214        if (pfmt->proto_addr_size != IPV4_ADDR_SIZE) {
    185                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Proto address size != %zu (%zu)",
     215                log_msg(LVL_DEBUG, "Proto address size != %zu (%zu)",
    186216                    (size_t)IPV4_ADDR_SIZE, (size_t)pfmt->proto_addr_size);
    187217                return EINVAL;
     
    192222        case AOP_REPLY: packet->opcode = aop_reply; break;
    193223        default:
    194                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")",
     224                log_msg(LVL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")",
    195225                    uint16_t_be2host(pfmt->opcode));
    196226                return EINVAL;
    197227        }
    198228
    199         addr48(pfmt->sender_hw_addr, packet->sender_hw_addr);
    200         packet->sender_proto_addr =
     229        mac48_decode(pfmt->sender_hw_addr, &packet->sender_hw_addr);
     230        packet->sender_proto_addr.ipv4 =
    201231            uint32_t_be2host(pfmt->sender_proto_addr);
    202         addr48(pfmt->target_hw_addr, packet->target_hw_addr);
    203         packet->target_proto_addr =
     232        mac48_decode(pfmt->target_hw_addr, &packet->target_hw_addr);
     233        packet->target_proto_addr.ipv4 =
    204234            uint32_t_be2host(pfmt->target_proto_addr);
    205         log_msg(LOG_DEFAULT, LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr);
    206 
    207         return EOK;
    208 }
     235        log_msg(LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr);
     236
     237        return EOK;
     238}
     239
    209240
    210241/** @}
Note: See TracChangeset for help on using the changeset viewer.