/*
* Intel Wireless WiMAX Connection 2400m
* Miscellaneous control functions for managing the device
*
*
* Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Intel Corporation <linux-wimax@intel.com>
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
* - Initial implementation
*
* This is a collection of functions used to control the device (plus
* a few helpers).
*
* There are utilities for handling TLV buffers, hooks on the device's
* reports to act on device changes of state [i2400m_report_hook()],
* on acks to commands [i2400m_msg_ack_hook()], a helper for sending
* commands to the device and blocking until a reply arrives
* [i2400m_msg_to_dev()], a few high level commands for manipulating
* the device state, powersving mode and configuration plus the
* routines to setup the device once communication is stablished with
* it [i2400m_dev_initialize()].
*
* ROADMAP
*
* i2400m_dev_initalize() Called by i2400m_dev_start()
* i2400m_set_init_config()
* i2400m_firmware_check()
* i2400m_cmd_get_state()
* i2400m_dev_shutdown() Called by i2400m_dev_stop()
* i2400m->bus_reset()
*
* i2400m_{cmd,get,set}_*()
* i2400m_msg_to_dev()
* i2400m_msg_check_status()
*
* i2400m_report_hook() Called on reception of an event
* i2400m_report_state_hook()
* i2400m_tlv_buffer_walk()
* i2400m_tlv_match()
* i2400m_report_tlv_system_state()
* i2400m_report_tlv_rf_switches_status()
* i2400m_report_tlv_media_status()
* i2400m_cmd_enter_powersave()
*
* i2400m_msg_ack_hook() Called on reception of a reply to a
* command, get or set
*/
#include <stdarg.h>
#include "i2400m.h"
#include <linux/kernel.h>
#include <linux/wimax/i2400m.h>
#define D_SUBMODULE control
#include "debug-levels.h"
/*
* Return if a TLV is of a give type and size
*
* @tlv_hdr: pointer to the TLV
* @tlv_type: type of the TLV we are looking for
* @tlv_size: expected size of the TLV we are looking for (if -1,
* don't check the size). This includes the header
* Returns: 0 if the TLV matches
* < 0 if it doesn't match at all
* > 0 total TLV + payload size, if the type matches, but not
* the size
*/
static
ssize_t i2400m_tlv_match(const struct i2400m_tlv_hdr *tlv,
enum i2400m_tlv tlv_type, ssize_t tlv_size)
{
if (le16_to_cpu(tlv->type) != tlv_type) /* Not our type? skip */
return -1;
if (tlv_size != -1
&& le16_to_cpu(tlv->length) + sizeof(*tlv) != tlv_size) {
size_t size = le16_to_cpu(tlv->length) + sizeof(*tlv);
printk(KERN_WARNING "W: tlv type 0x%x mismatched because of "
"size (got %zu vs %zu expected)\n",
tlv_type, size, tlv_size);
return size;
}
return 0;
}
/*
* Given a buffer of TLVs, iterate over them
*
* @i2400m: device instance
* @tlv_buf: pointer to the beginning of the TLV buffer
* @buf_size: buffer size in bytes
* @tlv_pos: seek position; this is assumed to be a pointer returned
* by i2400m_tlv_buffer_walk() [and thus, validated]. The
* TLV returned will be the one following this one.
*
* Usage:
*
* tlv_itr = NULL;
* while (tlv_itr = i2400m_tlv_buffer_walk(i2400m, buf, size, tlv_itr)) {
* ...
* // Do stuff with tlv_itr, DON'T MODIFY IT
* ...
* }
*/
static
const struct i2400m_tlv_hdr *i2400m_tlv_buffer_walk(
struct i2400m *i2400m,
const void *tlv_buf, size_t buf_size,
const struct i2400m_tlv_hdr *