2 * Copyright (c) 2011, 2012, Atheros Communications Inc.
3 * Copyright (c) 2014, I2SE GmbH
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose with or without fee is hereby granted, provided
7 * that the above copyright notice and this permission notice appear
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Atheros ethernet framing. Every Ethernet frame is surrounded
21 * by an atheros frame while transmitted over a serial channel;
24 #include <linux/kernel.h>
26 #include "qca_framing.h"
29 qcafrm_create_header(u8
*buf
, u16 length
)
36 len
= cpu_to_le16(length
);
43 buf
[5] = (len
>> 8) & 0xff;
47 return QCAFRM_HEADER_LEN
;
51 qcafrm_create_footer(u8
*buf
)
58 return QCAFRM_FOOTER_LEN
;
61 /* Gather received bytes and try to extract a full ethernet frame by
62 * following a simple state machine.
64 * Return: QCAFRM_GATHER No ethernet frame fully received yet.
65 * QCAFRM_NOHEAD Header expected but not found.
66 * QCAFRM_INVLEN Atheros frame length is invalid
67 * QCAFRM_NOTAIL Footer expected but not found.
68 * > 0 Number of byte in the fully received
73 qcafrm_fsm_decode(struct qcafrm_handle
*handle
, u8
*buf
, u16 buf_len
, u8 recv_byte
)
75 s32 ret
= QCAFRM_GATHER
;
78 switch (handle
->state
) {
81 /* by default, just go to next state */
84 if (recv_byte
!= 0x00) {
85 /* first two bytes of length must be 0 */
86 handle
->state
= QCAFRM_HW_LEN0
;
93 /* 4 bytes header pattern */
98 if (recv_byte
!= 0xAA) {
100 handle
->state
= QCAFRM_HW_LEN0
;
105 /* 2 bytes length. */
106 /* Borrow offset field to hold length for now. */
107 case QCAFRM_WAIT_LEN_BYTE0
:
108 handle
->offset
= recv_byte
;
109 handle
->state
= QCAFRM_WAIT_LEN_BYTE1
;
111 case QCAFRM_WAIT_LEN_BYTE1
:
112 handle
->offset
= handle
->offset
| (recv_byte
<< 8);
113 handle
->state
= QCAFRM_WAIT_RSVD_BYTE1
;
115 case QCAFRM_WAIT_RSVD_BYTE1
:
116 handle
->state
= QCAFRM_WAIT_RSVD_BYTE2
;
118 case QCAFRM_WAIT_RSVD_BYTE2
:
119 len
= handle
->offset
;
120 if (len
> buf_len
|| len
< QCAFRM_ETHMINLEN
) {
122 handle
->state
= QCAFRM_HW_LEN0
;
124 handle
->state
= (enum qcafrm_state
)(len
+ 1);
125 /* Remaining number of bytes. */
130 /* Receiving Ethernet frame itself. */
131 buf
[handle
->offset
] = recv_byte
;
135 case QCAFRM_WAIT_551
:
136 if (recv_byte
!= 0x55) {
138 handle
->state
= QCAFRM_HW_LEN0
;
140 handle
->state
= QCAFRM_WAIT_552
;
143 case QCAFRM_WAIT_552
:
144 if (recv_byte
!= 0x55) {
146 handle
->state
= QCAFRM_HW_LEN0
;
148 ret
= handle
->offset
;
149 /* Frame is fully received. */
150 handle
->state
= QCAFRM_HW_LEN0
;
This page took 0.033998 seconds and 5 git commands to generate.