示例#1
0
文件: wps.c 项目: drashti304/TizenRT
/**
 * wps_process_msg - Process a WPS message
 * @wps: WPS Registration protocol data from wps_init()
 * @op_code: Message OP Code
 * @msg: Message data
 * Returns: Processing result
 *
 * This function is used to process WPS messages with OP Codes WSC_ACK,
 * WSC_NACK, WSC_MSG, and WSC_Done. The caller (e.g., EAP server/peer) is
 * responsible for reassembling the messages before calling this function.
 * Response to this message is built by calling wps_get_msg().
 */
enum wps_process_res wps_process_msg(struct wps_data *wps, enum wsc_op_code op_code, const struct wpabuf *msg)
{
	if (wps->registrar) {
		return wps_registrar_process_msg(wps, op_code, msg);
	} else {
		return wps_enrollee_process_msg(wps, op_code, msg);
	}
}
示例#2
0
/* Processes a received WPS message and returns the message type */
enum wps_type process_wps_message(const void *data, size_t data_size) {
    const struct wpabuf *msg = NULL;
    enum wps_type type = UNKNOWN;
    struct wps_data *wps = get_wps();
    unsigned char *element_data = NULL;
    struct wfa_element_header element = {0};
    int i = 0, header_size = sizeof (struct wfa_element_header);

    /* Shove data into a wpabuf structure for processing */
    msg = wpabuf_alloc_copy(data, data_size);
    if (msg) {
        /* Process the incoming message */
        wps_registrar_process_msg(wps, get_opcode(), msg);
        wpabuf_free((struct wpabuf *) msg);

        /* Loop through until we hit the end of the data buffer */
        for (i = 0; i < data_size; i += header_size) {
            element_data = NULL;
            memset((void *) &element, 0, header_size);

            /* Get the element header data */
            memcpy((void *) &element, (data + i), header_size);
            element.type = htons(element.type);
            element.length = htons(element.length);

            /* Make sure the element length does not exceed the remaining buffer size */
            if (element.length <= (data_size - i - header_size)) {
                element_data = (unsigned char *) (data + i + header_size);

                switch (element.type) {
                    case MESSAGE_TYPE:
                        type = (uint8_t) element_data[0];
                        break;
                    case CONFIGURATION_ERROR:
                        /* Check element_data length */
                        if (element.length == 2)
                            set_nack_reason(htons(*((uint16_t*) element_data)));
                        break;
                    default:
                        break;
                }
            }

            /* Offset must include element length(s) */
            i += element.length;
        }

    }

    return type;
}