Lines Matching +full:magic +full:- +full:packet
1 // SPDX-License-Identifier: GPL-2.0-or-later
28 * replaces the standard ethernet header in a packet so only actual
43 __le32 magic; member
62 return -ENOMEM; in vl600_bind()
70 dev->driver_priv = s; in vl600_bind()
78 * packet depend only on whether it is on the IN or OUT endpoint. */ in vl600_bind()
79 dev->net->flags |= IFF_NOARP; in vl600_bind()
81 dev->net->flags |= IFF_MULTICAST; in vl600_bind()
88 struct vl600_state *s = dev->driver_priv; in vl600_unbind()
90 dev_kfree_skb(s->current_rx_buf); in vl600_unbind()
99 struct vl600_pkt_hdr *packet; in vl600_rx_fixup() local
104 struct vl600_state *s = dev->driver_priv; in vl600_rx_fixup()
110 /* Allow a packet (or multiple packets batched together) to be in vl600_rx_fixup()
114 if (s->current_rx_buf) { in vl600_rx_fixup()
115 frame = (struct vl600_frame_hdr *) s->current_rx_buf->data; in vl600_rx_fixup()
116 if (skb->len + s->current_rx_buf->len > in vl600_rx_fixup()
117 le32_to_cpup(&frame->len)) { in vl600_rx_fixup()
118 netif_err(dev, ifup, dev->net, "Fragment too long\n"); in vl600_rx_fixup()
119 dev->net->stats.rx_length_errors++; in vl600_rx_fixup()
123 buf = s->current_rx_buf; in vl600_rx_fixup()
124 skb_put_data(buf, skb->data, skb->len); in vl600_rx_fixup()
125 } else if (skb->len < 4) { in vl600_rx_fixup()
126 netif_err(dev, ifup, dev->net, "Frame too short\n"); in vl600_rx_fixup()
127 dev->net->stats.rx_length_errors++; in vl600_rx_fixup()
131 frame = (struct vl600_frame_hdr *) buf->data; in vl600_rx_fixup()
132 /* Yes, check that frame->magic == 0x53544448 (or 0x44544d48), in vl600_rx_fixup()
133 * otherwise we may run out of memory w/a bad packet */ in vl600_rx_fixup()
134 if (ntohl(frame->magic) != 0x53544448 && in vl600_rx_fixup()
135 ntohl(frame->magic) != 0x44544d48) in vl600_rx_fixup()
138 if (buf->len < sizeof(*frame) || in vl600_rx_fixup()
139 buf->len != le32_to_cpup(&frame->len)) { in vl600_rx_fixup()
141 if (s->current_rx_buf) in vl600_rx_fixup()
144 s->current_rx_buf = skb_copy_expand(skb, 0, in vl600_rx_fixup()
145 le32_to_cpup(&frame->len), GFP_ATOMIC); in vl600_rx_fixup()
146 if (!s->current_rx_buf) in vl600_rx_fixup()
147 dev->net->stats.rx_errors++; in vl600_rx_fixup()
152 count = le32_to_cpup(&frame->pkt_cnt); in vl600_rx_fixup()
156 while (count--) { in vl600_rx_fixup()
157 if (buf->len < sizeof(*packet)) { in vl600_rx_fixup()
158 netif_err(dev, ifup, dev->net, "Packet too short\n"); in vl600_rx_fixup()
162 packet = (struct vl600_pkt_hdr *) buf->data; in vl600_rx_fixup()
163 packet_len = sizeof(*packet) + le32_to_cpup(&packet->len); in vl600_rx_fixup()
164 if (packet_len > buf->len) { in vl600_rx_fixup()
165 netif_err(dev, ifup, dev->net, in vl600_rx_fixup()
166 "Bad packet length stored in header\n"); in vl600_rx_fixup()
170 /* Packet header is same size as the ethernet header in vl600_rx_fixup()
171 * (sizeof(*packet) == sizeof(*ethhdr)), additionally in vl600_rx_fixup()
175 ethhdr = (struct ethhdr *) skb->data; in vl600_rx_fixup()
176 if (be16_to_cpup(ðhdr->h_proto) == ETH_P_ARP && in vl600_rx_fixup()
177 buf->len > 0x26) { in vl600_rx_fixup()
178 /* Copy the addresses from packet contents */ in vl600_rx_fixup()
179 memcpy(ethhdr->h_source, in vl600_rx_fixup()
180 &buf->data[sizeof(*ethhdr) + 0x8], in vl600_rx_fixup()
182 memcpy(ethhdr->h_dest, in vl600_rx_fixup()
183 &buf->data[sizeof(*ethhdr) + 0x12], in vl600_rx_fixup()
186 eth_zero_addr(ethhdr->h_source); in vl600_rx_fixup()
187 memcpy(ethhdr->h_dest, dev->net->dev_addr, ETH_ALEN); in vl600_rx_fixup()
194 if ((buf->data[sizeof(*ethhdr)] & 0xf0) == 0x60) in vl600_rx_fixup()
195 ethhdr->h_proto = htons(ETH_P_IPV6); in vl600_rx_fixup()
199 /* Not the last packet in this batch */ in vl600_rx_fixup()
211 if (s->current_rx_buf) { in vl600_rx_fixup()
213 s->current_rx_buf = NULL; in vl600_rx_fixup()
222 if (s->current_rx_buf) { in vl600_rx_fixup()
223 dev_kfree_skb_any(s->current_rx_buf); in vl600_rx_fixup()
224 s->current_rx_buf = NULL; in vl600_rx_fixup()
226 dev->net->stats.rx_errors++; in vl600_rx_fixup()
235 struct vl600_pkt_hdr *packet; in vl600_tx_fixup() local
237 int orig_len = skb->len - sizeof(struct ethhdr); in vl600_tx_fixup()
238 int full_len = (skb->len + sizeof(struct vl600_frame_hdr) + 3) & ~3; in vl600_tx_fixup()
240 frame = (struct vl600_frame_hdr *) skb->data; in vl600_tx_fixup()
241 if (skb->len > sizeof(*frame) && skb->len == le32_to_cpup(&frame->len)) in vl600_tx_fixup()
244 if (skb->len < sizeof(struct ethhdr)) in vl600_tx_fixup()
252 if (tailroom >= full_len - skb->len - sizeof(*frame) && in vl600_tx_fixup()
257 if (headroom + tailroom + skb->len >= full_len) { in vl600_tx_fixup()
259 skb->data = memmove(skb->head + sizeof(*frame), in vl600_tx_fixup()
260 skb->data, skb->len); in vl600_tx_fixup()
261 skb_set_tail_pointer(skb, skb->len); in vl600_tx_fixup()
267 ret = skb_copy_expand(skb, sizeof(struct vl600_frame_hdr), full_len - in vl600_tx_fixup()
268 skb->len - sizeof(struct vl600_frame_hdr), flags); in vl600_tx_fixup()
275 /* Packet header is same size as ethernet packet header in vl600_tx_fixup()
276 * (sizeof(*packet) == sizeof(struct ethhdr)), additionally the in vl600_tx_fixup()
280 packet = (struct vl600_pkt_hdr *) skb->data; in vl600_tx_fixup()
285 packet->h_proto = htons(ETH_P_IP); in vl600_tx_fixup()
286 memset(&packet->dummy, 0, sizeof(packet->dummy)); in vl600_tx_fixup()
287 packet->len = cpu_to_le32(orig_len); in vl600_tx_fixup()
291 frame->len = cpu_to_le32(full_len); in vl600_tx_fixup()
292 frame->serial = cpu_to_le32(serial++); in vl600_tx_fixup()
293 frame->pkt_cnt = cpu_to_le32(1); in vl600_tx_fixup()
295 if (skb->len < full_len) /* Pad */ in vl600_tx_fixup()
296 skb_put(skb, full_len - skb->len); in vl600_tx_fixup()
322 .name = "lg-vl600",
334 MODULE_DESCRIPTION("LG-VL600 modem's ethernet link");