This has not been tested, as I haven't been able to test until compiling.
This is only a compile patch for 2.6.26.5.
---
This is patch 2 of 2. It changes 3 things:
- the URB callback mechanism changed
- the work queue API changed... it no longer takes a pointer to data,
so I had to put a pointer to the urb in the modem and
blackberry_data structures. This is almost surely the wrong
way to do it, since there is only a queue of 1.
- all sha1 crypto calls go through the new, untested API. :-)
Testing is next of course, after I study the module sources more closely,
but I wanted to get this to you so as not to hold you up.
- Chris
kernel/blackberry.h | 14 +++--
kernel/init.c | 174 ++++++++++++++++++---------------------------------
kernel/modem.c | 102 +++++++++++++++++-------------
3 files changed, 126 insertions(+), 164 deletions(-)
diff --git a/kernel/blackberry.h b/kernel/blackberry.h
index 49b0107..8808d99 100644
--- a/kernel/blackberry.h
+++ b/kernel/blackberry.h
@@ -14,6 +14,13 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+/*
+ Copyright 2008, Chris Frey, NetDirect (http://www.netdirect.ca/), GPL v2
+ 2008/11 - Now compiles on 2.6.26.5: Changes to URB callback mechanism and
+ work queue API. Also uses new sha1 API.
+*/
+
#ifndef _BLACKBERRY_H
#define _BLACKBERRY_H
@@ -62,6 +69,7 @@ struct modem {
int max_rx;
wait_queue_head_t open_wait;
int login_complete;
+ struct urb *latest_urb;
};
struct blackberry_device {
@@ -75,6 +83,7 @@ struct blackberry_device {
struct modem modem;
int read_ep;
int write_ep;
+ struct urb *latest_urb;
};
#define to_blackberry_device(d) container_of(d, struct blackberry_device, kref)
@@ -82,11 +91,6 @@ extern int debug;
extern int num_devices;
extern struct device_map *device_map;
extern struct workqueue_struct *work_queue;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
-extern struct hash_desc crypto_hash;
-#else
-extern struct crypto_tfm *crypto_tfm;
-#endif
void blackberry_put(struct blackberry_device *blackberry_device);
struct blackberry_device *blackberry_get(struct blackberry_device
*blackberry_device);
#endif
diff --git a/kernel/init.c b/kernel/init.c
index e5627ea..a151866 100644
--- a/kernel/init.c
+++ b/kernel/init.c
@@ -14,6 +14,13 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+/*
+ Copyright 2008, Chris Frey, NetDirect (http://www.netdirect.ca/), GPL v2
+ 2008/11 - Now compiles on 2.6.26.5: Changes to URB callback mechanism and
+ work queue API. Also uses new sha1 API.
+*/
+
#include "config.h"
#include <linux/version.h>
@@ -25,14 +32,13 @@
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/mm.h>
-#include <asm/scatterlist.h>
-#include <linux/scatterlist.h>
#include <asm/uaccess.h>
#include "blackberry.h"
#include "charge.h"
#include "util.h"
#include "modem.h"
+#include "crypto.h"
#ifndef SUCCESS
#define SUCCESS (0)
@@ -102,11 +108,6 @@ static struct tty_operations desktop_ops = {
};
struct workqueue_struct *work_queue = NULL;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
-struct hash_desc crypto_hash;
-#else
-struct crypto_tfm *crypto_tfm = NULL;
-#endif
static unsigned char serial_header[] = {0xd9, 0xae, 0xfb};
static unsigned char serial_footer[] = {0xbf, 0xea, 0x9d};
@@ -117,63 +118,28 @@ send_password(struct blackberry_device
*blackberry_device, int mem_flags)
int ret = 0;
u8 *response = NULL;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
- if (crypto_hash.tfm)
+ if (blackberry_sha1_avail())
{
- response = kmalloc(8 + crypto_hash_digestsize(crypto_hash.tfm),
mem_flags);
+ response = kmalloc(8 + blackberry_sha1_digestsize(), mem_flags);
}
if (response)
{
- struct scatterlist sg;
-
- sg_init_one(&sg,
- &device_map[blackberry_device->desktop.tty->index].password_hash[0],
- 4 + crypto_hash_digestsize(crypto_hash.tfm));
- crypto_hash_init(&crypto_hash);
- crypto_hash_update(&crypto_hash,
- &sg, 1);
- crypto_hash_final(&crypto_hash, &response[8]);
+
blackberry_sha1_sum(&device_map[blackberry_device->desktop.tty->index].password_hash[0],
+ 4 + blackberry_sha1_digestsize(),
+ &response[8]
+ );
response[0] = 0x0f;
response[1] = (blackberry_device->desktop.socket >> 0) & 0xff;
response[2] = (blackberry_device->desktop.socket >> 8) & 0xff;
response[3] = blackberry_device->desktop.attempts_remaining + 1;
response[4] = 0x00;
response[5] = 0x00;
- response[6] = crypto_hash_digestsize(crypto_hash.tfm);
+ response[6] = blackberry_sha1_digestsize();
response[7] = 0x00;
- blackberry_write(blackberry_device, 0, response, 8 +
crypto_hash_digestsize(crypto_hash.tfm), GFP_ATOMIC);
+ blackberry_write(blackberry_device, 0, response, 8 +
blackberry_sha1_digestsize(), GFP_ATOMIC);
kfree(response);
}
else
-#else
- if (crypto_tfm)
- {
- response = kmalloc(8 + crypto_tfm_alg_digestsize(crypto_tfm),
mem_flags);
- }
- if (response)
- {
- struct scatterlist sg;
-
- sg_init_one(&sg,
- &device_map[blackberry_device->desktop.tty->index].password_hash[0],
- 4 + crypto_tfm_alg_digestsize(crypto_tfm));
- crypto_digest_init(crypto_tfm);
- crypto_digest_update(crypto_tfm,
- &sg, 1);
- crypto_digest_final(crypto_tfm, &response[8]);
- response[0] = 0x0f;
- response[1] = (blackberry_device->desktop.socket >> 0) & 0xff;
- response[2] = (blackberry_device->desktop.socket >> 8) & 0xff;
- response[3] = blackberry_device->desktop.attempts_remaining + 1;
- response[4] = 0x00;
- response[5] = 0x00;
- response[6] = crypto_tfm_alg_digestsize(crypto_tfm);
- response[7] = 0x00;
- blackberry_write(blackberry_device, 0, response, 8 +
crypto_tfm_alg_digestsize(crypto_tfm), GFP_ATOMIC);
- kfree(response);
- }
- else
-#endif
{
ret = -ENOMEM;
}
@@ -245,41 +211,15 @@ process_buffer(struct blackberry_device
*blackberry_device)
blackberry_device->desktop.tty->index);
dump_hex("<-- desktop",
blackberry_device->desktop.buffer, blackberry_device->desktop.num_buffer);
*/
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
if
(device_map[blackberry_device->desktop.tty->index].password_hash)
{
- struct scatterlist sg;
-
- sg_init_one(&sg,
-
&blackberry_device->desktop.buffer[sizeof(serial_header) + 5],
-
strlen(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5]));
- crypto_hash_init(&crypto_hash);
- crypto_hash_update(&crypto_hash,
- &sg, 1);
- crypto_hash_final(&crypto_hash,
&device_map[blackberry_device->desktop.tty->index].password_hash[4]);
+//
blackberry_sha1_sum(&blackberry_device->desktop.buffer[sizeof(serial_header) +
5],
+//
strlen(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5]));
/* Don't leave the unhashed password laying
around */
memset(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5], 0,
strlen(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5]));
send_password(blackberry_device,
GFP_ATOMIC);
}
else
-#else
- if
(device_map[blackberry_device->desktop.tty->index].password_hash)
- {
- struct scatterlist sg;
-
- sg_init_one(&sg,
-
&blackberry_device->desktop.buffer[sizeof(serial_header) + 5],
-
strlen(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5]));
- crypto_digest_init(crypto_tfm);
- crypto_digest_update(crypto_tfm,
- &sg, 1);
- crypto_digest_final(crypto_tfm,
&device_map[blackberry_device->desktop.tty->index].password_hash[4]);
- /* Don't leave the unhashed password laying
around */
-
memset(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5], 0,
strlen(&blackberry_device->desktop.buffer[sizeof(serial_header) + 5]));
- send_password(blackberry_device,
GFP_ATOMIC);
- }
- else
-#endif
{
err("%s(%d) - %08x", __FUNCTION__, __LINE__,
blackberry_device ?
blackberry_device->pin : (u_int32_t)-1);
@@ -793,7 +733,11 @@ struct blackberry_device *blackberry_device = tty ?
tty->driver_data : NULL;
}
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+blackberry_write_callback(struct urb *urb)
+#else
blackberry_write_callback(struct urb *urb, struct pt_regs *regs)
+#endif
{
struct blackberry_device *blackberry_device = urb->context;
@@ -1282,21 +1226,12 @@ int ret = 0;
unsigned char cmd[] = {0x40, 0x00, 'P'};
int use_old;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
if
(device_map[blackberry_device->desktop.tty->index].password_hash == NULL)
{
-
device_map[blackberry_device->desktop.tty->index].password_hash = kmalloc(4 +
crypto_hash_digestsize(&crypto_hash.tfm), GFP_KERNEL);
+
device_map[blackberry_device->desktop.tty->index].password_hash = kmalloc(4 +
blackberry_sha1_digestsize(), GFP_KERNEL);
use_old = 0;
}
else
-#else
- if
(device_map[blackberry_device->desktop.tty->index].password_hash == NULL)
- {
-
device_map[blackberry_device->desktop.tty->index].password_hash = kmalloc(4 +
crypto_tfm_alg_digestsize(crypto_tfm), GFP_KERNEL);
- use_old = 0;
- }
- else
-#endif
{
use_old = 1;
}
@@ -1525,11 +1460,20 @@ int ret = 0;
}
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+blackberry_read_work(struct work_struct *work)
+#else
blackberry_read_work(void *data)
+#endif
{
int ret = 0;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+struct blackberry_device *blackberry_device = container_of(work, struct
blackberry_device, read_work);
+struct urb *urb = blackberry_device->latest_urb;
+#else
struct urb *urb = data;
struct blackberry_device *blackberry_device = urb->context;
+#endif
if (debug >= 9)
{
@@ -1582,11 +1526,18 @@ struct blackberry_device *blackberry_device =
urb->context;
urb->transfer_buffer_length, urb->transfer_buffer,
urb->transfer_dma);
usb_free_urb(urb);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ blackberry_device->latest_urb = NULL;
+#endif
blackberry_put(blackberry_device);
}
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+blackberry_read_callback(struct urb *urb)
+#else
blackberry_read_callback(struct urb *urb, struct pt_regs *pt_regs)
+#endif
{
int ret = 0;
struct blackberry_device *blackberry_device = urb->context;
@@ -1599,9 +1550,19 @@ struct blackberry_device *blackberry_device =
urb->context;
if (urb->status == 0)
{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ if( blackberry_device->latest_urb == NULL )
+ {
+ usb_get_urb(urb);
+ blackberry_device->latest_urb = urb;
+ PREPARE_WORK(&blackberry_device->read_work, blackberry_read_work);
+ ret = queue_work(work_queue, &blackberry_device->read_work);
+ }
+#else
usb_get_urb(urb);
PREPARE_WORK(&blackberry_device->read_work, blackberry_read_work, urb);
ret = queue_work(work_queue, &blackberry_device->read_work);
+#endif
}
else
{
@@ -1881,22 +1842,12 @@ int i;
}
if (ret == 0)
{
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
- crypto_hash.tfm = crypto_alloc_hash("sha1", 0, 0);
- crypto_hash.flags = 0;
- if (crypto_hash.tfm)
- {
- info("%s(%d) - passwords are possible", __FUNCTION__, __LINE__);
- }
- else
-#else
- crypto_tfm = crypto_alloc_tfm("sha1", 0);
- if (crypto_tfm)
- {
+ blackberry_sha1_init();
+ if( blackberry_sha1_avail() )
+ {
info("%s(%d) - passwords are possible", __FUNCTION__, __LINE__);
- }
- else
-#endif
+ }
+ else
{
err("%s(%d) - passwords not supported", __FUNCTION__, __LINE__);
}
@@ -1912,17 +1863,8 @@ blackberry_exit(void)
info("%s(%d) - num_devices = %i", __FUNCTION__, __LINE__, num_devices);
}
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
- if (crypto_hash.tfm)
- {
- crypto_free_hash(crypto_hash.tfm);
- }
-#else
- if (crypto_tfm)
- {
- crypto_free_tfm(crypto_tfm);
- }
-#endif
+ blackberry_sha1_dnit();
+
blackberry_deregister(&blackberry_driver);
if (work_queue)
{
@@ -1990,7 +1932,11 @@ struct usb_device *udev = interface_to_usbdev(intf);
blackberry_device->max_packet = 32;
blackberry_device->read_ep =
intf->cur_altsetting->endpoint[2].desc.bEndpointAddress;
blackberry_device->write_ep =
intf->cur_altsetting->endpoint[3].desc.bEndpointAddress;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ INIT_WORK(&blackberry_device->read_work,
blackberry_read_work);
+#else
INIT_WORK(&blackberry_device->read_work,
blackberry_read_work, NULL);
+#endif
init_waitqueue_head(&blackberry_device->desktop.open_wait);
init_MUTEX(&blackberry_device->desktop.sem);
diff --git a/kernel/modem.c b/kernel/modem.c
index 4441bd4..cb51079 100644
--- a/kernel/modem.c
+++ b/kernel/modem.c
@@ -14,18 +14,24 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+/*
+ Copyright 2008, Chris Frey, NetDirect (http://www.netdirect.ca/), GPL v2
+ 2008/11 - Now compiles on 2.6.26.5: Changes to URB callback mechanism and
+ work queue API. Also uses new sha1 API.
+*/
+
#include <linux/version.h>
#include <linux/usb.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/mm.h>
-#include <asm/scatterlist.h>
-#include <linux/scatterlist.h>
#include <asm/uaccess.h>
#include "modem.h"
#include "util.h"
+#include "crypto.h"
static struct tty_driver *modem_driver = NULL;
static char special_tag[] = {0x78, 0x56, 0x34, 0x12};
@@ -73,7 +79,11 @@ static struct tty_operations modem_ops = {
};
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+modem_write_callback(struct urb *urb)
+#else
modem_write_callback(struct urb *urb, struct pt_regs *regs)
+#endif
{
struct blackberry_device *blackberry_device = urb->context;
@@ -208,10 +218,19 @@ unsigned char *rx_data = input;
}
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+modem_read_work(struct work_struct *work)
+#else
modem_read_work(void *data)
+#endif
{
int ret = 0;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+struct modem *modem = container_of(work, struct modem, read_work);
+struct urb *urb = modem->latest_urb;
+#else
struct urb *urb = data;
+#endif
struct blackberry_device *blackberry_device = urb->context;
unsigned char *rx_data;
@@ -280,65 +299,37 @@ unsigned char *rx_data;
*/
if (device_map[blackberry_device->modem.tty->index].password_hash)
{
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
- u8 *response = NULL;
+ u8 *response = NULL, *response_final = NULL;
- if (crypto_hash.tfm)
+ if (blackberry_sha1_avail())
{
- response = kmalloc(4 +
crypto_hash_digestsize(&crypto_hash.tfm) + sizeof(special_tag), GFP_KERNEL);
+ response = kmalloc(4 + blackberry_sha1_digestsize() +
sizeof(special_tag), GFP_KERNEL);
+ response_final = kmalloc(4 + blackberry_sha1_digestsize(),
GFP_KERNEL);
}
- if (response)
+ if (response && response_final)
{
u8 *data = urb->transfer_buffer;
u8 hdr[] = {0x03, 0x00, 0x00, 0x00};
- struct scatterlist sg;
memcpy(&device_map[blackberry_device->modem.tty->index].password_hash[0],
&data[4], 4);
- sg_init_one(&sg,
-
&device_map[blackberry_device->modem.tty->index].password_hash[0],
- 4 + crypto_hash_digestsize(&crypto_hash.tfm));
- crypto_hash_init(&crypto_hash);
- crypto_hash_update(&crypto_hash,
- &sg, 1);
- memcpy(&response[0], hdr, sizeof(hdr));
- crypto_hash_final(&crypto_hash, &response[sizeof(hdr)]);
- memcpy(&response[sizeof(hdr) +
crypto_hash_digestsize(&crypto_hash.tfm)], special_tag, sizeof(special_tag));
- blackberry_write(blackberry_device, 0,
- response,
- 4 + crypto_hash_digestsize(&crypto_hash.tfm) +
sizeof(special_tag),
- GFP_KERNEL);
- }
- else
-#else
- u8 *response = NULL;
- if (crypto_tfm)
- {
- response = kmalloc(4 +
crypto_tfm_alg_digestsize(crypto_tfm) + sizeof(special_tag), GFP_KERNEL);
- }
- if (response)
- {
- u8 *data = urb->transfer_buffer;
- u8 hdr[] = {0x03, 0x00, 0x00, 0x00};
- struct scatterlist sg;
-
-
memcpy(&device_map[blackberry_device->modem.tty->index].password_hash[0],
&data[4], 4);
- sg_init_one(&sg,
+ blackberry_sha1_sum(
&device_map[blackberry_device->modem.tty->index].password_hash[0],
- 4 + crypto_tfm_alg_digestsize(crypto_tfm));
- crypto_digest_init(crypto_tfm);
- crypto_digest_update(crypto_tfm,
- &sg, 1);
+ 4, &response[4]);
+
memcpy(&response[0], hdr, sizeof(hdr));
- crypto_digest_final(crypto_tfm, &response[sizeof(hdr)]);
- memcpy(&response[sizeof(hdr) +
crypto_tfm_alg_digestsize(crypto_tfm)], special_tag, sizeof(special_tag));
+ blackberry_sha1_sum(response, 4 +
blackberry_sha1_digestsize(),
+ &response[0]);
+ memcpy(&response[sizeof(hdr) +
blackberry_sha1_digestsize()], special_tag, sizeof(special_tag));
blackberry_write(blackberry_device, 0,
response,
- 4 + crypto_tfm_alg_digestsize(crypto_tfm) +
sizeof(special_tag),
+ 4 + blackberry_sha1_digestsize() + sizeof(special_tag),
GFP_KERNEL);
+
+ kfree(response);
+ kfree(response_final);
}
else
-#endif
{
char *err_msg = "ERROR\r\n";
@@ -374,11 +365,18 @@ unsigned char *rx_data;
urb->transfer_buffer_length, urb->transfer_buffer,
urb->transfer_dma);
usb_free_urb(urb);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ modem->latest_urb = NULL;
+#endif
blackberry_put(blackberry_device);
}
static void
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+modem_read_callback(struct urb *urb)
+#else
modem_read_callback(struct urb *urb, struct pt_regs *pt_regs)
+#endif
{
int ret = 0;
struct blackberry_device *blackberry_device = urb->context;
@@ -396,9 +394,19 @@ struct blackberry_device *blackberry_device = urb->context;
if (urb->status == 0 ||
urb->status == -EOVERFLOW)
{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ if( blackberry_device->modem.latest_urb == NULL )
+ {
+ usb_get_urb(urb);
+ blackberry_device->modem.latest_urb = urb;
+ PREPARE_WORK(&blackberry_device->modem.read_work, modem_read_work);
+ ret = queue_work(work_queue, &blackberry_device->modem.read_work);
+ }
+#else
usb_get_urb(urb);
PREPARE_WORK(&blackberry_device->modem.read_work, modem_read_work, urb);
ret = queue_work(work_queue, &blackberry_device->modem.read_work);
+#endif
}
else
{
@@ -750,7 +758,11 @@ int ret = 0;
blackberry_device->modem.rx_special_urbs = 0;
blackberry_device->modem.read_ep =
blackberry_device->interface->cur_altsetting->endpoint[4].desc.bEndpointAddress;
blackberry_device->modem.write_ep =
blackberry_device->interface->cur_altsetting->endpoint[5].desc.bEndpointAddress;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+ INIT_WORK(&blackberry_device->modem.read_work, modem_read_work);
+#else
INIT_WORK(&blackberry_device->modem.read_work, modem_read_work, NULL);
+#endif
init_MUTEX(&blackberry_device->modem.sem);
blackberry_device->modem.login_complete = 0;
init_waitqueue_head(&blackberry_device->modem.open_wait);
--
1.6.0.3
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Barry-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/barry-devel