/* ipwps_pbc.c - IPWPS Protocol Adaptor 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,26feb09,mry Created */ /* DESCRIPTION: * =========== * This library contains the IPWPS PBC Config Method support routines. */ /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ #include "ipwps_config.h" /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #define IPCOM_USE_CLIB_PROTO #include #include #include #include #include #include #include "ipwps_common.h" #include "ipwps_pbc.h" #include "ipwps_config_methods.h" /* MUST BE AFTER "ipwps_pbc.h" which redefines IPWPS_CONFIG_METHOD_CTX */ /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #define IPWPS_PUSHBUTTON_DEVICE_PASSWORD "00000000" /* **************************************************************************** * 5 TYPES **************************************************************************** */ typedef struct Ipwps_pbc_ctx_st { Ip_bool enabled; Ip_u16 config_method; Ipwps_device_pwdid dev_pwd_id; } Ipwps_pbc_ctx; /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 8 STATIC FUNCTIONS **************************************************************************** */ IP_STATIC Ip_bool ipwps_pbc_is_enabled(Ipwps_pbc_ctx *pbc_ctx); IP_STATIC Ip_u16 Ipwps_pbc_get_config_method(Ipwps_pbc_ctx *pbc_ctx); IP_STATIC Ipwps_device_pwdid Ipwps_pbc_get_pwd_id(Ipwps_pbc_ctx *pbc_ctx); IP_STATIC Ip_err Ipwps_pbc_handle_event(Ipwps_pbc_ctx *pbc_ctx, Ipwps_event_msg *event_msg, Ipwps_event_data *resp_event_data); IP_STATIC Ipwps_operation_status ipwps_pbc_get_device_password(Ipwps_pbc_ctx *pbc_ctx, Ipwps_dev_pwd_container *dev_pwd); /* * **************************************************************************** * 9 DATA **************************************************************************** */ IP_STATIC Ipwps_config_method_api ipwps_pbc_cma = { ipwps_pbc_is_enabled, Ipwps_pbc_get_config_method, Ipwps_pbc_get_pwd_id, Ipwps_pbc_handle_event, ipwps_pbc_get_device_password }; /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ /* *=========================================================================== * *=========================================================================== * Description: * Initializes a PBC config method context and provides its supported config * methods. * Parameters: * struct ipwps_pbc_ctx_st *supported_config_methods - This will be updated * upon successful initialization to contain all the supported WPS config * methods by this PBC umbrella config method. * Returns: * Pointer to a valid PBC config method context if successful, * IP_NULL otherwise */ IP_GLOBAL Ipwps_pbc_ctx *ipwps_pbc_init(Ip_u16 *supported_config_methods) { Ipwps_pbc_ctx *pbc_ctx = IP_NULL; ip_assert(supported_config_methods); pbc_ctx = ipcom_calloc(1, sizeof(Ipwps_pbc_ctx)); if (!pbc_ctx) { IPCOM_LOG0(CRIT, "ipwps_pbc_init :: out of memory"); return IP_NULL; } pbc_ctx->enabled = ipcom_sysvar_get_as_int(IPWPS_SYSVAR_PBC_ENABLE, 0); if (pbc_ctx->enabled) { pbc_ctx->dev_pwd_id = IPWPS_DEVPWDID_PUSHBUTTON; *supported_config_methods = IPWPS_CONFIG_METHOD_PUSHBUTTON; pbc_ctx->config_method = IPWPS_CONFIG_METHOD_PUSHBUTTON; } return pbc_ctx; } /* *=========================================================================== * ipwps_pbc_destroy *=========================================================================== * Description: * Parameters: * Returns: */ IP_GLOBAL Ip_err ipwps_pbc_destroy(Ipwps_pbc_ctx *pbc_ctx) { ip_assert(pbc_ctx); ipcom_free(pbc_ctx); return IPCOM_SUCCESS; } /* *=========================================================================== * ipwps_pbc_get_cma *=========================================================================== * Description: * Returns the Ipwps_config_method_api for the corresponding PBC config method. * Parameters: * struct ipwps_pbc_ctx_st *pbc_ctx - Pointer to a valid allocated PBC config * method context. * Returns: * Pointer to a valid Ipwps_config_method_api if successful, * IP_NULL otherwise. */ IP_GLOBAL Ipwps_config_method_api *ipwps_pbc_get_cma(Ipwps_pbc_ctx *pbc_ctx) { ip_assert(pbc_ctx); return &ipwps_pbc_cma; } /* *=========================================================================== * *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_bool ipwps_pbc_is_enabled(Ipwps_pbc_ctx *pbc_ctx) { ip_assert(pbc_ctx); return pbc_ctx->enabled; } /* *=========================================================================== * *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_u16 Ipwps_pbc_get_config_method(Ipwps_pbc_ctx *pbc_ctx) { ip_assert(pbc_ctx); return pbc_ctx->config_method; } /* *=========================================================================== * *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ipwps_device_pwdid Ipwps_pbc_get_pwd_id(Ipwps_pbc_ctx *pbc_ctx) { ip_assert(pbc_ctx); return pbc_ctx->dev_pwd_id; } /* *=========================================================================== * Ipwps_pbc_handle_event *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_err Ipwps_pbc_handle_event(Ipwps_pbc_ctx *pbc_ctx, Ipwps_event_msg *event_msg, Ipwps_event_data *resp_event_data) { ip_assert(pbc_ctx); ip_assert(event_msg); if (event_msg->event_type.pbc_event != IPWPS_PBC_EVENT_PUSHBUTTON) { IPCOM_LOG0(DEBUG2, "Ipwps_pbc_handle_event :: received unsupported event"); return IPCOM_ERR_NOT_SUPPORTED; } return IPCOM_SUCCESS; } /* *=========================================================================== * ipwps_pbc_get_device_password *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ipwps_operation_status ipwps_pbc_get_device_password(Ipwps_pbc_ctx *pbc_ctx, Ipwps_dev_pwd_container *dev_pwd) { ip_assert(pbc_ctx); ip_assert(dev_pwd); dev_pwd->len = ipcom_strlen(IPWPS_PUSHBUTTON_DEVICE_PASSWORD); ip_assert(dev_pwd->len <= IPWPS_DEVICE_PASSWORD_MAXLEN); ipcom_memcpy(dev_pwd->pwd, IPWPS_PUSHBUTTON_DEVICE_PASSWORD, dev_pwd->len); return IPWPS_OPSTATUS_OK; }