Files
m241Neelima/components/ip_net2-6.9/ipwps/src/ipwps_ui.c
T
2026-07-30 11:19:44 +05:30

268 lines
9.4 KiB
C

/* ipwps_ui.c - IPWPS User Interface implementation */
/*
* Copyright (c) 2009 Wind River Systems, Inc.
*
* The right to copy, distribute, modify, or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*
*/
/*
modification history
--------------------
01a,16mar09,mry Created
*/
/* DESCRIPTION:
* ===========
* This library contains the IPWPS User Interface implementation.
* The current User Interface implementation uses the console to
* prompt/notify with the user (via printf).
* The implementation of the UI functions can be cutomized to support
* a richer UI (e.g. web based or GUI).
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipwps_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#define IPCOM_USE_CLIB_PROTO
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_clib.h>
#include <ipcom_err.h>
#include <ipcom_syslog.h>
#include "ipwps_core.h"
#include "ipwps_ui.h"
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 8 STATIC FUNCTIONS
****************************************************************************
*/
IP_STATIC int ipwps_ui_led_feedback(Ipwps_session_status status);
/*
*
****************************************************************************
* 9 DATA
****************************************************************************
*/
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipwps_ui_display
*===========================================================================
* Description:
* The implementation of this function can customized to use a richer UI
* NOTE: THIS FUNCTION MUST NOT BLOCK OR PEND.
* Parameters:
* Returns:
* >= 0 if successful, < 0 if not.
*/
IP_GLOBAL int ipwps_ui_display(Ipwps_ui_display_type type, const char *string) {
char *prefix = "";
#define IPWPS_UI_DISPLAY_STRING ">>>>> WPS %s: %s"
switch (type) {
case IPWPS_UI_DISPLAY_CRITICAL:
/* Warn the user of a possible serious event */
prefix = "CRITICAL";
IPCOM_LOG2(CRIT, IPWPS_UI_DISPLAY_STRING, prefix, string);
break;
case IPWPS_UI_DISPLAY_ERROR:
/* Inform the user of an error event */
prefix = "ERROR";
IPCOM_LOG2(ERR, IPWPS_UI_DISPLAY_STRING, prefix, string);
break;
case IPWPS_UI_DISPLAY_WARNING:
/* Warn the user of a possible serious event */
prefix = "WARNING";
IPCOM_LOG2(WARNING, IPWPS_UI_DISPLAY_STRING, prefix, string);
break;
case IPWPS_UI_DISPLAY_NOTIFICATION:
prefix = "NOTIFICATION";
IPCOM_LOG2(INFO, IPWPS_UI_DISPLAY_STRING, prefix, string);
break;
case IPWPS_UI_DISPLAY_INFO:
prefix = "INFO";
IPCOM_LOG2(INFO, IPWPS_UI_DISPLAY_STRING, prefix, string);
break;
}
return 0;
}
/*
*===========================================================================
* ipwps_ui_prompt
*===========================================================================
* Description:
* The implementation of this function can customized to use a richer UI
* NOTE: THIS FUNCTION MUST NOT BLOCK OR PEND.
* Parameters:
* Returns:
* >= 0 if successful, < 0 if not.
*/
IP_GLOBAL int ipwps_ui_prompt(Ipwps_ui_prompt_type prompt, const char *string) {
switch (prompt) {
case IPWPS_UI_PROMPT_ENTER_PIN:
ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, string);
ipwps_ui_display(IPWPS_UI_DISPLAY_INFO, "Use \"wps pin set\".");
break;
case IPWPS_UI_PROMPT_WPS_AP_FOUND:
ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, string);
break;
case IPWPS_UI_PROMPT_WPS_REGISTRAR_FOUND:
ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, string);
break;
case IPWPS_UI_PROMPT_WPS_PBC_ENROLLEE_DETECTED:
ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, string);
break;
}
return 0;
}
/*
*===========================================================================
* ipwps_ui_report_wps_status
*===========================================================================
* Description: IPWPS User Interface function which is called by
* IPWPS applications to report the WPS status as described in the WPS spec.
* DO NOT MODIFY THIS FUNCTION. Instead modify
* ipwps_ui_display() and/or ipwps_ui_led_feedback().
* Parameters:
* Ipwps_session_status status - WPS status to report.
* Returns:
* >= 0 if successful, < 0 if not.
*/
IP_GLOBAL int ipwps_ui_report_wps_status(Ipwps_ctx* ctx, Ipwps_session_status status) {
int rc = 0;
ip_assert(ctx);
if (ipwps_ui_led_feedback(status) == 0)
return 0;
switch (status) {
case IPWPS_SESSION_STATUS_IDLE:
ctx->public.coop_info.session_status = IPWPS_SESSION_STATUS_IDLE;
ctx->public.coop_info.config_error = IPWPS_CONFIG_ERROR_NOERR;
ipcom_memset(&ctx->public.peer_dev_info, 0, sizeof(ctx->public.peer_dev_info));
ipcom_memset(&ctx->public.peer_cap_info, 0, sizeof(ctx->public.peer_cap_info));
IPCOM_LOG0(DEBUG, "IPWPS UI STATUS IDLE");
break;
case IPWPS_SESSION_STATUS_IN_PROGRESS:
ctx->public.coop_info.session_status = IPWPS_SESSION_STATUS_IN_PROGRESS;
rc = ipwps_ui_display(IPWPS_UI_DISPLAY_INFO, "WPS Session in progress. Please wait...");
break;
case IPWPS_SESSION_STATUS_ERROR:
ctx->public.coop_info.session_status = IPWPS_SESSION_STATUS_ERROR;
rc = ipwps_ui_display(IPWPS_UI_DISPLAY_ERROR, "WPS Session failed.");
break;
case IPWPS_SESSION_STATUS_SESSION_OVERLAP:
ctx->public.coop_info.session_status = IPWPS_SESSION_STATUS_SESSION_OVERLAP;
rc = ipwps_ui_display(IPWPS_UI_DISPLAY_CRITICAL, "WPS Session overlap detected. Possible Security Risk!");
break;
case IPWPS_SESSION_STATUS_SUCCESS:
ctx->public.coop_info.session_status = IPWPS_SESSION_STATUS_SUCCESS;
rc = ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, "WPS Session completed sucessfully.");
break;
case IPWPS_ENROLLEE_JOIN_SUCCESS:
{
char notify[256];
snprintf(notify, sizeof(notify), "Successfully associated with ssid \"%s\".",
ctx->credentials.enrollee_credentials[ctx->public.enrollee_info.credential_setno].ssid);
ipwps_ui_display(IPWPS_UI_DISPLAY_NOTIFICATION, notify);
break;
}
case IPWPS_ENROLLEE_JOIN_FAIL:
ipwps_ui_display(IPWPS_UI_DISPLAY_CRITICAL, "FAILED to associate with an AP using the credentials provided by the WPS registrar.");
break;
}
return rc;
}
/*
*===========================================================================
* ipwps_ui_led_feedback
*===========================================================================
* Description:
* The implementation of this function can customized to provide the LED feedback
* NOTE: THIS FUNCTION MUST NOT BLOCK OR PEND.
* If LED feedback is desired, define IPWPS_UI_LED_FEEDBACK
* and customize this function to implement the LED feedback functionality.
* Parameters:
* Ipwps_session_status status - WPS session status to report.
* Returns:
* 0 if successful and no further UI display is desired.
* >0 if successful and/or further UI display is desired.
* < 0 if not successful but further UI display is desired.
*/
IP_STATIC int ipwps_ui_led_feedback(Ipwps_session_status status) {
#ifdef IPWPS_UI_LED_FEEDBACK
/* LED Patterns for IPWPS_SESSION_STATUS_IN_PROGRESS, IPWPS_SESSION_STATUS_ERROR,
* IPWPS_SESSION_STATUS_SESSION_OVERLAP, IPWPS_SESSION_STATUS_SUCCESS
* are defined in "WPS Usability and Protocol Best Practices, v1.0.7, Oct 2008" as follows:
* IPWPS_SESSION_STATUS_IN_PROGRESS: 2 sec on, 1 sec off, ... repeated (in yellow if available)
* IPWPS_SESSION_STATUS_ERROR: 0.25 sec on, 0.25 sec off, ... repeated (in red if available)
* IPWPS_SESSION_STATUS_SESSION_OVERLAP: 0.25 sec on, 0.25 sec off, ... repeated for 1 second,
* followed by 0.5 sec off, then the whole pattern repeated (in red if available)
* IPWPS_SESSION_STATUS_SUCCESS: 300 seconds on then off (in green if available)
* IPWPS_SESSION_STATUS_IDLE should cause the LED to be turned off
*/
return 1;
#else
return -1;
#endif
}