linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] android/hidhost: Fix hex string to buffer convertion
       [not found] ` <3B53A9C2-0FA3-4C0C-BC44-9DF2798BFDF8@holtmann.org>
@ 2014-04-10  9:57   ` Luiz Augusto von Dentz
  2014-04-10 10:32     ` Szymon Janc
  0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2014-04-10  9:57 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Szymon Janc, linux-bluetooth@vger.kernel.org

Hi,

On Wed, Apr 9, 2014 at 11:49 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Szymon,
>
>> Due to missing limit specifier buffer was always filled with last hex
>> value in string.
>> ---
>> android/hidhost.c | 23 ++++++++++++++---------
>> 1 file changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/android/hidhost.c b/android/hidhost.c
>> index 5ea7c5a..124d710 100644
>> --- a/android/hidhost.c
>> +++ b/android/hidhost.c
>> @@ -162,10 +162,18 @@ static void hid_device_remove(struct hid_device *dev)
>>       hid_device_free(dev);
>> }
>>
>> +static void hex2buf(const uint8_t *hex, uint8_t *buf, int num)
>> +{
>> +     int i;
>> +
>> +     for (i = 0; i < num; i++)
>> +             sscanf((const char *)(hex + (i * 2)), "%02hhX", &buf[i]);
>> +}
>
> can we please build a cheaper version of this that does not require to use sscanf. Small hint is to look into src/util.c from oFono.

I also wonder why we are doing this? All the HAL does is to
memcpy(cmd->data, data, cmd->len) or is it because the string itself
is hexadecimal encoded? If that is the case someone probably deserves
a medal...


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] android/hidhost: Fix hex string to buffer convertion
  2014-04-10  9:57   ` [PATCH] android/hidhost: Fix hex string to buffer convertion Luiz Augusto von Dentz
@ 2014-04-10 10:32     ` Szymon Janc
  2014-04-10 10:52       ` Ravi kumar Veeramally
  0 siblings, 1 reply; 3+ messages in thread
From: Szymon Janc @ 2014-04-10 10:32 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: Marcel Holtmann, linux-bluetooth@vger.kernel.org,
	Ravi Kumar Veeramally

Hi Luiz,

On Thursday 10 of April 2014 12:57:00 Luiz Augusto von Dentz wrote:
> Hi,
> 
> On Wed, Apr 9, 2014 at 11:49 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Szymon,
> >
> >> Due to missing limit specifier buffer was always filled with last hex
> >> value in string.
> >> ---
> >> android/hidhost.c | 23 ++++++++++++++---------
> >> 1 file changed, 14 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/android/hidhost.c b/android/hidhost.c
> >> index 5ea7c5a..124d710 100644
> >> --- a/android/hidhost.c
> >> +++ b/android/hidhost.c
> >> @@ -162,10 +162,18 @@ static void hid_device_remove(struct hid_device *dev)
> >>       hid_device_free(dev);
> >> }
> >>
> >> +static void hex2buf(const uint8_t *hex, uint8_t *buf, int num)
> >> +{
> >> +     int i;
> >> +
> >> +     for (i = 0; i < num; i++)
> >> +             sscanf((const char *)(hex + (i * 2)), "%02hhX", &buf[i]);
> >> +}
> >
> > can we please build a cheaper version of this that does not require to use sscanf. Small hint is to look into src/util.c from oFono.
> 
> I also wonder why we are doing this? All the HAL does is to
> memcpy(cmd->data, data, cmd->len) or is it because the string itself
> is hexadecimal encoded? If that is the case someone probably deserves
> a medal...

Yeap, Java is passing string to send_data() and set_report() calls (those have no
size parameter).

In JNI you can see:
 const char *c_report = env->GetStringUTFChars(report, NULL);
    if ( (status = sBluetoothHidInterface->send_data((bt_bdaddr_t *) addr, (char*) c_report)) !=
             BT_STATUS_SUCCESS) {

Those are test commands so not that important. But I wonder why this is done
also in handle_uhid_output()...   Ravi, could you comment on that?

-- 
Best regards, 
Szymon Janc

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] android/hidhost: Fix hex string to buffer convertion
  2014-04-10 10:32     ` Szymon Janc
@ 2014-04-10 10:52       ` Ravi kumar Veeramally
  0 siblings, 0 replies; 3+ messages in thread
From: Ravi kumar Veeramally @ 2014-04-10 10:52 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org

Hi Szymon,

On 04/10/2014 01:32 PM, Szymon Janc wrote:
> Hi Luiz,
>
> On Thursday 10 of April 2014 12:57:00 Luiz Augusto von Dentz wrote:
>> Hi,
>>
>> On Wed, Apr 9, 2014 at 11:49 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
>>> Hi Szymon,
>>>
>>>> Due to missing limit specifier buffer was always filled with last hex
>>>> value in string.
>>>> ---
>>>> android/hidhost.c | 23 ++++++++++++++---------
>>>> 1 file changed, 14 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/android/hidhost.c b/android/hidhost.c
>>>> index 5ea7c5a..124d710 100644
>>>> --- a/android/hidhost.c
>>>> +++ b/android/hidhost.c
>>>> @@ -162,10 +162,18 @@ static void hid_device_remove(struct hid_device *dev)
>>>>        hid_device_free(dev);
>>>> }
>>>>
>>>> +static void hex2buf(const uint8_t *hex, uint8_t *buf, int num)
>>>> +{
>>>> +     int i;
>>>> +
>>>> +     for (i = 0; i < num; i++)
>>>> +             sscanf((const char *)(hex + (i * 2)), "%02hhX", &buf[i]);
>>>> +}
>>> can we please build a cheaper version of this that does not require to use sscanf. Small hint is to look into src/util.c from oFono.
>> I also wonder why we are doing this? All the HAL does is to
>> memcpy(cmd->data, data, cmd->len) or is it because the string itself
>> is hexadecimal encoded? If that is the case someone probably deserves
>> a medal...
> Yeap, Java is passing string to send_data() and set_report() calls (those have no
> size parameter).
>
> In JNI you can see:
>   const char *c_report = env->GetStringUTFChars(report, NULL);
>      if ( (status = sBluetoothHidInterface->send_data((bt_bdaddr_t *) addr, (char*) c_report)) !=
>               BT_STATUS_SUCCESS) {
>
> Those are test commands so not that important. But I wonder why this is done
> also in handle_uhid_output()...   Ravi, could you comment on that?
   Could not recall exactly, probably done similar to set_report due to
   req[0] = HID_MSG_SET_REPORT | output->rtype;

Regards,
Ravi.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-10 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1396959747-19848-1-git-send-email-szymon.janc@tieto.com>
     [not found] ` <3B53A9C2-0FA3-4C0C-BC44-9DF2798BFDF8@holtmann.org>
2014-04-10  9:57   ` [PATCH] android/hidhost: Fix hex string to buffer convertion Luiz Augusto von Dentz
2014-04-10 10:32     ` Szymon Janc
2014-04-10 10:52       ` Ravi kumar Veeramally

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).