31 #include <linux/types.h>
32 #include <linux/module.h>
34 #include <asm/unaligned.h>
35 #include <asm/byteorder.h>
40 static int irda_extract_integer(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
42 static int irda_extract_string(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
44 static int irda_extract_octseq(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
46 static int irda_extract_no_value(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
49 static int irda_insert_integer(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
51 static int irda_insert_no_value(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
54 static int irda_param_unpack(
__u8 *
buf,
char *
fmt, ...);
80 static int irda_insert_no_value(
void *
self,
__u8 *
buf,
int len,
__u8 pi,
90 ret = (*func)(
self, &
p,
PV_GET);
107 static int irda_extract_no_value(
void *
self,
__u8 *buf,
int len,
__u8 pi,
114 irda_param_unpack(buf,
"bb", &p.
pi, &p.
pl);
117 ret = (*func)(
self, &
p,
PV_PUT);
128 static int irda_insert_integer(
void *
self,
__u8 *buf,
int len,
__u8 pi,
140 err = (*func)(
self, &
p,
PV_GET);
151 IRDA_DEBUG(2,
"%s(), using 1 byte\n", __func__);
153 }
else if (p.pv.i < 0xffff) {
154 IRDA_DEBUG(2,
"%s(), using 2 bytes\n", __func__);
157 IRDA_DEBUG(2,
"%s(), using 4 bytes\n", __func__);
162 if (len < (2+p.pl)) {
167 IRDA_DEBUG(2,
"%s(), pi=%#x, pl=%d, pi=%d\n", __func__,
181 if (type & PV_BIG_ENDIAN)
204 static int irda_extract_integer(
void *
self,
__u8 *buf,
int len,
__u8 pi,
218 if (len < (2+p.
pl)) {
220 "Need %d bytes, but len is only %d\n",
221 __func__, p.
pl, len);
230 if (((type & PV_MASK) !=
PV_INTEGER) && ((type & PV_MASK) != p.
pl)) {
232 "Expected %d bytes, but value had %d bytes!\n",
233 __func__, type & PV_MASK, p.
pl);
241 if((p.
pl < (type & PV_MASK)) || (type & PV_BIG_ENDIAN)) {
251 switch (extract_len) {
253 n += irda_param_unpack(buf+2,
"b", &p.
pv.
i);
256 n += irda_param_unpack(buf+2,
"s", &p.
pv.
i);
257 if (type & PV_BIG_ENDIAN)
263 n += irda_param_unpack(buf+2,
"i", &p.
pv.
i);
264 if (type & PV_BIG_ENDIAN)
277 IRDA_DEBUG(2,
"%s(), pi=%#x, pl=%d, pi=%d\n", __func__,
280 err = (*func)(
self, &
p,
PV_PUT);
290 static int irda_extract_string(
void *
self,
__u8 *buf,
int len,
__u8 pi,
304 IRDA_DEBUG(2,
"%s(), pi=%#x, pl=%d\n", __func__,
308 if (len < (2+p.
pl)) {
310 "Need %d bytes, but len is only %d\n",
311 __func__, p.
pl, len);
319 IRDA_DEBUG(2,
"%s(), str=0x%02x 0x%02x\n", __func__,
328 err = (*func)(
self, &
p,
PV_PUT);
338 static int irda_extract_octseq(
void *
self,
__u8 *buf,
int len,
__u8 pi,
347 if (len < (2+p.
pl)) {
349 "Need %d bytes, but len is only %d\n",
350 __func__, p.
pl, len);
376 for (p = fmt; *p !=
'\0'; p++) {
410 static int irda_param_unpack(
__u8 *buf,
char *
fmt, ...)
419 for (p = fmt; *p !=
'\0'; p++) {
474 if ((pi_major > info->
len-1) ||
475 (pi_minor > info->
tables[pi_major].
len-1))
477 IRDA_DEBUG(0,
"%s(), no handler for parameter=0x%02x\n",
488 type = pi_minor_info->
type;
491 if (!pi_minor_info->
func) {
492 IRDA_MESSAGE(
"%s: no handler for pi=%#x\n", __func__, pi);
498 ret = (*pv_insert_table[type &
PV_MASK])(
self, buf+n, len, pi, type,
499 pi_minor_info->
func);
511 static int irda_param_extract(
void *
self,
__u8 *buf,
int len,
528 if ((pi_major > info->
len-1) ||
529 (pi_minor > info->
tables[pi_major].
len-1))
531 IRDA_DEBUG(0,
"%s(), no handler for parameter=0x%02x\n",
535 return 2 + buf[n + 1];
542 type = pi_minor_info->
type;
544 IRDA_DEBUG(3,
"%s(), pi=[%d,%d], type=%d\n", __func__,
545 pi_major, pi_minor, type);
548 if (!pi_minor_info->
func) {
552 return 2 + buf[n + 1];
556 ret = (*pv_extract_table[type &
PV_MASK])(
self, buf+n, len, buf[n],
557 type, pi_minor_info->
func);
582 ret = irda_param_extract(
self, buf+n, len, info);