diff --git a/repos/dde_linux/src/lib/usb/storage/storage.cc b/repos/dde_linux/src/lib/usb/storage/storage.cc index ed950a8a32..6994b72a6e 100644 --- a/repos/dde_linux/src/lib/usb/storage/storage.cc +++ b/repos/dde_linux/src/lib/usb/storage/storage.cc @@ -63,8 +63,8 @@ class Storage_device : public Genode::List::Element, wait_for_completion(&comp); Genode::uint32_t *data = (Genode::uint32_t *)scsi_buffer_data(cmnd); - _block_count = bswap(data[0]); - _block_size = bswap(data[1]); + _block_count = host_to_big_endian(data[0]); + _block_size = host_to_big_endian(data[1]); /* if device returns the highest block number */ if (!_sdev->fix_capacity) @@ -100,11 +100,11 @@ class Storage_device : public Genode::List::Element, *p = packet; cmnd->packet = (void *)p; - Genode::uint32_t be_block_nr = bswap(block_nr); + Genode::uint32_t be_block_nr = host_to_big_endian(block_nr); memcpy(&cmnd->cmnd[2], &be_block_nr, 4); /* transfer one block */ - Genode::uint16_t be_block_count = bswap(block_count); + Genode::uint16_t be_block_count = host_to_big_endian(block_count); memcpy(&cmnd->cmnd[7], &be_block_count, 2); /* setup command */ diff --git a/repos/os/include/net/arp.h b/repos/os/include/net/arp.h index da5ec34ced..229541ef70 100644 --- a/repos/os/include/net/arp.h +++ b/repos/os/include/net/arp.h @@ -172,13 +172,13 @@ class Net::Arp_packet * \return link layer type (Arp_packet::Hardware_type). */ Genode::uint16_t hardware_address_type() { - return bswap(_hw_addr_type); } + return host_to_big_endian(_hw_addr_type); } /** * \return network/internet layer type (Ether_frame::EtherType). */ Genode::uint16_t protocol_address_type() { - return bswap(_prot_addr_type); } + return host_to_big_endian(_prot_addr_type); } /** * \return size in bytes of hardware address. @@ -193,7 +193,7 @@ class Net::Arp_packet /** * \return operation code (Arp_packet::Opcode). */ - Genode::uint16_t opcode() { return bswap(_opcode); } + Genode::uint16_t opcode() { return host_to_big_endian(_opcode); } /** * \return source MAC address. @@ -230,7 +230,7 @@ class Net::Arp_packet * \param opcode Arp_packet::Opcode to set. */ void opcode(Genode::uint16_t opcode) { - _opcode = bswap(opcode); } + _opcode = host_to_big_endian(opcode); } /** * Set source MAC address. @@ -274,8 +274,8 @@ class Net::Arp_packet * address resolution with respect to IPv4 addresses. */ bool ethernet_ipv4() { - return ( bswap(_hw_addr_type) == ETHERNET - && bswap(_prot_addr_type) == Ethernet_frame::IPV4 + return ( host_to_big_endian(_hw_addr_type) == ETHERNET + && host_to_big_endian(_prot_addr_type) == Ethernet_frame::IPV4 && _hw_addr_sz == Ethernet_frame::ADDR_LEN && _prot_addr_sz == Ipv4_packet::ADDR_LEN); } diff --git a/repos/os/include/net/dhcp.h b/repos/os/include/net/dhcp.h index e0ea86a30c..da492d0b01 100644 --- a/repos/os/include/net/dhcp.h +++ b/repos/os/include/net/dhcp.h @@ -190,8 +190,8 @@ class Net::Dhcp_packet Genode::uint8_t htype() { return _htype; } Genode::uint8_t hlen() { return _hlen; } Genode::uint8_t hops() { return _hops; } - Genode::uint32_t xid() { return bswap(_xid); } - Genode::uint16_t secs() { return bswap(_secs); } + Genode::uint32_t xid() { return host_to_big_endian(_xid); } + Genode::uint16_t secs() { return host_to_big_endian(_secs); } bool broadcast() { return _flags & BROADCAST; } @@ -233,8 +233,8 @@ class Net::Dhcp_packet void htype(Genode::uint8_t htype) { _htype = htype; } void hlen(Genode::uint8_t hlen) { _hlen = hlen; } void hops(Genode::uint8_t hops) { _hops = hops; } - void xid(Genode::uint32_t xid) { _xid = bswap(_xid); } - void secs(Genode::uint16_t secs) { _secs = bswap(_secs); } + void xid(Genode::uint32_t xid) { _xid = host_to_big_endian(_xid); } + void secs(Genode::uint16_t secs) { _secs = host_to_big_endian(_secs); } void broadcast(bool broadcast) { _flags = broadcast ? BROADCAST : 0; } diff --git a/repos/os/include/net/ethernet.h b/repos/os/include/net/ethernet.h index 9e3c480682..4a1b1818df 100644 --- a/repos/os/include/net/ethernet.h +++ b/repos/os/include/net/ethernet.h @@ -132,7 +132,7 @@ class Net::Ethernet_frame /** * \return EtherType - type of encapsulated protocol. */ - Genode::uint16_t type() { return bswap(_type); } + Genode::uint16_t type() { return host_to_big_endian(_type); } /** * \return payload data. @@ -163,7 +163,7 @@ class Net::Ethernet_frame * * \param type the EtherType to be set. */ - void type(Genode::uint16_t type) { _type = bswap(type); } + void type(Genode::uint16_t type) { _type = host_to_big_endian(type); } /*************** diff --git a/repos/os/include/net/ipv4.h b/repos/os/include/net/ipv4.h index ba20c4fcd8..2ae537a1be 100644 --- a/repos/os/include/net/ipv4.h +++ b/repos/os/include/net/ipv4.h @@ -140,8 +140,8 @@ class Net::Ipv4_packet bool high_reliability() { return _diff_service & RELIABILITY;} bool minimize_monetary_cost() { return _diff_service & COST; } - Genode::uint16_t total_length() { return bswap(_total_length); } - Genode::uint16_t identification() { return bswap(_identification); } + Genode::uint16_t total_length() { return host_to_big_endian(_total_length); } + Genode::uint16_t identification() { return host_to_big_endian(_identification); } bool no_fragmentation() { return _flags & NO_FRAGMENT; } bool more_fragments() { return _flags & MORE_FRAGMENTS; } @@ -150,7 +150,7 @@ class Net::Ipv4_packet Genode::uint8_t time_to_live() { return _time_to_live; } Genode::uint8_t protocol() { return _protocol; } - Genode::uint16_t checksum() { return bswap(_header_checksum); } + Genode::uint16_t checksum() { return host_to_big_endian(_header_checksum); } Ipv4_address dst() { return Ipv4_address(&_dst_addr); } Ipv4_address src() { return Ipv4_address(&_src_addr); } diff --git a/repos/os/include/net/udp.h b/repos/os/include/net/udp.h index 697ac442d3..9d2ceef6f9 100644 --- a/repos/os/include/net/udp.h +++ b/repos/os/include/net/udp.h @@ -75,10 +75,10 @@ class Net::Udp_packet ** UDP field read-accessors ** ******************************/ - Genode::uint16_t src_port() { return bswap(_src_port); } - Genode::uint16_t dst_port() { return bswap(_dst_port); } - Genode::uint16_t length() { return bswap(_length); } - Genode::uint16_t checksum() { return bswap(_checksum); } + Genode::uint16_t src_port() { return host_to_big_endian(_src_port); } + Genode::uint16_t dst_port() { return host_to_big_endian(_dst_port); } + Genode::uint16_t length() { return host_to_big_endian(_length); } + Genode::uint16_t checksum() { return host_to_big_endian(_checksum); } void* data() { return &_data; } @@ -124,7 +124,7 @@ class Net::Udp_packet sum += s + d; } Genode::uint8_t prot[] = { 0, IP_ID }; - sum += bswap(*(Genode::uint16_t*)&prot) + length(); + sum += host_to_big_endian(*(Genode::uint16_t*)&prot) + length(); /* * sum up udp packet itself @@ -132,13 +132,13 @@ class Net::Udp_packet unsigned max = (length() & 1) ? (length() - 1) : length(); Genode::uint16_t *udp = (Genode::uint16_t*) this; for (unsigned i = 0; i < max; i=i+2) - sum += bswap(*udp++); + sum += host_to_big_endian(*udp++); /* if udp length is odd, append a zero byte */ if (length() & 1) { Genode::uint8_t last[] = { *((Genode::uint8_t*)this + (length()-1)), 0 }; - sum += bswap(*(Genode::uint16_t*)&last); + sum += host_to_big_endian(*(Genode::uint16_t*)&last); } /* @@ -149,7 +149,7 @@ class Net::Udp_packet sum = (sum & 0xffff) + (sum >> 16); /* one's complement of sum */ - _checksum = bswap((Genode::uint16_t) ~sum); + _checksum = host_to_big_endian((Genode::uint16_t) ~sum); } } __attribute__((packed)); diff --git a/repos/os/include/util/endian.h b/repos/os/include/util/endian.h index 7694063c74..569a212253 100644 --- a/repos/os/include/util/endian.h +++ b/repos/os/include/util/endian.h @@ -17,7 +17,7 @@ #include template -inline T bswap(T x) +inline T host_to_big_endian(T x) { Genode::uint8_t v[sizeof(T)]; for (unsigned i=0; i