Changes in uspace/srv/net/ethip/pdu.c [f0a2720:9ae6fc7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/pdu.c
rf0a2720 r9ae6fc7 46 46 #include "pdu.h" 47 47 48 #define MAC48_BYTES 649 50 48 /** Encode Ethernet PDU. */ 51 49 int eth_pdu_encode(eth_frame_t *frame, void **rdata, size_t *rsize) … … 62 60 63 61 hdr = (eth_header_t *)data; 64 mac48_encode(&frame->src, hdr->src);65 mac48_encode(&frame->dest, hdr->dest);62 addr48(frame->src, hdr->src); 63 addr48(frame->dest, hdr->dest); 66 64 hdr->etype_len = host2uint16_t_be(frame->etype_len); 67 65 … … 69 67 frame->size); 70 68 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); 69 log_msg(LOG_DEFAULT, LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size); 75 70 76 71 *rdata = data; … … 84 79 eth_header_t *hdr; 85 80 86 log_msg(L VL_DEBUG, "eth_pdu_decode()");81 log_msg(LOG_DEFAULT, LVL_DEBUG, "eth_pdu_decode()"); 87 82 88 83 if (size < sizeof(eth_header_t)) { 89 log_msg(L VL_DEBUG, "PDU too short (%zu)", size);84 log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size); 90 85 return EINVAL; 91 86 } … … 98 93 return ENOMEM; 99 94 100 mac48_decode(hdr->src, &frame->src);101 mac48_decode(hdr->dest, &frame->dest);95 addr48(hdr->src, frame->src); 96 addr48(hdr->dest, frame->dest); 102 97 frame->etype_len = uint16_t_be2host(hdr->etype_len); 103 98 … … 105 100 frame->size); 106 101 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 115 void 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 126 void 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; 102 log_msg(LOG_DEFAULT, LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size); 103 104 return EOK; 137 105 } 138 106 … … 145 113 uint16_t fopcode; 146 114 147 log_msg(L VL_DEBUG, "arp_pdu_encode()");115 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_pdu_encode()"); 148 116 149 117 size = sizeof(arp_eth_packet_fmt_t); … … 168 136 pfmt->proto_addr_size = IPV4_ADDR_SIZE; 169 137 pfmt->opcode = host2uint16_t_be(fopcode); 170 mac48_encode(&packet->sender_hw_addr, pfmt->sender_hw_addr);138 addr48(packet->sender_hw_addr, pfmt->sender_hw_addr); 171 139 pfmt->sender_proto_addr = 172 host2uint32_t_be(packet->sender_proto_addr .ipv4);173 mac48_encode(&packet->target_hw_addr, pfmt->target_hw_addr);140 host2uint32_t_be(packet->sender_proto_addr); 141 addr48(packet->target_hw_addr, pfmt->target_hw_addr); 174 142 pfmt->target_proto_addr = 175 host2uint32_t_be(packet->target_proto_addr .ipv4);143 host2uint32_t_be(packet->target_proto_addr); 176 144 177 145 *rdata = data; … … 185 153 arp_eth_packet_fmt_t *pfmt; 186 154 187 log_msg(L VL_DEBUG, "arp_pdu_decode()");155 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_pdu_decode()"); 188 156 189 157 if (size < sizeof(arp_eth_packet_fmt_t)) { 190 log_msg(L VL_DEBUG, "ARP PDU too short (%zu)", size);158 log_msg(LOG_DEFAULT, LVL_DEBUG, "ARP PDU too short (%zu)", size); 191 159 return EINVAL; 192 160 } … … 195 163 196 164 if (uint16_t_be2host(pfmt->hw_addr_space) != AHRD_ETHERNET) { 197 log_msg(L VL_DEBUG, "HW address space != %u (%" PRIu16 ")",165 log_msg(LOG_DEFAULT, LVL_DEBUG, "HW address space != %u (%" PRIu16 ")", 198 166 AHRD_ETHERNET, uint16_t_be2host(pfmt->hw_addr_space)); 199 167 return EINVAL; … … 201 169 202 170 if (uint16_t_be2host(pfmt->proto_addr_space) != 0x0800) { 203 log_msg(L VL_DEBUG, "Proto address space != %u (%" PRIu16 ")",171 log_msg(LOG_DEFAULT, LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")", 204 172 ETYPE_IP, uint16_t_be2host(pfmt->proto_addr_space)); 205 173 return EINVAL; … … 207 175 208 176 if (pfmt->hw_addr_size != ETH_ADDR_SIZE) { 209 log_msg(L VL_DEBUG, "HW address size != %zu (%zu)",177 log_msg(LOG_DEFAULT, LVL_DEBUG, "HW address size != %zu (%zu)", 210 178 (size_t)ETH_ADDR_SIZE, (size_t)pfmt->hw_addr_size); 211 179 return EINVAL; … … 213 181 214 182 if (pfmt->proto_addr_size != IPV4_ADDR_SIZE) { 215 log_msg(L VL_DEBUG, "Proto address size != %zu (%zu)",183 log_msg(LOG_DEFAULT, LVL_DEBUG, "Proto address size != %zu (%zu)", 216 184 (size_t)IPV4_ADDR_SIZE, (size_t)pfmt->proto_addr_size); 217 185 return EINVAL; … … 222 190 case AOP_REPLY: packet->opcode = aop_reply; break; 223 191 default: 224 log_msg(L VL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")",192 log_msg(LOG_DEFAULT, LVL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")", 225 193 uint16_t_be2host(pfmt->opcode)); 226 194 return EINVAL; 227 195 } 228 196 229 mac48_decode(pfmt->sender_hw_addr, &packet->sender_hw_addr);230 packet->sender_proto_addr .ipv4=197 addr48(pfmt->sender_hw_addr, packet->sender_hw_addr); 198 packet->sender_proto_addr = 231 199 uint32_t_be2host(pfmt->sender_proto_addr); 232 mac48_decode(pfmt->target_hw_addr, &packet->target_hw_addr);233 packet->target_proto_addr .ipv4=200 addr48(pfmt->target_hw_addr, packet->target_hw_addr); 201 packet->target_proto_addr = 234 202 uint32_t_be2host(pfmt->target_proto_addr); 235 log_msg(LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); 236 237 return EOK; 238 } 239 203 log_msg(LOG_DEFAULT, LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); 204 205 return EOK; 206 } 240 207 241 208 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.