~ubuntu-branches/ubuntu/natty/bcmwl/natty

« back to all changes in this revision

Viewing changes to src/src/include/bcmendian.h

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Milone
  • Date: 2010-02-14 19:58:58 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100214195858-76xedzc2a1gz1ujz
Tags: upstream-5.60.48.36+bdcom
ImportĀ upstreamĀ versionĀ 5.60.48.36+bdcom

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * local version of endian.h - byte order defines
 
2
 * Byte order utilities
3
3
 *
4
 
 * Copyright 2008, Broadcom Corporation
 
4
 * Copyright (C) 2010, Broadcom Corporation
5
5
 * All Rights Reserved.
6
6
 * 
7
 
 *      Unless you and Broadcom execute a separate written software license
8
 
 * agreement governing use of this software, this software is licensed to you
9
 
 * under the terms of the GNU General Public License version 2, available at
10
 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"), with the
11
 
 * following added to such license:
12
 
 *      As a special exception, the copyright holders of this software give you
13
 
 * permission to link this software with independent modules, regardless of the
14
 
 * license terms of these independent modules, and to copy and distribute the
15
 
 * resulting executable under terms of your choice, provided that you also meet,
16
 
 * for each linked independent module, the terms and conditions of the license
17
 
 * of that module. An independent module is a module which is not derived from
18
 
 * this software.
19
 
 *
20
7
 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
21
8
 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
22
9
 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
23
10
 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
24
11
 *
25
 
 *  $Id: bcmendian.h,v 1.31 2005/09/03 22:24:22 Exp $
26
 
*/
 
12
 *  $Id: bcmendian.h,v 1.34 2008/09/17 22:52:25 Exp $
 
13
 *
 
14
 * This file by default provides proper behavior on little-endian architectures.
 
15
 * On big-endian architectures, IL_BIGENDIAN should be defined.
 
16
 */
27
17
 
28
18
#ifndef _BCMENDIAN_H_
29
19
#define _BCMENDIAN_H_
31
21
#include <typedefs.h>
32
22
 
33
23
#define BCMSWAP16(val) \
34
 
        ((uint16)(\
35
 
                (((uint16)(val) & (uint16)0x00ffU) << 8) | \
36
 
                (((uint16)(val) & (uint16)0xff00U) >> 8)))
 
24
        ((uint16)((((uint16)(val) & (uint16)0x00ffU) << 8) | \
 
25
                  (((uint16)(val) & (uint16)0xff00U) >> 8)))
37
26
 
38
27
#define BCMSWAP32(val) \
39
 
        ((uint32)(\
40
 
                (((uint32)(val) & (uint32)0x000000ffUL) << 24) | \
41
 
                (((uint32)(val) & (uint32)0x0000ff00UL) <<  8) | \
42
 
                (((uint32)(val) & (uint32)0x00ff0000UL) >>  8) | \
43
 
                (((uint32)(val) & (uint32)0xff000000UL) >> 24)))
 
28
        ((uint32)((((uint32)(val) & (uint32)0x000000ffU) << 24) | \
 
29
                  (((uint32)(val) & (uint32)0x0000ff00U) <<  8) | \
 
30
                  (((uint32)(val) & (uint32)0x00ff0000U) >>  8) | \
 
31
                  (((uint32)(val) & (uint32)0xff000000U) >> 24)))
44
32
 
45
33
#define BCMSWAP32BY16(val) \
46
 
        ((uint32)(\
47
 
                (((uint32)(val) & (uint32)0x0000ffffUL) << 16) | \
48
 
                (((uint32)(val) & (uint32)0xffff0000UL) >> 16)))
 
34
        ((uint32)((((uint32)(val) & (uint32)0x0000ffffU) << 16) | \
 
35
                  (((uint32)(val) & (uint32)0xffff0000U) >> 16)))
49
36
 
