Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
/src/samples/bluetooth/browse.c
/*
* This file is part of the Soletta (TM) Project
*
* Copyright (C) 2016 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "soletta.h"
#include "sol-log.h"
#include "sol-mainloop.h"
#include "sol-bluetooth.h"
#include "sol-gatt.h"
static struct sol_bt_scan_pending *scan;
static struct sol_bt_session *session;
static struct sol_bt_conn *browse_conn;
static struct sol_timeout *timeout;
static void
on_error(void *user_data, int error)
{
SOL_DBG("error %d", error);
browse_conn = NULL;
}
static bool
notify_callback(void *user_data,
const struct sol_gatt_attr *attr, const struct sol_buffer *buffer)
{
SOL_INF("attr %p update %zu bytes", attr, buffer->used);
return true;
}
static bool
print_attr(void *user_data, struct sol_bt_conn *conn,
const struct sol_gatt_attr *attr)
{
int r;
if (!conn || !attr) {
return false;
}
r = sol_bt_uuid_to_str(&attr->uuid, &buf);
SOL_INT_CHECK_GOTO(r, < 0, done);
SOL_INF("type %d uuid %.*s flags %#x", attr->type, (int)buf.used,
(char *)buf.data, attr->flags);
goto done;
goto done;
r = sol_gatt_subscribe(conn, attr, notify_callback, NULL);
SOL_INT_CHECK_GOTO(r, < 0, done);
done:
if (r)
return false;
return true;
}
static bool
on_connect(void *user_data, struct sol_bt_conn *conn)
{
int r;
SOL_INF("Connected to device %.*s", (int)str.used, (char *)str.data);
r = sol_gatt_discover(conn, 0, NULL, NULL, print_attr, NULL);
SOL_INT_CHECK(r, < 0, false);
return true;
}
static void
on_disconnect(void *user_data, struct sol_bt_conn *conn)
{
SOL_INF("Disconnected from device %.*s", (int)str.used, (char *)str.data);
browse_conn = NULL;
}
static bool
{
on_error, NULL);
return false;
}
static void
found_device(void *user_data, const struct sol_bt_device_info *device)
{
const char *addr;
addr = sol_network_link_addr_to_str(&device->addr, &str);
SOL_INF("device %.*s in range %s", (int)str.used, (char *)str.data,
device->in_range ? "yes" : "no");
if (!device->in_range)
return;
return;
scan = NULL;
}
}
static void
enabled(void *data, bool powered)
{
if (!powered)
return;
SOL_INF("Bluetooth Adapter enabled");
}
static void
shutdown(void)
{
if (scan)
if (session)
}
static void
startup(void)
{
if (sol_argc() > 1) {
const struct sol_network_link_addr *addr;
}
if (!session) {
SOL_WRN("Couldn't create a Bluetooth session");
}
}