linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Grzegorz Kołodziejczyk" <grzegorz.kolodziejczyk@codecoup.pl>
To: Szymon Janc <szymon.janc@codecoup.pl>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ 6/8] tools/btpclient: Add pair, unpair commands
Date: Tue, 23 Jan 2018 16:08:14 +0100	[thread overview]
Message-ID: <CALevQMYpUpDS6VFp7j02_tDabbAAVSmoG=YGCUWmys3Bsd9u1g@mail.gmail.com> (raw)
In-Reply-To: <1641665.1XMgaMqVk0@ix>

Hi Szymon,

2018-01-23 14:53 GMT+01:00 Szymon Janc <szymon.janc@codecoup.pl>:
> Hi Grzegorz,
>
> On Friday, 19 January 2018 17:41:31 CET Grzegorz Kolodziejczyk wrote:
>> This patch adds pair and unpair commands for btp client.
>> ---
>>  tools/btpclient.c | 124
>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1=
24
>> insertions(+)
>>
>> diff --git a/tools/btpclient.c b/tools/btpclient.c
>> index 53c0d4c05..9d44fba41 100644
>> --- a/tools/btpclient.c
>> +++ b/tools/btpclient.c
>> @@ -304,6 +304,8 @@ static void btp_gap_read_commands(uint8_t index, con=
st
>> void *param, commands |=3D (1 << BTP_OP_GAP_CONNECT);
>>       commands |=3D (1 << BTP_OP_GAP_DISCONNECT);
>>       commands |=3D (1 << BTP_OP_GAP_SET_IO_CAPA);
>> +     commands |=3D (1 << BTP_OP_GAP_PAIR);
>> +     commands |=3D (1 << BTP_OP_GAP_UNPAIR);
>>
>>       commands =3D L_CPU_TO_LE16(commands);
>>
>> @@ -1875,6 +1877,122 @@ failed:
>>       btp_send_error(btp, BTP_GAP_SERVICE, index, status);
>>  }
>>
>> +static void pair_reply(struct l_dbus_proxy *proxy,
>> +                             struct l_dbus_message *result, void *user_=
data)
>> +{
>> +     uint8_t adapter_index =3D L_PTR_TO_UINT(user_data);
>> +     struct btp_adapter *adapter =3D find_adapter_by_index(adapter_inde=
x);
>> +
>> +     if (!adapter)
>> +             return;
>> +
>> +     if (l_dbus_message_is_error(result)) {
>> +             const char *name, *desc;
>> +
>> +             l_dbus_message_get_error(result, &name, &desc);
>> +             l_error("Failed to pair (%s), %s", name, desc);
>> +
>> +             return;
>> +     }
>> +}
>> +
>> +static void btp_gap_pair(uint8_t index, const void *param, uint16_t len=
gth,
>> +                                                             void *user=
_data)
>> +{
>> +     struct btp_adapter *adapter =3D find_adapter_by_index(index);
>> +     const struct btp_gap_pair_cp *cp =3D param;
>> +     uint8_t status =3D BTP_ERROR_FAIL;
>> +     struct btp_device *device;
>> +     bool prop;
>> +
>> +     if (!adapter) {
>> +             status =3D BTP_ERROR_INVALID_INDEX;
>> +             goto failed;
>> +     }
>> +
>> +     /* Adapter needs to be powered to be able to pair */
>> +     if (!l_dbus_proxy_get_property(adapter->proxy, "Powered", "b", &pr=
op) ||
>> +                                                                     !p=
rop)
>> +             goto failed;
>> +
>> +     device =3D find_device_by_address(adapter, &cp->address,
>> +                                                     cp->address_type);
>> +
>> +     if (!device)
>> +             goto failed;
>> +
>> +     btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_PAIR, adapter->index, 0,
>
> Please comment here that on BTP this command is suppose to initiate pairi=
ng
> only and successful pairing result is reported via event later on.
Ok
>
>> +                                                                     NU=
LL);
>> +
>> +     l_dbus_proxy_method_call(device->proxy, "Pair", NULL, pair_reply,
>> +                                     L_UINT_TO_PTR(adapter->index), NUL=
L);
>> +
>> +     return;
>> +
>> +failed:
>> +     btp_send_error(btp, BTP_GAP_SERVICE, index, status);
>> +}
>> +
>> +static void unpair_reply(struct l_dbus_proxy *proxy,
>> +                             struct l_dbus_message *result, void *user_=
data)
>> +{
>> +     uint8_t adapter_index =3D L_PTR_TO_UINT(user_data);
>> +     struct btp_adapter *adapter =3D find_adapter_by_index(adapter_inde=
x);
>> +
>> +     if (!adapter) {
>> +             btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROL=
LER,
>> +                                                             BTP_ERROR_=
FAIL);
>> +             return;
>> +     }
>> +
>> +     if (l_dbus_message_is_error(result)) {
>> +             const char *name, *desc;
>> +
>> +             l_dbus_message_get_error(result, &name, &desc);
>> +             l_error("Failed to unpair (%s), %s", name, desc);
>> +
>> +             btp_send_error(btp, BTP_GAP_SERVICE, adapter_index,
>> +                                                             BTP_ERROR_=
FAIL);
>> +             return;
>> +     }
>> +
>> +     btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_UNPAIR, adapter_index, 0=
, NULL);
>> +}
>> +
>> +static void btp_gap_unpair(uint8_t index, const void *param, uint16_t
>> length, +                                                             vo=
id *user_data)
>> +{
>> +     struct btp_adapter *adapter =3D find_adapter_by_index(index);
>> +     const struct btp_gap_pair_cp *cp =3D param;
>> +     uint8_t status =3D BTP_ERROR_FAIL;
>> +     struct btp_device *device;
>> +     bool prop;
>> +
>> +     if (!adapter) {
>> +             status =3D BTP_ERROR_INVALID_INDEX;
>> +             goto failed;
>> +     }
>> +
>> +     /* Adapter needs to be powered to be able to unpair */
>> +     if (!l_dbus_proxy_get_property(adapter->proxy, "Powered", "b", &pr=
op) ||
>> +                                                                     !p=
rop)
>> +             goto failed;
>> +
>> +     device =3D find_device_by_address(adapter, &cp->address,
>> +                                                     cp->address_type);
>> +
>> +     if (!device)
>> +             goto failed;
>> +
>> +     l_dbus_proxy_method_call(device->proxy, "Unpair", NULL, unpair_rep=
ly,
>> +                                     L_UINT_TO_PTR(adapter->index), NUL=
L);
>
> There is no "Unpair" command in Device1 interface :)  Use RemoveDevice fr=
om
> Adapter1.
Right, that was copy-paste mistake
>
>> +     return;
>> +
>> +failed:
>> +     btp_send_error(btp, BTP_GAP_SERVICE, index, status);
>> +}
>> +
>>  static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
>>  {
>>       struct btp_device_found_ev ev;
>> @@ -1999,6 +2117,12 @@ static void register_gap_service(void)
>>
>>       btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_SET_IO_CAPA,
>>                               btp_gap_set_io_capabilities, NULL, NULL);
>> +
>> +     btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_PAIR, btp_gap_pair, =
NULL,
>> +                                                                     NU=
LL);
>> +
>> +     btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_UNPAIR, btp_gap_unpa=
ir,
>> +                                                             NULL, NULL=
);
>>  }
>>
>>  static void btp_core_read_commands(uint8_t index, const void *param,
>
>
> --
> pozdrawiam
> Szymon Janc
>
>

pozdrawiam,
Grzegorz Ko=C5=82odziejczyk

  reply	other threads:[~2018-01-23 15:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19 16:41 [PATCH BlueZ 1/8] tools/btpclient: Fix start adv commend comment Grzegorz Kolodziejczyk
2018-01-19 16:41 ` [PATCH BlueZ 2/8] tools/btpclient: Initial check of ad_proxy presence in stop adv cmd Grzegorz Kolodziejczyk
2018-01-19 16:41 ` [PATCH BlueZ 3/8] tools/btpclient: Add set io capabilities command Grzegorz Kolodziejczyk
2018-01-23 13:48   ` Szymon Janc
2018-01-23 15:06     ` Grzegorz Kołodziejczyk
2018-01-19 16:41 ` [PATCH BlueZ 4/8] tools/btpclient: Restore default settings on reset Grzegorz Kolodziejczyk
2018-01-23 13:48   ` Szymon Janc
2018-01-19 16:41 ` [PATCH BlueZ 5/8] tools/btpclient: Cleanup advertising data " Grzegorz Kolodziejczyk
2018-01-19 16:41 ` [PATCH BlueZ 6/8] tools/btpclient: Add pair, unpair commands Grzegorz Kolodziejczyk
2018-01-23 13:53   ` Szymon Janc
2018-01-23 15:08     ` Grzegorz Kołodziejczyk [this message]
2018-01-19 16:41 ` [PATCH BlueZ 7/8] tools/btpclient: Add passkey entry cmd and passkey display event Grzegorz Kolodziejczyk
2018-01-19 16:41 ` [PATCH BlueZ 8/8] tools/btpclient: Add passkey confirm ev and passkey confirm rsp cmd Grzegorz Kolodziejczyk
2018-01-23 14:03   ` Szymon Janc
2018-01-23 15:09     ` Grzegorz Kołodziejczyk
2018-01-23 13:44 ` [PATCH BlueZ 1/8] tools/btpclient: Fix start adv commend comment Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALevQMYpUpDS6VFp7j02_tDabbAAVSmoG=YGCUWmys3Bsd9u1g@mail.gmail.com' \
    --to=grzegorz.kolodziejczyk@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@codecoup.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).