50
37
static INLINE uint16
51
38
bcmswap16(uint16 val)
68
55
static INLINE void
69
56
bcmswap16_buf(uint16 *buf, uint len)
70
57
{
71
 
        len = len/2;
 
58
        len = len / 2;
72
59
 
73
60
        while (len--) {
74
61
                *buf = bcmswap16(*buf);
79
66
#ifndef hton16
80
67
#define HTON16(i) BCMSWAP16(i)
81
68
#define hton16(i) bcmswap16(i)
 
69
#define HTON32(i) BCMSWAP32(i)
82
70
#define hton32(i) bcmswap32(i)
 
71
#define NTOH16(i) BCMSWAP16(i)
83
72
#define ntoh16(i) bcmswap16(i)
 
73
#define NTOH32(i) BCMSWAP32(i)
84
74
#define ntoh32(i) bcmswap32(i)
 
75
#define LTOH16(i) (i)
85
76
#define ltoh16(i) (i)
 
77
#define LTOH32(i) (i)
86
78
#define ltoh32(i) (i)
 
79
#define HTOL16(i) (i)
87
80
#define htol16(i) (i)
 
81
#define HTOL32(i) (i)
88
82
#define htol32(i) (i)
89
83
#endif 
90
84
 
94
88
static INLINE void
95
89
htol16_ua_store(uint16 val, uint8 *bytes)
96
90
{
97
 
        bytes[0] = val&0xff;
98
 
        bytes[1] = val>>8;
 
91
        bytes[0] = val & 0xff;
 
92
        bytes[1] = val >> 8;
99
93
}
100
94
 
101
95
static INLINE void
102
96
htol32_ua_store(uint32 val, uint8 *bytes)
103
97
{
104
 
        bytes[0] = val&0xff;
105
 
        bytes[1] = (val>>8)&0xff;
106
 
        bytes[2] = (val>>16)&0xff;
107
 
        bytes[3] = val>>24;
 
98
        bytes[0] = val & 0xff;
 
99
        bytes[1] = (val >> 8) & 0xff;
 
100
        bytes[2] = (val >> 16) & 0xff;
 
101
        bytes[3] = val >> 24;
108
102
}
109
103
 
110
104
static INLINE void
111
105
hton16_ua_store(uint16 val, uint8 *bytes)
112
106
{
113
 
        bytes[1] = val&0xff;
114
 
        bytes[0] = val>>8;
 
107
        bytes[0] = val >> 8;
 
108
        bytes[1] = val & 0xff;
115
109
}
116
110
 
117
111
static INLINE void
118
112
hton32_ua_store(uint32 val, uint8 *bytes)
119
113
{
120
 
        bytes[3] = val&0xff;
121
 
        bytes[2] = (val>>8)&0xff;
122
 
        bytes[1] = (val>>16)&0xff;
123
 
        bytes[0] = val>>24;
124
 
}
125
 
 
126
 
static INLINE uint16
127
 
ltoh16_ua(void *bytes)
128
 
{
129
 
        return (((uint8*)bytes)[1]<<8)+((uint8 *)bytes)[0];
130
 
}
131
 
 
132
 
static INLINE uint32
133
 
ltoh32_ua(void *bytes)
134
 
{
135
 
        return (((uint8*)bytes)[3]<<24)+(((uint8*)bytes)[2]<<16)+
136
 
               (((uint8*)bytes)[1]<<8)+((uint8*)bytes)[0];
137
 
}
138
 
 
139
 
static INLINE uint16
140
 
ntoh16_ua(void *bytes)
141
 
{
142
 
        return (((uint8*)bytes)[0]<<8)+((uint8*)bytes)[1];
143
 
}
144
 
 
145
 
static INLINE uint32
146
 
ntoh32_ua(void *bytes)
147
 
{
148
 
        return (((uint8*)bytes)[0]<<24)+(((uint8*)bytes)[1]<<16)+
149
 
               (((uint8*)bytes)[2]<<8)+((uint8*)bytes)[3];
150
 
}
151
 
 
152
 
#define ltoh_ua(ptr) (\
153
 
        sizeof(*(ptr)) == sizeof(uint8) ?  *(uint8 *)ptr : \
154
 
        sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] : \
155
 
        (((uint8 *)ptr)[3]<<24)+(((uint8 *)ptr)[2]<<16)+(((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] \
156
 
)
157
 
 
158
 
#define ntoh_ua(ptr) (\
159
 
        sizeof(*(ptr)) == sizeof(uint8) ?  *(uint8 *)ptr : \
160
 
        sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[0]<<8)+((uint8 *)ptr)[1] : \
161
 
        (((uint8 *)ptr)[0]<<24)+(((uint8 *)ptr)[1]<<16)+(((uint8 *)ptr)[2]<<8)+((uint8 *)ptr)[3] \
162
 
)
 
114
        bytes[0] = val >> 24;
 
115
        bytes[1] = (val >> 16) & 0xff;
 
116
        bytes[2] = (val >> 8) & 0xff;
 
117
        bytes[3] = val & 0xff;
 
118
}
 
119
 
 
120
#define _LTOH16_UA(cp)  ((cp)[0] | ((cp)[1] << 8))
 
121
#define _LTOH32_UA(cp)  ((cp)[0] | ((cp)[1] << 8) | ((cp)[2] << 16) | ((cp)[3] << 24))
 
122
#define _NTOH16_UA(cp)  (((cp)[0] << 8) | (cp)[1])
 
123
#define _NTOH32_UA(cp)  (((cp)[0] << 24) | ((cp)[1] << 16) | ((cp)[2] << 8) | (cp)[3])
 
124
 
 
125
static INLINE uint16
 
126
ltoh16_ua(const void *bytes)
 
127
{
 
128
        return _LTOH16_UA((const uint8 *)bytes);
 
129
}
 
130
 
 
131
static INLINE uint32
 
132
ltoh32_ua(const void *bytes)
 
133
{
 
134
        return _LTOH32_UA((const uint8 *)bytes);
 
135
}
 
136
 
 
137
static INLINE uint16
 
138
ntoh16_ua(const void *bytes)
 
139
{
 
140
        return _NTOH16_UA((const uint8 *)bytes);
 
141
}
 
142
 
 
143
static INLINE uint32
 
144
ntoh32_ua(const void *bytes)
 
145
{
 
146
        return _NTOH32_UA((const uint8 *)bytes);
 
147
}
 
148
 
 
149
#define ltoh_ua(ptr) \
 
150
        (sizeof(*(ptr)) == sizeof(uint8) ? *(const uint8 *)ptr : \
 
151
         sizeof(*(ptr)) == sizeof(uint16) ? _LTOH16_UA((const uint8 *)ptr) : \
 
152
         sizeof(*(ptr)) == sizeof(uint32) ? _LTOH32_UA((const uint8 *)ptr) : \
 
153
         0xfeedf00d)
 
154
 
 
155
#define ntoh_ua(ptr) \
 
156
        (sizeof(*(ptr)) == sizeof(uint8) ? *(const uint8 *)ptr : \
 
157
         sizeof(*(ptr)) == sizeof(uint16) ? _NTOH16_UA((const uint8 *)ptr) : \
 
158
         sizeof(*(ptr)) == sizeof(uint32) ? _NTOH32_UA((const uint8 *)ptr) : \
 
159
         0xfeedf00d)
163
160
 
164
161
#endif