Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for library based QR-Code generation - setup identifier #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions include/mgos_hap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ bool mgos_hap_setup_info_from_string(
const char* _Nonnull salt,
const char* _Nonnull verifier);

/*
* Load setup identifier from string.
*/
bool mgos_hap_setup_id_from_string(HAPSetupID* _Nonnull setupID, const char* setup_id);

#ifdef MGOS_HAP_SIMPLE_CONFIG
bool mgos_hap_config_valid(void);

#ifdef MGOS_HAVE_RPC_COMMON
// Simple case: only one primary accessory, constant.
void mgos_hap_add_rpc_service(
HAPAccessoryServerRef* _Nonnull server,
const HAPAccessory* _Nonnull accessory);
void mgos_hap_add_rpc_service(HAPAccessoryServerRef* _Nonnull server, const HAPAccessory* _Nonnull accessory);
// More complicated variant.
void mgos_hap_add_rpc_service_cb(
HAPAccessoryServerRef* _Nonnull server,
Expand Down
1 change: 1 addition & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ conds:
- ["hap", "o", {"title": "HAP settings"}]
- ["hap.salt", "s", "", {"title": "Device verifier salt"}]
- ["hap.verifier", "s", "", {"title": "Device verifier"}]
- ["hap.setupid", "s", "", {"title": "Device setup id (Four characters)"}]
cdefs:
MGOS_HAP_SIMPLE_CONFIG: 1

Expand Down
31 changes: 31 additions & 0 deletions src/PAL/HAPPlatformAccessorySetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

#include "mgos.h"
#include "mgos_hap.h"

#include "HAPPlatformAccessorySetup.h"
#include "HAPPlatformAccessorySetup+Init.h"

Expand All @@ -23,6 +26,34 @@ void HAPPlatformAccessorySetupCreate(
const HAPPlatformAccessorySetupOptions* options HAP_UNUSED) {
}

void HAPPlatformAccessorySetupLoadSetupInfo(HAPPlatformAccessorySetupRef accessorySetup, HAPSetupInfo* setupInfo) {
struct mgos_hap_load_setup_info_arg arg = {
.accessorySetup = accessorySetup,
.setupInfo = setupInfo,
};
mgos_event_trigger(MGOS_HAP_EV_LOAD_SETUP_INFO, &arg);
}

void HAPPlatformAccessorySetupLoadSetupCode(HAPPlatformAccessorySetupRef accessorySetup, HAPSetupCode* setupCode) {
struct mgos_hap_load_setup_code_arg arg = {
.accessorySetup = accessorySetup,
.setupCode = setupCode,
};
mgos_event_trigger(MGOS_HAP_EV_LOAD_SETUP_CODE, &arg);
}

void HAPPlatformAccessorySetupLoadSetupID(
HAPPlatformAccessorySetupRef accessorySetup,
bool* valid,
HAPSetupID* setupID) {
struct mgos_hap_load_setup_id_arg arg = {
.accessorySetup = accessorySetup,
.valid = valid,
.setupID = setupID,
};
mgos_event_trigger(MGOS_HAP_EV_LOAD_SETUP_ID, &arg);
}

HAPPlatformAccessorySetupCapabilities
HAPPlatformAccessorySetupGetCapabilities(HAPPlatformAccessorySetupRef accessorySetup) {
HAPPrecondition(accessorySetup);
Expand Down
71 changes: 71 additions & 0 deletions src/PAL/HAPPlatformAccessorySetupDisplay+Init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2015-2019 The HomeKit ADK Contributors
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.

#ifndef HAP_PLATFORM_ACCESSORY_SETUP_DISPLAY_INIT_H
#define HAP_PLATFORM_ACCESSORY_SETUP_DISPLAY_INIT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "HAPPlatform.h"

#if __has_feature(nullability)
#pragma clang assume_nonnull begin
#endif

#ifndef HAVE_DISPLAY
#define HAVE_DISPLAY 0
#endif

/**@file
* Accessory setup display.
*
* - The HAPLog APIs are used to display the setup payload and setup code.
* For a real display the implementation needs to be adjusted.
*
* **Example**

@code{.c}

// Allocate Accessory setup display.
static HAPPlatformAccessorySetupDisplay setupDisplay;

// Initialize Accessory setup display.
HAPPlatformAccessorySetupDisplayCreate(&setupDisplay);

@endcode
*/

/**
* Accessory setup display.
*/
struct HAPPlatformAccessorySetupDisplay {
// Opaque type. Do not access the instance fields directly.
/**@cond */
HAPSetupPayload setupPayload;
HAPSetupCode setupCode;
bool setupPayloadIsSet : 1;
bool setupCodeIsSet : 1;
/**@endcond */
};

/**
* Initializes Accessory setup display.
*
* @param[out] setupDisplay Accessory setup display.
*/
void HAPPlatformAccessorySetupDisplayCreate(HAPPlatformAccessorySetupDisplayRef setupDisplay);

#if __has_feature(nullability)
#pragma clang assume_nonnull end
#endif

#ifdef __cplusplus
}
#endif

#endif
54 changes: 54 additions & 0 deletions src/PAL/HAPPlatformAccessorySetupDisplay.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2015-2019 The HomeKit ADK Contributors
// Copyright (c) 2019 Deomid "rojer" Ryabkov
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>

#include "mgos.h"
#include "mgos_hap.h"

#include "HAPPlatform.h"
#include "HAPPlatformAccessorySetupDisplay+Init.h"

void HAPPlatformAccessorySetupDisplayCreate(HAPPlatformAccessorySetupDisplayRef setupDisplay) {
HAPPrecondition(HAVE_DISPLAY);
HAPPrecondition(setupDisplay);

HAPRawBufferZero(setupDisplay, sizeof *setupDisplay);
}

void HAPPlatformAccessorySetupDisplayUpdateSetupPayload(
HAPPlatformAccessorySetupDisplayRef setupDisplay,
const HAPSetupPayload* _Nullable setupPayload,
const HAPSetupCode* _Nullable setupCode) {

struct mgos_hap_display_update_setup_payload_arg arg = {
.setupDisplay = setupDisplay,
.setupPayload = setupPayload,
.setupCode = setupCode,
};

mgos_event_trigger(MGOS_HAP_EV_DISPLAY_UPDATE_SETUP_PAYLOAD, &arg);
}

void HAPPlatformAccessorySetupDisplayHandleStartPairing(HAPPlatformAccessorySetupDisplayRef setupDisplay) {
struct mgos_hap_display_start_pairing_arg arg = {
.setupDisplay = setupDisplay,
};
mgos_event_trigger(MGOS_HAP_EV_DISPLAY_START_PAIRING, &arg);
}

void HAPPlatformAccessorySetupDisplayHandleStopPairing(HAPPlatformAccessorySetupDisplayRef setupDisplay) {
struct mgos_hap_display_stop_pairing_arg arg = {
.setupDisplay = setupDisplay,
};
mgos_event_trigger(MGOS_HAP_EV_DISPLAY_STOP_PAIRING, &arg);
}
31 changes: 31 additions & 0 deletions src/PAL/HAPPlatformAccessorySetupNFC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2015-2019 The HomeKit ADK Contributors
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.

#include "mgos.h"
#include "mgos_hap.h"

#include "HAPPlatform.h"

#ifndef HAVE_NFC
#define HAVE_NFC 0
#endif

#if HAVE_NFC
#include <errno.h>
#include <unistd.h>
#endif

void HAPPlatformAccessorySetupNFCUpdateSetupPayload(
HAPPlatformAccessorySetupNFCRef setupNFC,
const HAPSetupPayload* setupPayload,
bool isPairable) {
struct mgos_hap_nfc_update_setup_payload_arg arg = {
.setupNFC = setupNFC,
.setupPayload = setupPayload,
.isPairable = isPairable,
};
mgos_event_trigger(MGOS_HAP_EV_NFC_UPDATE_SETUP_PAYLOAD, &arg);
}
3 changes: 2 additions & 1 deletion src/PAL/HAPPlatformTCPStreamManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ bool HAPPlatformTCPStreamManagerIsListenerOpen(HAPPlatformTCPStreamManagerRef tc
}

static struct mg_connection* HAPMGListenerGetNextPendingConnection(HAPPlatformTCPStreamManagerRef tm) {
if (tm->listener == NULL) return NULL; // Stopping.
if (tm->listener == NULL)
return NULL; // Stopping.
struct mg_mgr* mgr = tm->listener->mgr;
struct mg_connection* result = NULL;
for (struct mg_connection* nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
Expand Down
Loading