mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-30 08:02:30 +00:00
staging: wilc1000: use helper API to pack data for firmware
As discussed in [1] use put_unaligned_le16() & put_unaligned_le32() helper to pack the data before sending to firmware. [1]. https://lore.kernel.org/linux-wireless/86bc79ccd379497d56bade79ec8f717603110ef7.camel@sipsolutions.net/ Signed-off-by: Ajay Singh <ajay.kathat@microchip.com> Link: https://lore.kernel.org/r/20190806103325.14063-1-ajay.kathat@microchip.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
36d042bd68
commit
b0d525a007
1 changed files with 18 additions and 56 deletions
|
@ -52,57 +52,35 @@ static const struct wilc_cfg_str g_cfg_str[] = {
|
|||
|
||||
static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
if ((offset + 4) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
buf[2] = 1;
|
||||
buf[3] = 0;
|
||||
buf[4] = val8;
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
put_unaligned_le16(1, &frame[offset + 2]);
|
||||
frame[offset + 4] = val8;
|
||||
return 5;
|
||||
}
|
||||
|
||||
static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
if ((offset + 5) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
buf[2] = 2;
|
||||
buf[3] = 0;
|
||||
buf[4] = (u8)val16;
|
||||
buf[5] = (u8)(val16 >> 8);
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
put_unaligned_le16(2, &frame[offset + 2]);
|
||||
put_unaligned_le16(val16, &frame[offset + 4]);
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
||||
static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
if ((offset + 7) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
buf[2] = 4;
|
||||
buf[3] = 0;
|
||||
buf[4] = (u8)val32;
|
||||
buf[5] = (u8)(val32 >> 8);
|
||||
buf[6] = (u8)(val32 >> 16);
|
||||
buf[7] = (u8)(val32 >> 24);
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
put_unaligned_le16(4, &frame[offset + 2]);
|
||||
put_unaligned_le32(val32, &frame[offset + 4]);
|
||||
|
||||
return 8;
|
||||
}
|
||||
|
@ -110,46 +88,35 @@ static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
|
|||
static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str,
|
||||
u32 size)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
if ((offset + size + 4) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
buf[2] = (u8)size;
|
||||
buf[3] = (u8)(size >> 8);
|
||||
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
put_unaligned_le16(size, &frame[offset + 2]);
|
||||
if (str && size != 0)
|
||||
memcpy(&buf[4], str, size);
|
||||
memcpy(&frame[offset + 4], str, size);
|
||||
|
||||
return (size + 4);
|
||||
}
|
||||
|
||||
static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
|
||||
{
|
||||
u8 *buf;
|
||||
u32 i;
|
||||
u8 checksum = 0;
|
||||
|
||||
if ((offset + size + 5) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
buf[2] = (u8)size;
|
||||
buf[3] = (u8)(size >> 8);
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
put_unaligned_le16(size, &frame[offset + 2]);
|
||||
|
||||
if ((b) && size != 0) {
|
||||
memcpy(&buf[4], b, size);
|
||||
memcpy(&frame[offset + 4], b, size);
|
||||
for (i = 0; i < size; i++)
|
||||
checksum += buf[i + 4];
|
||||
checksum += frame[offset + i + 4];
|
||||
}
|
||||
|
||||
buf[size + 4] = checksum;
|
||||
frame[offset + size + 4] = checksum;
|
||||
|
||||
return (size + 5);
|
||||
}
|
||||
|
@ -307,15 +274,10 @@ int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
|
|||
|
||||
int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
if ((offset + 2) >= WILC_MAX_CFG_FRAME_SIZE)
|
||||
return 0;
|
||||
|
||||
buf = &frame[offset];
|
||||
|
||||
buf[0] = (u8)id;
|
||||
buf[1] = (u8)(id >> 8);
|
||||
put_unaligned_le16(id, &frame[offset]);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue