Bluetooth: btp: Add LPN Subscribe/Unsubscribe commands

This adds commands to manage Friend node Subscription List.
Those will be used to add or remove and group/virtual address
from subscription list.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2017-12-29 12:52:10 +01:00 committed by Johan Hedberg
parent 0bd3790d5b
commit a909aa3a0b
5 changed files with 119 additions and 0 deletions

View file

@ -65,6 +65,30 @@ void bt_test_cb_unregister(struct bt_test_cb *cb);
void bt_test_mesh_net_recv(u8_t ttl, u8_t ctl, u16_t src, u16_t dst,
const void *payload, size_t payload_len);
/** Send Friend Subscription List Add message.
*
* Used by Low Power node to send the group address for which messages are to
* be stored by Friend node.
*
* @param group Group address
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_test_mesh_lpn_group_add(u16_t group);
/** Send Friend Subscription List Remove message.
*
* Used by Low Power node to remove the group addresses from Friend node
* subscription list. Messages sent to those addresses will not be stored
* by Friend node.
*
* @param groups Group addresses
* @param groups_count Group addresses count
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count);
/**
* @}
*/

View file

@ -10,6 +10,9 @@
#include <bluetooth/mesh.h>
#include <bluetooth/testing.h>
#include "mesh/net.h"
#include "mesh/lpn.h"
#include "testing.h"
static sys_slist_t cb_slist;
@ -71,3 +74,17 @@ void bt_test_mesh_prov_invalid_bearer(u8_t opcode)
}
}
}
int bt_test_mesh_lpn_group_add(u16_t group)
{
bt_mesh_lpn_group_add(group);
return 0;
}
int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count)
{
bt_mesh_lpn_group_del(groups, groups_count);
return 0;
}

View file

@ -1518,6 +1518,24 @@ Commands and responses:
In case of an error, the error response will be returned.
Opcode 0x10 - Low Power Node Subscribe
Controller Index: <controller id>
Command parameters: Address (2 octets)
This command is used to send out a Friend Subscription List
Add message message.
In case of an error, the error response will be returned.
Opcode 0x11 - Low Power Node Unsubscribe
Controller Index: <controller id>
Command parameters: Address (2 octets)
This command is used to send out a Friend Subscription List
Remove message.
In case of an error, the error response will be returned.
Events:
Opcode 0x80 - Output number action Event

View file

@ -755,6 +755,16 @@ struct mesh_model_send_cmd {
u8_t payload[0];
} __packed;
#define MESH_LPN_SUBSCRIBE 0x10
struct mesh_lpn_subscribe_cmd {
u16_t address;
} __packed;
#define MESH_LPN_UNSUBSCRIBE 0x11
struct mesh_lpn_unsubscribe_cmd {
u16_t address;
} __packed;
/* events */
#define MESH_EV_OUT_NUMBER_ACTION 0x80
struct mesh_out_number_action_ev {

View file

@ -83,6 +83,12 @@ static void supported_commands(u8_t *data, u16_t len)
tester_set_bit(buf->data, MESH_LPN);
tester_set_bit(buf->data, MESH_LPN_POLL);
tester_set_bit(buf->data, MESH_MODEL_SEND);
/* 3rd octet */
memset(net_buf_simple_add(buf, 1), 0, 1);
#if defined(CONFIG_BT_TESTING)
tester_set_bit(buf->data, MESH_LPN_SUBSCRIBE);
tester_set_bit(buf->data, MESH_LPN_UNSUBSCRIBE);
#endif /* CONFIG_BT_TESTING */
tester_send(BTP_SERVICE_ID_MESH, MESH_READ_SUPPORTED_COMMANDS,
CONTROLLER_INDEX, buf->data, buf->len);
@ -650,6 +656,42 @@ fail:
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
#if defined(CONFIG_BT_TESTING)
static void lpn_subscribe(u8_t *data, u16_t len)
{
struct mesh_lpn_subscribe_cmd *cmd = (void *) data;
u16_t address = sys_le16_to_cpu(cmd->address);
int err;
SYS_LOG_DBG("address 0x%04x", address);
err = bt_test_mesh_lpn_group_add(address);
if (err) {
SYS_LOG_ERR("Failed to subscribe (err %d)", err);
}
tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN_SUBSCRIBE, CONTROLLER_INDEX,
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
static void lpn_unsubscribe(u8_t *data, u16_t len)
{
struct mesh_lpn_unsubscribe_cmd *cmd = (void *) data;
u16_t address = sys_le16_to_cpu(cmd->address);
int err;
SYS_LOG_DBG("address 0x%04x", address);
err = bt_test_mesh_lpn_group_remove(&address, 1);
if (err) {
SYS_LOG_ERR("Failed to unsubscribe (err %d)", err);
}
tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN_UNSUBSCRIBE, CONTROLLER_INDEX,
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
#endif /* CONFIG_BT_TESTING */
void tester_handle_mesh(u8_t opcode, u8_t index, u8_t *data, u16_t len)
{
switch (opcode) {
@ -698,6 +740,14 @@ void tester_handle_mesh(u8_t opcode, u8_t index, u8_t *data, u16_t len)
case MESH_MODEL_SEND:
model_send(data, len);
break;
#if defined(CONFIG_BT_TESTING)
case MESH_LPN_SUBSCRIBE:
lpn_subscribe(data, len);
break;
case MESH_LPN_UNSUBSCRIBE:
lpn_unsubscribe(data, len);
break;
#endif /* CONFIG_BT_TESTING */
default:
tester_rsp(BTP_SERVICE_ID_MESH, opcode, index,
BTP_STATUS_UNKNOWN_CMD);