Changeset 1135

Show
Ignore:
Timestamp:
05/08/08 02:00:38 (12 years ago)
Author:
ppalmers
Message:

centralize byteswapping and make it conditional

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/bebob/bebob_dl_mgr.cpp

    r1134 r1135  
    3232#include "libutil/Time.h" 
    3333 
    34 #include <netinet/in.h> 
     34#include "libutil/ByteSwap.h" 
    3535 
    3636#include <cstdio> 
  • trunk/libffado/src/bebob/focusrite/focusrite_cmd.cpp

    r1134 r1135  
    2424#include "focusrite_cmd.h" 
    2525 
    26 #include <netinet/in.h> 
     26#include "libutil/ByteSwap.h" 
    2727#include <iostream> 
    2828 
     
    5454    result &= se.write(m_arg1,"FocusriteVendorDependentCmd arg1"); 
    5555    result &= se.write(m_arg2,"FocusriteVendorDependentCmd arg2"); 
    56     // FIXME: this is not consistent, we should not have to care about ntohl here 
    57     result &= se.write(htonl(m_id),"FocusriteVendorDependentCmd ID"); 
    58     result &= se.write(htonl(m_value),"FocusriteVendorDependentCmd value"); 
     56    // FIXME: this is not consistent, we should not have to care about CondSwap32 here 
     57    result &= se.write(CondSwap32(m_id),"FocusriteVendorDependentCmd ID"); 
     58    result &= se.write(CondSwap32(m_value),"FocusriteVendorDependentCmd value"); 
    5959     
    6060    return result; 
     
    6969    result &= de.read(&m_arg2); 
    7070    result &= de.read(&m_id); 
    71     m_id=ntohl(m_id); 
     71    m_id=CondSwap32(m_id); 
    7272    result &= de.read(&m_value); 
    73     m_value=ntohl(m_value); 
     73    m_value=CondSwap32(m_value); 
    7474 
    7575    return result; 
  • trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp

    r1134 r1135  
    2525#include "focusrite_cmd.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828 
    2929namespace BeBoB { 
     
    140140    fb_nodeid_t nodeId = getNodeId() | 0xFFC0; 
    141141 
    142     if(!get1394Service().write_quadlet( nodeId, addr, htonl(data) ) ) { 
     142    if(!get1394Service().write_quadlet( nodeId, addr, CondSwap32(data) ) ) { 
    143143        debugError("Could not write to node 0x%04X addr 0x%012X\n", nodeId, addr); 
    144144        return false; 
     
    161161    } 
    162162 
    163     result=ntohl(result); 
     163    result=CondSwap32(result); 
    164164    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Read result: 0x%08llX\n", result); 
    165165 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp

    r1134 r1135  
    2828#include "libutil/Time.h" 
    2929 
    30 #include <netinet/in.h> 
     30#include "libutil/ByteSwap.h" 
    3131 
    3232namespace BeBoB { 
     
    757757        char *ptr = (char *) &name[i*4]; 
    758758        tmp = *((uint32_t *)ptr); 
    759         tmp = htonl(tmp); 
     759        tmp = CondSwap32(tmp); 
    760760        if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_DEVICE_NAME_1 + i, tmp ) ) { 
    761761            debugError( "setSpecificValue failed\n" ); 
     
    776776            return ""; 
    777777        } 
    778         tmp = ntohl(tmp); 
     778        tmp = CondSwap32(tmp); 
    779779        unsigned int j; 
    780780        char *ptr = (char *) &tmp; 
  • trunk/libffado/src/bebob/terratec/terratec_cmd.cpp

    r1134 r1135  
    2424#include "terratec_cmd.h" 
    2525 
    26 #include <netinet/in.h> 
     26#include "libutil/ByteSwap.h" 
    2727#include <iostream> 
    2828 
  • trunk/libffado/src/bounce/bounce_avdevice.cpp

    r1134 r1135  
    4242 
    4343#include <string> 
    44 #include <netinet/in.h> 
     44#include "libutil/ByteSwap.h" 
    4545 
    4646namespace Bounce { 
  • trunk/libffado/src/bounce/bounce_slave_avdevice.cpp

    r1134 r1135  
    367367//     { 
    368368//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
    369 //         printf(" %08x", ntohl(current_rom[i])); 
     369//         printf(" %08x", CondSwap32(current_rom[i])); 
    370370//     } 
    371371//     printf("\n"); 
     
    391391//     { 
    392392//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
    393 //         printf(" %08x", ntohl(rom[i])); 
     393//         printf(" %08x", CondSwap32(rom[i])); 
    394394//     } 
    395395//     printf("\n"); 
     
    411411//     { 
    412412//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
    413 //         printf(" %08x", ntohl(rom[i])); 
     413//         printf(" %08x", CondSwap32(rom[i])); 
    414414//     } 
    415415//     printf("\n"); 
     
    435435//     { 
    436436//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
    437 //         printf(" %08x", ntohl(rom[i])); 
     437//         printf(" %08x", CondSwap32(rom[i])); 
    438438//     } 
    439439//     printf("\n"); 
     
    449449//     { 
    450450//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
    451 //         printf(" %08x", ntohl(rom[i])); 
     451//         printf(" %08x", CondSwap32(rom[i])); 
    452452//     } 
    453453//     printf("\n"); 
  • trunk/libffado/src/debugmodule/debugmodule.cpp

    r1134 r1135  
    2727 
    2828#include <stdarg.h> 
    29 #include <netinet/in.h> 
     29#include "libutil/ByteSwap.h" 
    3030 
    3131#include <iostream> 
     
    802802    for (i = 0; i< length; i += 1) { 
    803803        printf( "%02d %04X: %08X (%08X)" 
    804                 "\n", i, i*4, data[i],ntohl(data[i])); 
    805     } 
    806 } 
    807  
    808  
     804                "\n", i, i*4, data[i],CondSwap32(data[i])); 
     805    } 
     806} 
     807 
     808 
  • trunk/libffado/src/dice/dice_avdevice.cpp

    r1134 r1135  
    3333#include <stdint.h> 
    3434#include <assert.h> 
    35 #include <netinet/in.h> 
     35#include "libutil/ByteSwap.h" 
    3636#include <libraw1394/csr.h> 
    3737 
     
    14631463    } 
    14641464 
    1465     *result=ntohl(*result); 
     1465    *result=CondSwap32(*result); 
    14661466 
    14671467    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Read result: 0x%08X\n", *result); 
     
    14831483    fb_nodeid_t nodeId=getNodeId() | 0xFFC0; 
    14841484 
    1485     if(!get1394Service().write_quadlet( nodeId, addr, htonl(data) ) ) { 
     1485    if(!get1394Service().write_quadlet( nodeId, addr, CondSwap32(data) ) ) { 
    14861486        debugError("Could not write to node 0x%04X addr 0x%012X\n", nodeId, addr); 
    14871487        return false; 
     
    15091509 
    15101510    for(unsigned int i=0;i<length/4;i++) { 
    1511         *(data+i)=ntohl(*(data+i)); 
     1511        *(data+i)=CondSwap32(*(data+i)); 
    15121512    } 
    15131513 
     
    15311531 
    15321532    for(unsigned int i=0;i<length/4;i++) { 
    1533         data_out[i]=ntohl(*(data+i)); 
     1533        data_out[i]=CondSwap32(*(data+i)); 
    15341534    } 
    15351535 
  • trunk/libffado/src/fireworks/efc/efc_avc_cmd.cpp

    r1134 r1135  
    2424#include "efc_avc_cmd.h" 
    2525 
    26 #include <netinet/in.h> 
     26#include "libutil/ByteSwap.h" 
    2727#include <iostream> 
    2828 
  • trunk/libffado/src/fireworks/efc/efc_cmd.cpp

    r1134 r1135  
    2525#include "efc_cmds_hardware.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    110110    bool result=true; 
    111111     
    112     result &= se.write(htonl(m_length), "EFC length"); 
     112    result &= se.write(CondSwap32(m_length), "EFC length"); 
    113113     
    114114    unsigned int i=0; 
     
    123123    // serialize the header 
    124124    quadlet_t *header_as_quadlets=(quadlet_t *)&m_header; 
    125     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header version"); i++; 
    126     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header seqnum"); i++; 
    127     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header category"); i++; 
    128     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header command"); i++; 
    129     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header return value"); i++; 
     125    result &= se.write(CondSwap32(*(header_as_quadlets+i)), "EFC header version"); i++; 
     126    result &= se.write(CondSwap32(*(header_as_quadlets+i)), "EFC header seqnum"); i++; 
     127    result &= se.write(CondSwap32(*(header_as_quadlets+i)), "EFC header category"); i++; 
     128    result &= se.write(CondSwap32(*(header_as_quadlets+i)), "EFC header command"); i++; 
     129    result &= se.write(CondSwap32(*(header_as_quadlets+i)), "EFC header return value"); i++; 
    130130     
    131131    return result; 
     
    138138     
    139139    result &= de.read(&m_length); 
    140     m_length=ntohl(m_length); 
     140    m_length=CondSwap32(m_length); 
    141141     
    142142    // read the EFC header 
     
    144144    for (unsigned int i=0; i<sizeof(m_header)/4; i++) { 
    145145        result &= de.read((header_as_quadlets+i)); 
    146         *(header_as_quadlets+i)=ntohl(*(header_as_quadlets+i)); 
     146        *(header_as_quadlets+i)=CondSwap32(*(header_as_quadlets+i)); 
    147147    } 
    148148 
  • trunk/libffado/src/fireworks/efc/efc_cmd.h

    r1134 r1135  
    100100#define EFC_DESERIALIZE_AND_SWAP(__de__, __value__, __result__) \ 
    101101    { __result__ &= __de__.read(__value__); \ 
    102       *(__value__)=ntohl(*(__value__)); } \ 
     102      *(__value__)=CondSwap32(*(__value__)); } \ 
    103103 
    104104 
  • trunk/libffado/src/fireworks/efc/efc_cmds_flash.cpp

    r1134 r1135  
    2525#include "efc_cmds_flash.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    4848 
    4949    result &= EfcCmd::serialize ( se ); 
    50     result &= se.write(htonl(m_address), "Address" ); 
     50    result &= se.write(CondSwap32(m_address), "Address" ); 
    5151 
    5252    return result; 
     
    9090    result &= EfcCmd::serialize ( se ); 
    9191 
    92     result &= se.write(htonl(m_address), "Address" ); 
    93     result &= se.write(htonl(m_nb_quadlets), "Length (quadlets)" ); 
     92    result &= se.write(CondSwap32(m_address), "Address" ); 
     93    result &= se.write(CondSwap32(m_nb_quadlets), "Length (quadlets)" ); 
    9494 
    9595    return result; 
     
    152152    result &= EfcCmd::serialize ( se ); 
    153153 
    154     result &= se.write(htonl(m_address), "Address" ); 
    155     result &= se.write(htonl(m_nb_quadlets), "Length (quadlets)" ); 
    156  
    157     for (unsigned int i=0; i < m_nb_quadlets; i++) { 
    158         result &= se.write(htonl(m_data[i]), "Data"); 
     154    result &= se.write(CondSwap32(m_address), "Address" ); 
     155    result &= se.write(CondSwap32(m_nb_quadlets), "Length (quadlets)" ); 
     156 
     157    for (unsigned int i=0; i < m_nb_quadlets; i++) { 
     158        result &= se.write(CondSwap32(m_data[i]), "Data"); 
    159159    } 
    160160    return result; 
     
    200200 
    201201    result &= EfcCmd::serialize ( se ); 
    202     result &= se.write(htonl(m_lock), "Locked" ); 
     202    result &= se.write(CondSwap32(m_lock), "Locked" ); 
    203203 
    204204    return result; 
  • trunk/libffado/src/fireworks/efc/efc_cmds_hardware.cpp

    r1134 r1135  
    2424#include "efc_cmds_hardware.h" 
    2525 
    26 #include <netinet/in.h> 
     26#include "libutil/ByteSwap.h" 
    2727#include <iostream> 
    2828 
  • trunk/libffado/src/fireworks/efc/efc_cmds_hardware_ctrl.cpp

    r1134 r1135  
    2525#include "efc_cmds_hardware_ctrl.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    9898    result &= EfcCmd::serialize ( se ); 
    9999 
    100     result &= se.write(htonl(m_clock), "Clock" ); 
    101     result &= se.write(htonl(m_samplerate), "Samplerate" ); 
    102     result &= se.write(htonl(m_index), "Index" ); 
     100    result &= se.write(CondSwap32(m_clock), "Clock" ); 
     101    result &= se.write(CondSwap32(m_samplerate), "Samplerate" ); 
     102    result &= se.write(CondSwap32(m_index), "Index" ); 
    103103 
    104104    return result; 
  • trunk/libffado/src/fireworks/efc/efc_cmds_ioconfig.cpp

    r1134 r1135  
    2525#include "efc_cmds_ioconfig.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    6060        result &= EfcCmd::serialize ( se ); 
    6161 
    62         result &= se.write(htonl(m_value), "Value" ); 
     62        result &= se.write(CondSwap32(m_value), "Value" ); 
    6363    } 
    6464    return result; 
  • trunk/libffado/src/fireworks/efc/efc_cmds_mixer.cpp

    r1134 r1135  
    2525#include "efc_cmds_mixer.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    7373        result &= EfcCmd::serialize ( se ); 
    7474         
    75         result &= se.write(htonl(m_channel), "Channel" ); 
     75        result &= se.write(CondSwap32(m_channel), "Channel" ); 
    7676         
    7777    } else { 
     
    8282        result &= EfcCmd::serialize ( se ); 
    8383         
    84         result &= se.write(htonl(m_channel), "Channel" ); 
    85         result &= se.write(htonl(m_value), "Value" ); 
     84        result &= se.write(CondSwap32(m_channel), "Channel" ); 
     85        result &= se.write(CondSwap32(m_value), "Value" ); 
    8686    } 
    8787 
  • trunk/libffado/src/fireworks/efc/efc_cmds_monitor.cpp

    r1134 r1135  
    2525#include "efc_cmds_monitor.h" 
    2626 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828#include <iostream> 
    2929 
     
    106106        result &= EfcCmd::serialize ( se ); 
    107107         
    108         result &= se.write(htonl(m_input), "Input" ); 
    109         result &= se.write(htonl(m_output), "Output" ); 
     108        result &= se.write(CondSwap32(m_input), "Input" ); 
     109        result &= se.write(CondSwap32(m_output), "Output" ); 
    110110         
    111111    } else { 
     
    116116        result &= EfcCmd::serialize ( se ); 
    117117         
    118         result &= se.write(htonl(m_input), "Input" ); 
    119         result &= se.write(htonl(m_output), "Output" ); 
    120         result &= se.write(htonl(m_value), "Value" ); 
     118        result &= se.write(CondSwap32(m_input), "Input" ); 
     119        result &= se.write(CondSwap32(m_output), "Output" ); 
     120        result &= se.write(CondSwap32(m_value), "Value" ); 
    121121    } 
    122122    return result; 
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r1134 r1135  
    3939#include <stdint.h> 
    4040#include <assert.h> 
    41 #include <netinet/in.h> 
     41#include "libutil/ByteSwap.h" 
    4242#include <iostream> 
    4343#include <sstream> 
  • trunk/libffado/src/libavc/ccm/avc_signal_source.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/descriptors/avc_descriptor_cmd.cpp

    r1134 r1135  
    2828#include "libieee1394/ieee1394service.h" 
    2929 
    30 #include <netinet/in.h> 
     30#include "libutil/ByteSwap.h" 
    3131#include <iostream> 
    3232 
  • trunk/libffado/src/libavc/general/avc_connect.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_extended_plug_info.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_extended_subunit_info.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929 
    3030#define NR_OF_PAGE_DATA 5 
  • trunk/libffado/src/libavc/general/avc_generic.cpp

    r1134 r1135  
    3030#include "libutil/Time.h" 
    3131 
    32 #include <netinet/in.h> 
     32#include "libutil/ByteSwap.h" 
    3333 
    3434#define DEBUG_EXTRA_VERBOSE 5 
  • trunk/libffado/src/libavc/general/avc_plug_info.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_signal_format.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_subunit_info.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_unit_info.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/general/avc_vendor_dependent_cmd.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929#include <iostream> 
    3030 
  • trunk/libffado/src/libavc/musicsubunit/avc_descriptor_music.cpp

    r1134 r1135  
    3333#include "../general/avc_unit.h" 
    3434 
    35 #include <netinet/in.h> 
     35#include "libutil/ByteSwap.h" 
    3636 
    3737// info block implementations 
     
    5353    result &= AVCInfoBlock::serialize(se); 
    5454     
    55     quadlet_t tmp=htonl(m_current_latency_capability); 
     55    quadlet_t tmp=CondSwap32(m_current_latency_capability); 
    5656     
    5757    result &= se.write(m_current_transmit_capability, "AVCMusicGeneralStatusInfoBlock m_current_transmit_capability"); 
     
    7575    result &= de.read(&m_current_receive_capability); 
    7676    result &= de.read(&m_current_latency_capability); 
    77     m_current_latency_capability=ntohl(m_current_latency_capability); 
     77    m_current_latency_capability=CondSwap32(m_current_latency_capability); 
    7878     
    7979    return result; 
  • trunk/libffado/src/libavc/streamformat/avc_extended_stream_format.cpp

    r1134 r1135  
    2626#include "libieee1394/ieee1394service.h" 
    2727 
    28 #include <netinet/in.h> 
     28#include "libutil/ByteSwap.h" 
    2929 
    3030namespace AVC { 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r1134 r1135  
    3939 
    4040#include <errno.h> 
    41 #include <netinet/in.h> 
     41#include "libutil/ByteSwap.h" 
    4242 
    4343#include <string.h> 
     
    388388                CSR_REGISTER_BASE | CSR_CYCLE_TIME, 
    389389                sizeof(uint32_t), cycle_timer ) == 0 ) { 
    390             *cycle_timer = ntohl(*cycle_timer); 
     390            *cycle_timer = CondSwap32(*cycle_timer); 
    391391            return true; 
    392392        } else { 
     
    488488        fb_quadlet_t in_hi = (value >> 32) & 0xFFFFFFFF; 
    489489        fb_quadlet_t in_lo = value & 0xFFFFFFFF; 
    490         in_hi = htonl(in_hi); 
    491         in_lo = htonl(in_lo); 
     490        in_hi = CondSwap32(in_hi); 
     491        in_lo = CondSwap32(in_lo); 
    492492        fb_octlet_t value_new = in_lo; 
    493493        value_new <<= 32; 
     
    557557    m_handle_lock->Lock(); 
    558558    for (int i = 0; i < len; ++i) { 
    559         buf[i] = ntohl( buf[i] ); 
     559        buf[i] = CondSwap32( buf[i] ); 
    560560    } 
    561561 
     
    569569 
    570570    for ( unsigned int i = 0; i < *resp_len; ++i ) { 
    571         result[i] = htonl( result[i] ); 
     571        result[i] = CondSwap32( result[i] ); 
    572572    } 
    573573 
     
    11141114    if (result < 0) 
    11151115        return -1; 
    1116     return ntohl(buffer); 
     1116    return CondSwap32(buffer); 
    11171117} 
    11181118 
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r1134 r1135  
    3434 
    3535#include <errno.h> 
    36 #include <netinet/in.h> 
     36#include "libutil/ByteSwap.h" 
    3737#include <assert.h> 
    3838#include <unistd.h> 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp

    r1134 r1135  
    3232#include "libieee1394/cycletimer.h" 
    3333 
    34 #include <netinet/in.h> 
     34#include "libutil/ByteSwap.h" 
    3535#include <assert.h> 
    3636 
     
    102102              (length >= 2*sizeof(quadlet_t)); 
    103103    if(ok) { 
    104         m_last_timestamp = sytRecvToFullTicks2((uint32_t)ntohs(packet->syt), pkt_ctr); 
     104        m_last_timestamp = sytRecvToFullTicks2((uint32_t)CondSwap16(packet->syt), pkt_ctr); 
    105105        //#ifdef DEBUG 
    106106        #if 0 
     
    108108 
    109109        //=> convert the SYT to a full timestamp in ticks 
    110         uint64_t old_last_timestamp = sytRecvToFullTicks((uint32_t)ntohs(packet->syt), 
     110        uint64_t old_last_timestamp = sytRecvToFullTicks((uint32_t)CondSwap16(packet->syt), 
    111111                                              CYCLE_TIMER_GET_CYCLES(pkt_ctr), now); 
    112112        if(m_last_timestamp != old_last_timestamp) { 
     
    224224 
    225225            for(j = 0; j < nevents; j += 1) { 
    226                 *(buffer)=(ntohl((*target_event) ) & 0x00FFFFFF); 
     226                *(buffer)=(CondSwap32((*target_event) ) & 0x00FFFFFF); 
    227227                buffer++; 
    228228                target_event+=m_dimension; 
     
    258258 
    259259            for(j = 0; j < nevents; j += 1) { 
    260                 unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 
     260                unsigned int v = CondSwap32(*target_event) & 0x00FFFFFF; 
    261261                // sign-extend highest bit of 24-bit int 
    262262                int tmp = (int)(v << 8) / 256; 
     
    295295 
    296296            for(j = 0; j < nevents; j += 1) { 
    297                 *(buffer)=(ntohl((*target_event) ) & 0x00FFFFFF); 
     297                *(buffer)=(CondSwap32((*target_event) ) & 0x00FFFFFF); 
    298298                buffer++; 
    299299                target_event+=m_dimension; 
     
    329329 
    330330            for(j = 0; j < nevents; j += 1) { 
    331                 unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 
     331                unsigned int v = CondSwap32(*target_event) & 0x00FFFFFF; 
    332332                // sign-extend highest bit of 24-bit int 
    333333                int tmp = (int)(v << 8) / 256; 
     
    365365            for (j = p.location;j < nevents; j += 8) { 
    366366                target_event = (quadlet_t *) (data + ((j * m_dimension) + p.position)); 
    367                 sample_int=ntohl(*target_event); 
     367                sample_int=CondSwap32(*target_event); 
    368368                // FIXME: this assumes that 2X and 3X speed isn't used, 
    369369                // because only the 1X slot is put into the ringbuffer 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r1134 r1135  
    3535#include "libieee1394/cycletimer.h" 
    3636 
    37 #include <netinet/in.h> 
     37#include "libutil/ByteSwap.h" 
    3838#include <assert.h> 
    3939 
     
    353353    // convert the timestamp to SYT format 
    354354    uint16_t timestamp_SYT = TICKS_TO_SYT ( ts ); 
    355     packet->syt = htons ( timestamp_SYT ); 
     355    packet->syt = CondSwap16 ( timestamp_SYT ); 
    356356 
    357357    // FIXME: use a precomputed value here 
     
    683683                unsigned int tmp = ((int) v); 
    684684                tmp = ( tmp >> 8 ) | 0x40000000; 
    685                 *target_event = htonl((quadlet_t)tmp); 
     685                *target_event = CondSwap32((quadlet_t)tmp); 
    686686                buffer++; 
    687687                target_event += m_dimension; 
     
    839839            for(;j < nevents; j += 1) { 
    840840                uint32_t in = (uint32_t)(*buffer); 
    841                 *target_event = htonl((quadlet_t)((in & 0x00FFFFFF) | 0x40000000)); 
     841                *target_event = CondSwap32((quadlet_t)((in & 0x00FFFFFF) | 0x40000000)); 
    842842                buffer++; 
    843843                target_event += m_dimension; 
     
    884884            { 
    885885                uint32_t in = (uint32_t)(*buffer); 
    886                 *target_event = htonl((quadlet_t)((in & 0x00FFFFFF) | 0x40000000)); 
     886                *target_event = CondSwap32((quadlet_t)((in & 0x00FFFFFF) | 0x40000000)); 
    887887                buffer++; 
    888888                target_event += m_dimension; 
     
    933933 
    934934                tmp = ( tmp >> 8 ) | 0x40000000; 
    935                 *target_event = htonl((quadlet_t)tmp); 
     935                *target_event = CondSwap32((quadlet_t)tmp); 
    936936                buffer++; 
    937937                target_event += m_dimension; 
     
    968968        for (j = p.location;j < nevents; j += 8) { 
    969969            target_event = (quadlet_t *) (data + ((j * m_dimension) + p.position)); 
    970             *target_event = htonl(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
     970            *target_event = CondSwap32(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
    971971        } 
    972972    } 
     
    10011001                    tmpval = ((*buffer)<<16) & 0x00FF0000; 
    10021002                    tmpval = IEC61883_AM824_SET_LABEL(tmpval, IEC61883_AM824_LABEL_MIDI_1X); 
    1003                     *target_event = htonl(tmpval); 
     1003                    *target_event = CondSwap32(tmpval); 
    10041004 
    10051005//                     debugOutput ( DEBUG_LEVEL_VERBOSE, "MIDI port %s, pos=%u, loc=%u, nevents=%u, dim=%d\n", 
     
    10111011                    // or because this would exceed the maximum rate 
    10121012                    // FIXME: this can be ifdef optimized since it's a constant 
    1013                     *target_event = htonl(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
     1013                    *target_event = CondSwap32(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
    10141014                } 
    10151015                buffer+=8; 
     
    10191019                target_event = (quadlet_t *)(data + ((j * m_dimension) + p.position)); 
    10201020                __builtin_prefetch(target_event, 1, 0); // prefetch events for write, no temporal locality 
    1021                 *target_event = htonl(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
     1021                *target_event = CondSwap32(IEC61883_AM824_SET_LABEL(0, IEC61883_AM824_LABEL_MIDI_NO_DATA)); 
    10221022            } 
    10231023        } 
  • trunk/libffado/src/libstreaming/motu/MotuReceiveStreamProcessor.cpp

    r1134 r1135  
    3636 
    3737#include <math.h> 
    38 #include <netinet/in.h> 
     38#include "libutil/ByteSwap.h" 
    3939#include <assert.h> 
    4040 
     
    131131        // for 2x rates, 32 for 4x rates). 
    132132        quadlet_t *quadlet = (quadlet_t *)data; 
    133         unsigned int dbs = get_bits(ntohl(quadlet[0]), 23, 8);  // Size of one event in terms of fdf_size 
    134         unsigned int fdf_size = get_bits(ntohl(quadlet[1]), 23, 8) == 0x22 ? 32:0; // Event unit size in bits 
     133        unsigned int dbs = get_bits(CondSwap32(quadlet[0]), 23, 8);  // Size of one event in terms of fdf_size 
     134        unsigned int fdf_size = get_bits(CondSwap32(quadlet[1]), 23, 8) == 0x22 ? 32:0; // Event unit size in bits 
    135135 
    136136        // Don't even attempt to process a packet if it isn't what 
     
    150150        // received.  Since every frame from the MOTU has its own timestamp 
    151151        // we can just pick it straight from the packet. 
    152         uint32_t last_sph = ntohl(*(quadlet_t *)(data+8+(n_events-1)*event_length)); 
     152        uint32_t last_sph = CondSwap32(*(quadlet_t *)(data+8+(n_events-1)*event_length)); 
    153153        m_last_timestamp = sphRecvToFullTicks(last_sph, m_Parent.get1394Service().getCycleTimer()); 
    154154 
     
    174174    quadlet_t* quadlet = (quadlet_t*) data; 
    175175 
    176     unsigned int dbs = get_bits(ntohl(quadlet[0]), 23, 8);  // Size of one event in terms of fdf_size 
    177     unsigned int fdf_size = get_bits(ntohl(quadlet[1]), 23, 8) == 0x22 ? 32:0; // Event unit size in bits 
     176    unsigned int dbs = get_bits(CondSwap32(quadlet[0]), 23, 8);  // Size of one event in terms of fdf_size 
     177    unsigned int fdf_size = get_bits(CondSwap32(quadlet[1]), 23, 8) == 0x22 ? 32:0; // Event unit size in bits 
    178178    // this is only called for packets that return eCRV_OK on processPacketHeader 
    179179    // so event_length won't become 0 
  • trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r1134 r1135  
    3535#include "libieee1394/cycletimer.h" 
    3636 
    37 #include <netinet/in.h> 
     37#include "libutil/ByteSwap.h" 
    3838#include <assert.h> 
    3939 
     
    293293            // network byte order).  After byte order swap, the 24-bit 
    294294            // MSB is in the second byte of val. 
    295             signed int val = htonl(lrintf(0x7fffff*sin((1000.0*2.0*M_PI/24576000.0)*a_cx))); 
     295            signed int val = CondSwap32(lrintf(0x7fffff*sin((1000.0*2.0*M_PI/24576000.0)*a_cx))); 
    296296            memcpy(sample,((char *)&val)+1,3); 
    297297            if ((a_cx+=int_tpf) >= 24576000) { 
     
    309309        for (int i=0; i < n_events; i++, quadlet += dbs) { 
    310310            int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)lrintf(i * ticks_per_frame)); 
    311             *quadlet = htonl(fullTicksToSph(ts_frame)); 
     311            *quadlet = CondSwap32(fullTicksToSph(ts_frame)); 
    312312//fprintf(stderr,"tx: %d/%d\n", 
    313313//  CYCLE_TIMER_GET_CYCLES(fullTicksToSph(ts_frame)), 
     
    405405    for (int i=0; i < n_events; i++, quadlet += dbs) { 
    406406        int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)lrintf(i * ticks_per_frame)); 
    407         *quadlet = htonl(fullTicksToSph(ts_frame)); 
     407        *quadlet = CondSwap32(fullTicksToSph(ts_frame)); 
    408408    } 
    409409 
     
    428428    // present.  For data-less packets the dbc is the same as the previously 
    429429    // transmitted block. 
    430     *quadlet = htonl(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
     430    *quadlet = CondSwap32(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
    431431    quadlet++; 
    432     *quadlet = htonl(0x8222ffff); 
     432    *quadlet = CondSwap32(0x8222ffff); 
    433433    quadlet++; 
    434434    return n_events; 
     
    445445    // present.  For data-less packets the dbc is the same as the previously 
    446446    // transmitted block. 
    447     *quadlet = htonl(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
     447    *quadlet = CondSwap32(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
    448448    quadlet++; 
    449     *quadlet = htonl(0x8222ffff); 
     449    *quadlet = CondSwap32(0x8222ffff); 
    450450    quadlet++; 
    451451    *length = 8; 
  • trunk/libffado/src/libutil/ByteSwap.h

    r1134 r1135  
    2525#define __FFADO_BYTESWAP__ 
    2626 
    27 #include <netinet/in.h> 
     27#include <byteswap.h> 
     28#include <inttypes.h> 
    2829#include <endian.h> 
    2930#include <assert.h> 
     
    3738 
    3839// no-op for big endian machines 
     40 
     41static inline uint64_t 
     42CondSwap64(uint64_t d) 
     43{ 
     44    return d; 
     45} 
     46 
     47static inline uint32_t 
     48CondSwap32(uint32_t d) 
     49{ 
     50    return d; 
     51} 
     52 
     53static inline uint16_t 
     54CondSwap16(uint16_t d) 
     55{ 
     56    return d; 
     57} 
     58 
    3959static inline void 
    4060byteSwapToBus(quadlet_t *data, unsigned int nb_elements) 
     
    5070 
    5171#else 
     72 
     73static inline uint64_t 
     74CondSwap64(uint64_t d) 
     75{ 
     76    return bswap_64(d); 
     77} 
     78 
     79static inline uint32_t 
     80CondSwap32(uint32_t d) 
     81{ 
     82    return bswap_32(d); 
     83} 
     84 
     85static inline uint16_t 
     86CondSwap16(uint16_t d) 
     87{ 
     88    return bswap_16(d); 
     89} 
    5290 
    5391#ifdef __SSE2__ 
     
    6199    // Work input until data reaches 16 byte alignment 
    62100    while ((((unsigned long)data) & 0xF) && nb_elements > 0) { 
    63         *data = htonl(*data); 
     101        *data = CondSwap32(*data); 
    64102        data++; 
    65103        nb_elements--; 
     
    98136    // and do the remaining ones 
    99137    while (nb_elements > 0) { 
    100         *data = htonl(*data); 
     138        *data = CondSwap32(*data); 
    101139        data++; 
    102140        nb_elements--; 
     
    110148    // Work input until data reaches 16 byte alignment 
    111149    while ((((unsigned long)data) & 0xF) && nb_elements > 0) { 
    112         *data = htonl(*data); 
     150        *data = CondSwap32(*data); 
    113151        data++; 
    114152        nb_elements--; 
     
    144182    // and do the remaining ones 
    145183    while (nb_elements > 0) { 
    146         *data = htonl(*data); 
     184        *data = CondSwap32(*data); 
    147185        data++; 
    148186        nb_elements--; 
     
    157195    unsigned int i=0; 
    158196    for(; i<nb_elements; i++) { 
    159         *data = htonl(*data); 
     197        *data = CondSwap32(*data); 
    160198        data++; 
    161199    } 
     
    167205    unsigned int i=0; 
    168206    for(; i<nb_elements; i++) { 
    169         *data = ntohl(*data); 
     207        *data = CondSwap32(*data); 
    170208        data++; 
    171209    } 
  • trunk/libffado/src/libutil/cmd_serialize.cpp

    r1134 r1135  
    2727#include <iomanip> 
    2828 
    29 #include <netinet/in.h> 
     29#include "libutil/ByteSwap.h" 
    3030 
    3131 
  • trunk/libffado/src/metrichalo/mh_avdevice.cpp

    r1134 r1135  
    3636#include <stdint.h> 
    3737#include <assert.h> 
    38 #include <netinet/in.h> 
     38#include "libutil/ByteSwap.h" 
    3939#include <iostream> 
    4040#include <sstream> 
  • trunk/libffado/src/motu/motu_avdevice.cpp

    r1134 r1135  
    4444#include <stdint.h> 
    4545#include <assert.h> 
    46 #include <netinet/in.h> 
     46#include "libutil/ByteSwap.h" 
    4747#include <iostream> 
    4848#include <sstream> 
     
    13891389  } 
    13901390 
    1391   return ntohl(quadlet); 
     1391  return CondSwap32(quadlet); 
    13921392} 
    13931393 
     
    13981398 
    13991399  unsigned int err = 0; 
    1400   data = htonl(data); 
     1400  data = CondSwap32(data); 
    14011401 
    14021402  // Note: 1394Service::write() expects a physical ID, not the node id 
  • trunk/libffado/src/rme/rme_avdevice.cpp

    r1134 r1135  
    3535#include <stdint.h> 
    3636#include <assert.h> 
    37 #include <netinet/in.h> 
     37#include "libutil/ByteSwap.h" 
    3838 
    3939#include <iostream> 
     
    252252        debugError("Error doing RME read from register 0x%06x\n",reg); 
    253253    } 
    254     return ntohl(quadlet); 
     254    return CondSwap32(quadlet); 
    255255} 
    256256 
     
    259259 
    260260    unsigned int err = 0; 
    261     data = htonl(data); 
     261    data = CondSwap32(data); 
    262262    if (get1394Service().write(0xffc0 | getNodeId(), reg, 1, &data) <= 0) { 
    263263        err = 1; 
  • trunk/libffado/tests/dumpiso_mod.cpp

    r1134 r1135  
    2121#include "src/debugmodule/debugmodule.h" 
    2222#include "src/libstreaming/util/cip.h" 
    23 #include <netinet/in.h> 
     23#include "libutil/ByteSwap.h" 
    2424 
    2525#define BUFFER 1000 
     
    210210                    (length >= 2*sizeof(quadlet_t)); 
    211211        if(ok) { 
    212             timestamp = sytRecvToFullTicks((uint32_t)ntohs(packet->syt), 
     212            timestamp = sytRecvToFullTicks((uint32_t)CondSwap16(packet->syt), 
    213213                                    cycle, cycle_timer); 
    214214        } 
  • trunk/libffado/tests/scan-devreg.cpp

    r1134 r1135  
    2525 
    2626#include <libraw1394/raw1394.h> 
    27 #include <netinet/in.h> 
     27#include "libutil/ByteSwap.h" 
    2828 
    2929#include "debugmodule/debugmodule.h" 
     
    284284                continue; 
    285285            } else { 
    286                 quadlet = ntohl(quadlet); 
     286                quadlet = CondSwap32(quadlet); 
    287287            } 
    288288             
  • trunk/libffado/tests/streaming/test-isohandling.cpp

    r1134 r1135  
    3333#include "src/debugmodule/debugmodule.h" 
    3434 
    35 #include <netinet/in.h> 
     35#include "libutil/ByteSwap.h" 
    3636 
    3737#include "src/libutil/PosixThread.h" 
  • trunk/libffado/tests/test-bufferops.cpp

    r1134 r1135  
    6565     
    6666    for (i=0; i<nb_quadlets; i++) { 
    67         buffer_ref[i] = htonl(buffer_1[i]); 
     67        buffer_ref[i] = CondSwap32(buffer_1[i]); 
    6868    } 
    6969     
  • trunk/libffado/tests/test-ieee1394service.cpp

    r1134 r1135  
    3636#include "src/debugmodule/debugmodule.h" 
    3737 
    38 #include <netinet/in.h> 
     38#include "libutil/ByteSwap.h" 
    3939 
    4040#include "src/libieee1394/cycletimer.h" 
  • trunk/libffado/tests/test-timestampedbuffer.cpp

    r1134 r1135  
    3535#include "src/debugmodule/debugmodule.h" 
    3636 
    37 #include <netinet/in.h> 
     37#include "libutil/ByteSwap.h" 
    3838 
    3939#include "src/libieee1394/cycletimer.h"