Skip to content

Commit

Permalink
lib_nbgl: nbgl_sync_use_case: First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Apr 10, 2024
1 parent 90d0dce commit dfd3050
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib_nbgl/include/nbgl_sync_use_case.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "nbgl_use_case.h"

typedef enum {
NBGL_SYNC_RET_APPROVED,
NBGL_SYNC_RET_REJECTED,
NBGL_SYNC_RET_QUITTED,
NBGL_SYNC_RET_APDU_RECEIVED,
NBGL_SYNC_RET_ERROR
} nbgl_sync_ret_t;

nbgl_sync_ret_t nbgl_sync_useCaseHomeAndSettings(const char *appName,
const nbgl_icon_details_t *appIcon,
const char *tagline,
const uint8_t initSettingPage,
const nbgl_genericContents_t *settingContents,
const nbgl_contentInfoList_t *infosList,
const nbgl_homeAction_t *action);

nbgl_sync_ret_t nbgl_sync_useCaseReview(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const char *finishTitle);

nbgl_sync_ret_t nbgl_sync_useCaseAddressReview(
const char *address,
const nbgl_layoutTagValueList_t *additionalTagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle);

nbgl_sync_ret_t nbgl_sync_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType);

nbgl_sync_ret_t nbgl_sync_useCaseStatus(const char *message, bool isSuccess);

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingStart(nbgl_operationType_t operationType,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle);

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingContinue(
const nbgl_layoutTagValueList_t *tagValueList);

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingFinish(const char *finishTitle);

nbgl_sync_ret_t nbgl_sync_useCaseGenericReview(const nbgl_genericContents_t *contents,
const char *rejectText);

nbgl_sync_ret_t nbgl_sync_useCaseGenericConfiguration(const char *title,
uint8_t initPage,
const nbgl_genericContents_t *contents);

/*
* This function must be implemented by the caller.
* It must wait for the next seph event and process it except for APDU events.
* It must return:
* - true when an APDU has been received in the processed event
* - false otherwise
*
* Note on C apps using SDK lib_standard_app, this is already provided in io.c by the lib.
*/
extern bool io_recv_and_process_event(void);
161 changes: 161 additions & 0 deletions lib_nbgl/src/nbgl_sync_use_case.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include "nbgl_sync_use_case.h"

static nbgl_sync_ret_t g_ret;
static bool g_ended;

static void choice_callback(bool confirm)
{
if (confirm) {
g_ret = NBGL_SYNC_RET_APPROVED;
}
else {
g_ret = NBGL_SYNC_RET_REJECTED;
}

g_ended = true;
}

static void quit_callback(void)
{
g_ret = NBGL_SYNC_RET_QUITTED;
g_ended = true;
}

static void rejected_callback(void)
{
g_ret = NBGL_SYNC_RET_REJECTED;
g_ended = true;
}

static void nbgl_sync_init(void)
{
g_ended = false;
g_ret = NBGL_SYNC_RET_ERROR;
}

static nbgl_sync_ret_t nbgl_sync_wait(bool exitOnApdu)
{
bool apduReceived;

while (!g_ended) {
apduReceived = io_recv_and_process_event();
if (exitOnApdu && apduReceived) {
return NBGL_SYNC_RET_APDU_RECEIVED;
}
}

return g_ret;
}

nbgl_sync_ret_t nbgl_sync_useCaseHomeAndSettings(const char *appName,
const nbgl_icon_details_t *appIcon,
const char *tagline,
const uint8_t initSettingPage,
const nbgl_genericContents_t *settingContents,
const nbgl_contentInfoList_t *infosList,
const nbgl_homeAction_t *action)
{
nbgl_sync_init();
nbgl_useCaseHomeAndSettings(appName,
appIcon,
tagline,
initSettingPage,
settingContents,
infosList,
action,
quit_callback);
return nbgl_sync_wait(true);
}

nbgl_sync_ret_t nbgl_sync_useCaseReview(nbgl_operationType_t operationType,
const nbgl_layoutTagValueList_t *tagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle,
const char *finishTitle)
{
nbgl_sync_init();
nbgl_useCaseReview(operationType,
tagValueList,
icon,
reviewTitle,
reviewSubTitle,
finishTitle,
choice_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseAddressReview(
const char *address,
const nbgl_layoutTagValueList_t *additionalTagValueList,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle)
{
nbgl_sync_init();
nbgl_useCaseAddressReview(
address, additionalTagValueList, icon, reviewTitle, reviewSubTitle, choice_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType)
{
nbgl_sync_init();
nbgl_useCaseReviewStatus(reviewStatusType, quit_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseStatus(const char *message, bool isSuccess)
{
nbgl_sync_init();
nbgl_useCaseStatus(message, isSuccess, quit_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingStart(nbgl_operationType_t operationType,
const nbgl_icon_details_t *icon,
const char *reviewTitle,
const char *reviewSubTitle)

{
nbgl_sync_init();
nbgl_useCaseReviewStreamingStart(
operationType, icon, reviewTitle, reviewSubTitle, choice_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingContinue(
const nbgl_layoutTagValueList_t *tagValueList)

{
nbgl_sync_init();
nbgl_useCaseReviewStreamingContinue(tagValueList, choice_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingFinish(const char *finishTitle)

{
nbgl_sync_init();
nbgl_useCaseReviewStreamingFinish(finishTitle, choice_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseGenericReview(const nbgl_genericContents_t *contents,
const char *rejectText)

{
nbgl_sync_init();
nbgl_useCaseGenericReview(contents, rejectText, rejected_callback);
return nbgl_sync_wait(false);
}

nbgl_sync_ret_t nbgl_sync_useCaseGenericConfiguration(const char *title,
uint8_t initPage,
const nbgl_genericContents_t *contents)

{
nbgl_sync_init();
nbgl_useCaseGenericConfiguration(title, initPage, contents, quit_callback);
return nbgl_sync_wait(false);
}
17 changes: 17 additions & 0 deletions lib_standard_app/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,20 @@ WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint1

return ret;
}

#ifdef STANDARD_APP_SYNC_RAPDU
WEAK bool io_recv_and_process_event(void)
{
int apdu_state = G_io_app.apdu_state;

os_io_seph_recv_and_process(0);

// If an APDU was received in previous os_io_seph_recv_and_process call and
// is waiting to be processed, return true
if (apdu_state == APDU_IDLE && G_io_app.apdu_state != APDU_IDLE) {
return true;
}

return false;
}
#endif

0 comments on commit dfd3050

Please sign in to comment.