Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * USB network interface driver for Samsung Kalmia based LTE USB modem like the
4 * Samsung GT-B3730 and GT-B3710.
5 *
6 * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
7 *
8 * Sponsored by Quicklink Video Distribution Services Ltd.
9 *
10 * Based on the cdc_eem module.
11 */
12
13#include <linux/module.h>
14#include <linux/netdevice.h>
15#include <linux/etherdevice.h>
16#include <linux/ctype.h>
17#include <linux/ethtool.h>
18#include <linux/workqueue.h>
19#include <linux/mii.h>
20#include <linux/usb.h>
21#include <linux/crc32.h>
22#include <linux/usb/cdc.h>
23#include <linux/usb/usbnet.h>
24#include <linux/gfp.h>
25
26/*
27 * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
28 * handled by the "option" module and an ethernet data port handled by this
29 * module.
30 *
31 * The stick must first be switched into modem mode by usb_modeswitch
32 * or similar tool. Then the modem gets sent two initialization packets by
33 * this module, which gives the MAC address of the device. User space can then
34 * connect the modem using AT commands through the ACM port and then use
35 * DHCP on the network interface exposed by this module. Network packets are
36 * sent to and from the modem in a proprietary format discovered after watching
37 * the behavior of the windows driver for the modem.
38 *
39 * More information about the use of the modem is available in usb_modeswitch
40 * forum and the project page:
41 *
42 * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
43 * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
44 */
45
46/* #define DEBUG */
47/* #define VERBOSE */
48
49#define KALMIA_HEADER_LENGTH 6
50#define KALMIA_ALIGN_SIZE 4
51#define KALMIA_USB_TIMEOUT 10000
52
53/*-------------------------------------------------------------------------*/
54
55static int
56kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
57 u8 *buffer, u8 expected_len)
58{
59 int act_len;
60 int status;
61
62 netdev_dbg(dev->net, "Sending init packet");
63
64 status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
65 init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
66 if (status != 0) {
67 netdev_err(dev->net,
68 "Error sending init packet. Status %i\n",
69 status);
70 return status;
71 }
72 else if (act_len != init_msg_len) {
73 netdev_err(dev->net,
74 "Did not send all of init packet. Bytes sent: %i",
75 act_len);
76 }
77 else {
78 netdev_dbg(dev->net, "Successfully sent init packet.");
79 }
80
81 status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
82 buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
83
84 if (status != 0)
85 netdev_err(dev->net,
86 "Error receiving init result. Status %i\n",
87 status);
88 else if (act_len != expected_len)
89 netdev_err(dev->net, "Unexpected init result length: %i\n",
90 act_len);
91
92 return status;
93}
94
95static int
96kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
97{
98 static const char init_msg_1[] =
99 { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
100 0x00, 0x00 };
101 static const char init_msg_2[] =
102 { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
103 0x00, 0x00 };
104 static const int buflen = 28;
105 char *usb_buf;
106 int status;
107
108 usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
109 if (!usb_buf)
110 return -ENOMEM;
111
112 memcpy(usb_buf, init_msg_1, 12);
113 status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_1),
114 usb_buf, 24);
115 if (status != 0)
116 goto out;
117
118 memcpy(usb_buf, init_msg_2, 12);
119 status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_2),
120 usb_buf, 28);
121 if (status != 0)
122 goto out;
123
124 memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
125out:
126 kfree(usb_buf);
127 return status;
128}
129
130static int
131kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
132{
133 int status;
134 u8 ethernet_addr[ETH_ALEN];
135
136 /* Don't bind to AT command interface */
137 if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
138 return -EINVAL;
139
140 dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
141 dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
142 dev->status = NULL;
143
144 dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
145 dev->hard_mtu = 1400;
146 dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
147
148 status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
149 if (status)
150 return status;
151
152 eth_hw_addr_set(dev->net, ethernet_addr);
153
154 return status;
155}
156
157static struct sk_buff *
158kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
159{
160 struct sk_buff *skb2 = NULL;
161 u16 content_len;
162 unsigned char *header_start;
163 unsigned char ether_type_1, ether_type_2;
164 u8 remainder, padlen = 0;
165
166 if (!skb_cloned(skb)) {
167 int headroom = skb_headroom(skb);
168 int tailroom = skb_tailroom(skb);
169
170 if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
171 >= KALMIA_HEADER_LENGTH))
172 goto done;
173
174 if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
175 + KALMIA_ALIGN_SIZE)) {
176 skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
177 skb->data, skb->len);
178 skb_set_tail_pointer(skb, skb->len);
179 goto done;
180 }
181 }
182
183 skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
184 KALMIA_ALIGN_SIZE, flags);
185 if (!skb2)
186 return NULL;
187
188 dev_kfree_skb_any(skb);
189 skb = skb2;
190
191done:
192 header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
193 ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
194 ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
195
196 netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
197 ether_type_2);
198
199 /* According to empiric data for data packages */
200 header_start[0] = 0x57;
201 header_start[1] = 0x44;
202 content_len = skb->len - KALMIA_HEADER_LENGTH;
203
204 put_unaligned_le16(content_len, &header_start[2]);
205 header_start[4] = ether_type_1;
206 header_start[5] = ether_type_2;
207
208 /* Align to 4 bytes by padding with zeros */
209 remainder = skb->len % KALMIA_ALIGN_SIZE;
210 if (remainder > 0) {
211 padlen = KALMIA_ALIGN_SIZE - remainder;
212 skb_put_zero(skb, padlen);
213 }
214
215 netdev_dbg(dev->net,
216 "Sending package with length %i and padding %i. Header: %6phC.",
217 content_len, padlen, header_start);
218
219 return skb;
220}
221
222static int
223kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
224{
225 /*
226 * Our task here is to strip off framing, leaving skb with one
227 * data frame for the usbnet framework code to process.
228 */
229 static const u8 HEADER_END_OF_USB_PACKET[] =
230 { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
231 static const u8 EXPECTED_UNKNOWN_HEADER_1[] =
232 { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
233 static const u8 EXPECTED_UNKNOWN_HEADER_2[] =
234 { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
235 int i = 0;
236
237 /* incomplete header? */
238 if (skb->len < KALMIA_HEADER_LENGTH)
239 return 0;
240
241 do {
242 struct sk_buff *skb2 = NULL;
243 u8 *header_start;
244 u16 usb_packet_length, ether_packet_length;
245 int is_last;
246
247 header_start = skb->data;
248
249 if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
250 if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
251 sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
252 header_start, EXPECTED_UNKNOWN_HEADER_2,
253 sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
254 netdev_dbg(dev->net,
255 "Received expected unknown frame header: %6phC. Package length: %i\n",
256 header_start,
257 skb->len - KALMIA_HEADER_LENGTH);
258 }
259 else {
260 netdev_err(dev->net,
261 "Received unknown frame header: %6phC. Package length: %i\n",
262 header_start,
263 skb->len - KALMIA_HEADER_LENGTH);
264 return 0;
265 }
266 }
267 else
268 netdev_dbg(dev->net,
269 "Received header: %6phC. Package length: %i\n",
270 header_start, skb->len - KALMIA_HEADER_LENGTH);
271
272 /* subtract start header and end header */
273 usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
274 ether_packet_length = get_unaligned_le16(&header_start[2]);
275 skb_pull(skb, KALMIA_HEADER_LENGTH);
276
277 /* Some small packets misses end marker */
278 if (usb_packet_length < ether_packet_length) {
279 ether_packet_length = usb_packet_length
280 + KALMIA_HEADER_LENGTH;
281 is_last = true;
282 }
283 else {
284 netdev_dbg(dev->net, "Correct package length #%i", i
285 + 1);
286
287 is_last = (memcmp(skb->data + ether_packet_length,
288 HEADER_END_OF_USB_PACKET,
289 sizeof(HEADER_END_OF_USB_PACKET)) == 0);
290 if (!is_last) {
291 header_start = skb->data + ether_packet_length;
292 netdev_dbg(dev->net,
293 "End header: %6phC. Package length: %i\n",
294 header_start,
295 skb->len - KALMIA_HEADER_LENGTH);
296 }
297 }
298
299 if (is_last) {
300 skb2 = skb;
301 }
302 else {
303 skb2 = skb_clone(skb, GFP_ATOMIC);
304 if (unlikely(!skb2))
305 return 0;
306 }
307
308 skb_trim(skb2, ether_packet_length);
309
310 if (is_last) {
311 return 1;
312 }
313 else {
314 usbnet_skb_return(dev, skb2);
315 skb_pull(skb, ether_packet_length);
316 }
317
318 i++;
319 }
320 while (skb->len);
321
322 return 1;
323}
324
325static const struct driver_info kalmia_info = {
326 .description = "Samsung Kalmia LTE USB dongle",
327 .flags = FLAG_WWAN,
328 .bind = kalmia_bind,
329 .rx_fixup = kalmia_rx_fixup,
330 .tx_fixup = kalmia_tx_fixup
331};
332
333/*-------------------------------------------------------------------------*/
334
335static const struct usb_device_id products[] = {
336 /* The unswitched USB ID, to get the module auto loaded: */
337 { USB_DEVICE(0x04e8, 0x689a) },
338 /* The stick switched into modem (by e.g. usb_modeswitch): */
339 { USB_DEVICE(0x04e8, 0x6889),
340 .driver_info = (unsigned long) &kalmia_info, },
341 { /* EMPTY == end of list */} };
342MODULE_DEVICE_TABLE( usb, products);
343
344static struct usb_driver kalmia_driver = {
345 .name = "kalmia",
346 .id_table = products,
347 .probe = usbnet_probe,
348 .disconnect = usbnet_disconnect,
349 .suspend = usbnet_suspend,
350 .resume = usbnet_resume,
351 .disable_hub_initiated_lpm = 1,
352};
353
354module_usb_driver(kalmia_driver);
355
356MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
357MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
358MODULE_LICENSE("GPL");
1/*
2 * USB network interface driver for Samsung Kalmia based LTE USB modem like the
3 * Samsung GT-B3730 and GT-B3710.
4 *
5 * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
6 *
7 * Sponsored by Quicklink Video Distribution Services Ltd.
8 *
9 * Based on the cdc_eem module.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include <linux/module.h>
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
20#include <linux/ctype.h>
21#include <linux/ethtool.h>
22#include <linux/workqueue.h>
23#include <linux/mii.h>
24#include <linux/usb.h>
25#include <linux/crc32.h>
26#include <linux/usb/cdc.h>
27#include <linux/usb/usbnet.h>
28#include <linux/gfp.h>
29
30/*
31 * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
32 * handled by the "option" module and an ethernet data port handled by this
33 * module.
34 *
35 * The stick must first be switched into modem mode by usb_modeswitch
36 * or similar tool. Then the modem gets sent two initialization packets by
37 * this module, which gives the MAC address of the device. User space can then
38 * connect the modem using AT commands through the ACM port and then use
39 * DHCP on the network interface exposed by this module. Network packets are
40 * sent to and from the modem in a proprietary format discovered after watching
41 * the behavior of the windows driver for the modem.
42 *
43 * More information about the use of the modem is available in usb_modeswitch
44 * forum and the project page:
45 *
46 * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
47 * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
48 */
49
50/* #define DEBUG */
51/* #define VERBOSE */
52
53#define KALMIA_HEADER_LENGTH 6
54#define KALMIA_ALIGN_SIZE 4
55#define KALMIA_USB_TIMEOUT 10000
56
57/*-------------------------------------------------------------------------*/
58
59static int
60kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
61 u8 *buffer, u8 expected_len)
62{
63 int act_len;
64 int status;
65
66 netdev_dbg(dev->net, "Sending init packet");
67
68 status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
69 init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
70 if (status != 0) {
71 netdev_err(dev->net,
72 "Error sending init packet. Status %i, length %i\n",
73 status, act_len);
74 return status;
75 }
76 else if (act_len != init_msg_len) {
77 netdev_err(dev->net,
78 "Did not send all of init packet. Bytes sent: %i",
79 act_len);
80 }
81 else {
82 netdev_dbg(dev->net, "Successfully sent init packet.");
83 }
84
85 status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
86 buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
87
88 if (status != 0)
89 netdev_err(dev->net,
90 "Error receiving init result. Status %i, length %i\n",
91 status, act_len);
92 else if (act_len != expected_len)
93 netdev_err(dev->net, "Unexpected init result length: %i\n",
94 act_len);
95
96 return status;
97}
98
99static int
100kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
101{
102 static const char init_msg_1[] =
103 { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
104 0x00, 0x00 };
105 static const char init_msg_2[] =
106 { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
107 0x00, 0x00 };
108 static const int buflen = 28;
109 char *usb_buf;
110 int status;
111
112 usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
113 if (!usb_buf)
114 return -ENOMEM;
115
116 memcpy(usb_buf, init_msg_1, 12);
117 status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_1),
118 usb_buf, 24);
119 if (status != 0)
120 return status;
121
122 memcpy(usb_buf, init_msg_2, 12);
123 status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_2),
124 usb_buf, 28);
125 if (status != 0)
126 return status;
127
128 memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
129
130 kfree(usb_buf);
131 return status;
132}
133
134static int
135kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
136{
137 int status;
138 u8 ethernet_addr[ETH_ALEN];
139
140 /* Don't bind to AT command interface */
141 if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
142 return -EINVAL;
143
144 dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
145 dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
146 dev->status = NULL;
147
148 dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
149 dev->hard_mtu = 1400;
150 dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
151
152 status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
153 if (status)
154 return status;
155
156 memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
157
158 return status;
159}
160
161static struct sk_buff *
162kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
163{
164 struct sk_buff *skb2 = NULL;
165 u16 content_len;
166 unsigned char *header_start;
167 unsigned char ether_type_1, ether_type_2;
168 u8 remainder, padlen = 0;
169
170 if (!skb_cloned(skb)) {
171 int headroom = skb_headroom(skb);
172 int tailroom = skb_tailroom(skb);
173
174 if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
175 >= KALMIA_HEADER_LENGTH))
176 goto done;
177
178 if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
179 + KALMIA_ALIGN_SIZE)) {
180 skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
181 skb->data, skb->len);
182 skb_set_tail_pointer(skb, skb->len);
183 goto done;
184 }
185 }
186
187 skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
188 KALMIA_ALIGN_SIZE, flags);
189 if (!skb2)
190 return NULL;
191
192 dev_kfree_skb_any(skb);
193 skb = skb2;
194
195done:
196 header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
197 ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
198 ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
199
200 netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
201 ether_type_2);
202
203 /* According to empiric data for data packages */
204 header_start[0] = 0x57;
205 header_start[1] = 0x44;
206 content_len = skb->len - KALMIA_HEADER_LENGTH;
207
208 put_unaligned_le16(content_len, &header_start[2]);
209 header_start[4] = ether_type_1;
210 header_start[5] = ether_type_2;
211
212 /* Align to 4 bytes by padding with zeros */
213 remainder = skb->len % KALMIA_ALIGN_SIZE;
214 if (remainder > 0) {
215 padlen = KALMIA_ALIGN_SIZE - remainder;
216 skb_put_zero(skb, padlen);
217 }
218
219 netdev_dbg(dev->net,
220 "Sending package with length %i and padding %i. Header: %6phC.",
221 content_len, padlen, header_start);
222
223 return skb;
224}
225
226static int
227kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
228{
229 /*
230 * Our task here is to strip off framing, leaving skb with one
231 * data frame for the usbnet framework code to process.
232 */
233 static const u8 HEADER_END_OF_USB_PACKET[] =
234 { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
235 static const u8 EXPECTED_UNKNOWN_HEADER_1[] =
236 { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
237 static const u8 EXPECTED_UNKNOWN_HEADER_2[] =
238 { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
239 int i = 0;
240
241 /* incomplete header? */
242 if (skb->len < KALMIA_HEADER_LENGTH)
243 return 0;
244
245 do {
246 struct sk_buff *skb2 = NULL;
247 u8 *header_start;
248 u16 usb_packet_length, ether_packet_length;
249 int is_last;
250
251 header_start = skb->data;
252
253 if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
254 if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
255 sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
256 header_start, EXPECTED_UNKNOWN_HEADER_2,
257 sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
258 netdev_dbg(dev->net,
259 "Received expected unknown frame header: %6phC. Package length: %i\n",
260 header_start,
261 skb->len - KALMIA_HEADER_LENGTH);
262 }
263 else {
264 netdev_err(dev->net,
265 "Received unknown frame header: %6phC. Package length: %i\n",
266 header_start,
267 skb->len - KALMIA_HEADER_LENGTH);
268 return 0;
269 }
270 }
271 else
272 netdev_dbg(dev->net,
273 "Received header: %6phC. Package length: %i\n",
274 header_start, skb->len - KALMIA_HEADER_LENGTH);
275
276 /* subtract start header and end header */
277 usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
278 ether_packet_length = get_unaligned_le16(&header_start[2]);
279 skb_pull(skb, KALMIA_HEADER_LENGTH);
280
281 /* Some small packets misses end marker */
282 if (usb_packet_length < ether_packet_length) {
283 ether_packet_length = usb_packet_length
284 + KALMIA_HEADER_LENGTH;
285 is_last = true;
286 }
287 else {
288 netdev_dbg(dev->net, "Correct package length #%i", i
289 + 1);
290
291 is_last = (memcmp(skb->data + ether_packet_length,
292 HEADER_END_OF_USB_PACKET,
293 sizeof(HEADER_END_OF_USB_PACKET)) == 0);
294 if (!is_last) {
295 header_start = skb->data + ether_packet_length;
296 netdev_dbg(dev->net,
297 "End header: %6phC. Package length: %i\n",
298 header_start,
299 skb->len - KALMIA_HEADER_LENGTH);
300 }
301 }
302
303 if (is_last) {
304 skb2 = skb;
305 }
306 else {
307 skb2 = skb_clone(skb, GFP_ATOMIC);
308 if (unlikely(!skb2))
309 return 0;
310 }
311
312 skb_trim(skb2, ether_packet_length);
313
314 if (is_last) {
315 return 1;
316 }
317 else {
318 usbnet_skb_return(dev, skb2);
319 skb_pull(skb, ether_packet_length);
320 }
321
322 i++;
323 }
324 while (skb->len);
325
326 return 1;
327}
328
329static const struct driver_info kalmia_info = {
330 .description = "Samsung Kalmia LTE USB dongle",
331 .flags = FLAG_WWAN,
332 .bind = kalmia_bind,
333 .rx_fixup = kalmia_rx_fixup,
334 .tx_fixup = kalmia_tx_fixup
335};
336
337/*-------------------------------------------------------------------------*/
338
339static const struct usb_device_id products[] = {
340 /* The unswitched USB ID, to get the module auto loaded: */
341 { USB_DEVICE(0x04e8, 0x689a) },
342 /* The stick switched into modem (by e.g. usb_modeswitch): */
343 { USB_DEVICE(0x04e8, 0x6889),
344 .driver_info = (unsigned long) &kalmia_info, },
345 { /* EMPTY == end of list */} };
346MODULE_DEVICE_TABLE( usb, products);
347
348static struct usb_driver kalmia_driver = {
349 .name = "kalmia",
350 .id_table = products,
351 .probe = usbnet_probe,
352 .disconnect = usbnet_disconnect,
353 .suspend = usbnet_suspend,
354 .resume = usbnet_resume,
355 .disable_hub_initiated_lpm = 1,
356};
357
358module_usb_driver(kalmia_driver);
359
360MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
361MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
362MODULE_LICENSE("GPL");