/** * wimax_report_rfkill_hw - Reports changes in the hardware RF switch * * @wimax_dev: WiMAX device descriptor * * @state: New state of the RF Kill switch. %WIMAX_RF_ON radio on, * %WIMAX_RF_OFF radio off. * * When the device detects a change in the state of thehardware RF * switch, it must call this function to let the WiMAX kernel stack * know that the state has changed so it can be properly propagated. * * The WiMAX stack caches the state (the driver doesn't need to). As * well, as the change is propagated it will come back as a request to * change the software state to mirror the hardware state. * * If the device doesn't have a hardware kill switch, just report * it on initialization as always on (%WIMAX_RF_ON, radio on). */ void wimax_report_rfkill_hw(struct wimax_dev *wimax_dev, enum wimax_rf_state state) { int result; struct device *dev = wimax_dev_to_dev(wimax_dev); enum wimax_st wimax_state; d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); BUG_ON(state == WIMAX_RF_QUERY); BUG_ON(state != WIMAX_RF_ON && state != WIMAX_RF_OFF); mutex_lock(&wimax_dev->mutex); result = wimax_dev_is_ready(wimax_dev); if (result < 0) goto error_not_ready; if (state != wimax_dev->rf_hw) { wimax_dev->rf_hw = state; if (wimax_dev->rf_hw == WIMAX_RF_ON && wimax_dev->rf_sw == WIMAX_RF_ON) wimax_state = WIMAX_ST_READY; else wimax_state = WIMAX_ST_RADIO_OFF; result = rfkill_set_hw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); __wimax_state_change(wimax_dev, wimax_state); } error_not_ready: mutex_unlock(&wimax_dev->mutex); d_fnend(3, dev, "(wimax_dev %p state %u) = void [%d]\n", wimax_dev, state, result); }
/* * Callback for the RF Kill toggle operation * * This function is called by: * * - The rfkill subsystem when the RF-Kill key is pressed in the * hardware and the driver notifies through * wimax_report_rfkill_hw(). The rfkill subsystem ends up calling back * here so the software RF Kill switch state is changed to reflect * the hardware switch state. * * - When the user sets the state through sysfs' rfkill/state file * * - When the user calls wimax_rfkill(). * * This call blocks! * * WARNING! When we call rfkill_unregister(), this will be called with * state 0! * * WARNING: wimax_dev must be locked */ static int __wimax_rf_toggle_radio(struct wimax_dev *wimax_dev, enum wimax_rf_state state) { int result = 0; struct device *dev = wimax_dev_to_dev(wimax_dev); enum wimax_st wimax_state; might_sleep(); d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); if (wimax_dev->rf_sw == state) goto out_no_change; if (wimax_dev->op_rfkill_sw_toggle != NULL) result = wimax_dev->op_rfkill_sw_toggle(wimax_dev, state); else if (state == WIMAX_RF_OFF) /* No op? can't turn off */ result = -ENXIO; else /* No op? can turn on */ result = 0; /* should never happen tho */ if (result >= 0) { result = 0; wimax_dev->rf_sw = state; wimax_state = state == WIMAX_RF_ON ? WIMAX_ST_READY : WIMAX_ST_RADIO_OFF; __wimax_state_change(wimax_dev, wimax_state); } out_no_change: d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n", wimax_dev, state, result); return result; }
/* * Exporting to user space over generic netlink * * Parse the reset command from user space, return error code. * * No attributes. */ static int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info) { int result, ifindex; struct wimax_dev *wimax_dev; struct device *dev; d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); result = -ENODEV; if (info->attrs[WIMAX_GNL_RESET_IFIDX] == NULL) { printk(KERN_ERR "WIMAX_GNL_OP_RFKILL: can't find IFIDX " "attribute\n"); goto error_no_wimax_dev; } ifindex = nla_get_u32(info->attrs[WIMAX_GNL_RESET_IFIDX]); wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); if (wimax_dev == NULL) goto error_no_wimax_dev; dev = wimax_dev_to_dev(wimax_dev); /* Execute the operation and send the result back to user space */ result = wimax_reset(wimax_dev); dev_put(wimax_dev->net_dev); error_no_wimax_dev: d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); return result; }
static int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info) { int result, ifindex; struct wimax_dev *wimax_dev; struct device *dev; d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); result = -ENODEV; if (info->attrs[WIMAX_GNL_STGET_IFIDX] == NULL) { printk(KERN_ERR "WIMAX_GNL_OP_STATE_GET: can't find IFIDX " "attribute\n"); goto error_no_wimax_dev; } ifindex = nla_get_u32(info->attrs[WIMAX_GNL_STGET_IFIDX]); wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); if (wimax_dev == NULL) goto error_no_wimax_dev; dev = wimax_dev_to_dev(wimax_dev); result = wimax_state_get(wimax_dev); dev_put(wimax_dev->net_dev); error_no_wimax_dev: d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); return result; }
/* * Deregister a WiMAX device's RF Kill support * * Ick, we can't call rfkill_free() after rfkill_unregister()...oh * well. * * WARNING: wimax_dev->mutex must be unlocked */ void wimax_rfkill_rm(struct wimax_dev *wimax_dev) { struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev); rfkill_unregister(wimax_dev->rfkill); rfkill_destroy(wimax_dev->rfkill); d_fnend(3, dev, "(wimax_dev %p)\n", wimax_dev); }
/* * Allocate a Report State Change message * * @header: save it, you need it for _send() * * Creates and fills a basic state change message; different code * paths can then add more attributes to the message as needed. * * Use wimax_gnl_re_state_change_send() to send the returned skb. * * Returns: skb with the genl message if ok, IS_ERR() ptr on error * with an errno code. */ static struct sk_buff *wimax_gnl_re_state_change_alloc( struct wimax_dev *wimax_dev, enum wimax_st new_state, enum wimax_st old_state, void **header) { int result; struct device *dev = wimax_dev_to_dev(wimax_dev); void *data; struct sk_buff *report_skb; d_fnstart(3, dev, "(wimax_dev %p new_state %u old_state %u)\n", wimax_dev, new_state, old_state); result = -ENOMEM; report_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (report_skb == NULL) { dev_err(dev, "RE_STCH: can't create message\n"); goto error_new; } /* FIXME: sending a group ID as the seq is wrong */ data = genlmsg_put(report_skb, 0, wimax_gnl_family.mcgrp_offset, &wimax_gnl_family, 0, WIMAX_GNL_RE_STATE_CHANGE); if (data == NULL) { dev_err(dev, "RE_STCH: can't put data into message\n"); goto error_put; } *header = data; result = nla_put_u8(report_skb, WIMAX_GNL_STCH_STATE_OLD, old_state); if (result < 0) { dev_err(dev, "RE_STCH: Error adding OLD attr: %d\n", result); goto error_put; } result = nla_put_u8(report_skb, WIMAX_GNL_STCH_STATE_NEW, new_state); if (result < 0) { dev_err(dev, "RE_STCH: Error adding NEW attr: %d\n", result); goto error_put; } result = nla_put_u32(report_skb, WIMAX_GNL_STCH_IFIDX, wimax_dev->net_dev->ifindex); if (result < 0) { dev_err(dev, "RE_STCH: Error adding IFINDEX attribute\n"); goto error_put; } d_fnend(3, dev, "(wimax_dev %p new_state %u old_state %u) = %p\n", wimax_dev, new_state, old_state, report_skb); return report_skb; error_put: nlmsg_free(report_skb); error_new: d_fnend(3, dev, "(wimax_dev %p new_state %u old_state %u) = %d\n", wimax_dev, new_state, old_state, result); return ERR_PTR(result); }
struct sk_buff *wimax_msg_alloc(struct wimax_dev *wimax_dev, const char *pipe_name, const void *msg, size_t size, gfp_t gfp_flags) { int result; struct device *dev = wimax_dev_to_dev(wimax_dev); size_t msg_size; void *genl_msg; struct sk_buff *skb; msg_size = nla_total_size(size) + nla_total_size(sizeof(u32)) + (pipe_name ? nla_total_size(strlen(pipe_name)) : 0); result = -ENOMEM; skb = genlmsg_new(msg_size, gfp_flags); if (skb == NULL) goto error_new; genl_msg = genlmsg_put(skb, 0, 0, &wimax_gnl_family, 0, WIMAX_GNL_OP_MSG_TO_USER); if (genl_msg == NULL) { dev_err(dev, "no memory to create generic netlink message\n"); goto error_genlmsg_put; } result = nla_put_u32(skb, WIMAX_GNL_MSG_IFIDX, wimax_dev->net_dev->ifindex); if (result < 0) { dev_err(dev, "no memory to add ifindex attribute\n"); goto error_nla_put; } if (pipe_name) { result = nla_put_string(skb, WIMAX_GNL_MSG_PIPE_NAME, pipe_name); if (result < 0) { dev_err(dev, "no memory to add pipe_name attribute\n"); goto error_nla_put; } } result = nla_put(skb, WIMAX_GNL_MSG_DATA, size, msg); if (result < 0) { dev_err(dev, "no memory to add payload (msg %p size %zu) in " "attribute: %d\n", msg, size, result); goto error_nla_put; } genlmsg_end(skb, genl_msg); return skb; error_nla_put: error_genlmsg_put: error_new: nlmsg_free(skb); return ERR_PTR(result); }
int wimax_msg_send(struct wimax_dev *wimax_dev, struct sk_buff *skb) { struct device *dev = wimax_dev_to_dev(wimax_dev); void *msg = skb->data; size_t size = skb->len; might_sleep(); d_printf(1, dev, "CTX: wimax msg, %zu bytes\n", size); d_dump(2, dev, msg, size); genlmsg_multicast(skb, 0, wimax_gnl_mcg.id, GFP_KERNEL); d_printf(1, dev, "CTX: genl multicast done\n"); return 0; }
/* * Send a Report State Change message (as created with _alloc). * * @report_skb: as returned by wimax_gnl_re_state_change_alloc() * @header: as returned by wimax_gnl_re_state_change_alloc() * * Returns: 0 if ok, < 0 errno code on error. * * If the message is NULL, pretend it didn't happen. */ static int wimax_gnl_re_state_change_send( struct wimax_dev *wimax_dev, struct sk_buff *report_skb, void *header) { int result = 0; struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p report_skb %p)\n", wimax_dev, report_skb); if (report_skb == NULL) { result = -ENOMEM; goto out; } genlmsg_end(report_skb, header); genlmsg_multicast(&wimax_gnl_family, report_skb, 0, 0, GFP_KERNEL); out: d_fnend(3, dev, "(wimax_dev %p report_skb %p) = %d\n", wimax_dev, report_skb, result); return result; }
/* * Translate from rfkill state to wimax state * * NOTE: Special state handling rules here * * Just pretend the call didn't happen if we are in a state where * we know for sure it cannot be handled (WIMAX_ST_DOWN or * __WIMAX_ST_QUIESCING). rfkill() needs it to register and * unregister, as it will run this path. * * NOTE: This call will block until the operation is completed. */ static int wimax_rfkill_set_radio_block(void *data, bool blocked) { int result; struct wimax_dev *wimax_dev = data; struct device *dev = wimax_dev_to_dev(wimax_dev); enum wimax_rf_state rf_state; d_fnstart(3, dev, "(wimax_dev %p blocked %u)\n", wimax_dev, blocked); rf_state = WIMAX_RF_ON; if (blocked) rf_state = WIMAX_RF_OFF; mutex_lock(&wimax_dev->mutex); if (wimax_dev->state <= __WIMAX_ST_QUIESCING) result = 0; else result = __wimax_rf_toggle_radio(wimax_dev, rf_state); mutex_unlock(&wimax_dev->mutex); d_fnend(3, dev, "(wimax_dev %p blocked %u) = %d\n", wimax_dev, blocked, result); return result; }
int wimax_rfkill(struct wimax_dev *wimax_dev, enum wimax_rf_state state) { int result; struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); mutex_lock(&wimax_dev->mutex); result = wimax_dev_is_ready(wimax_dev); if (result < 0) { /* */ if (result == -ENOMEDIUM && state == WIMAX_RF_QUERY) result = WIMAX_RF_OFF << 1 | WIMAX_RF_OFF; goto error_not_ready; } switch (state) { case WIMAX_RF_ON: case WIMAX_RF_OFF: result = __wimax_rf_toggle_radio(wimax_dev, state); if (result < 0) goto error; rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); break; case WIMAX_RF_QUERY: break; default: result = -EINVAL; goto error; } result = wimax_dev->rf_sw << 1 | wimax_dev->rf_hw; error: error_not_ready: mutex_unlock(&wimax_dev->mutex); d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n", wimax_dev, state, result); return result; }
/** * wimax_rfkill - Set the software RF switch state for a WiMAX device * * @wimax_dev: WiMAX device descriptor * * @state: New RF state. * * Returns: * * >= 0 toggle state if ok, < 0 errno code on error. The toggle state * is returned as a bitmap, bit 0 being the hardware RF state, bit 1 * the software RF state. * * 0 means disabled (%WIMAX_RF_ON, radio on), 1 means enabled radio * off (%WIMAX_RF_OFF). * * Description: * * Called by the user when he wants to request the WiMAX radio to be * switched on (%WIMAX_RF_ON) or off (%WIMAX_RF_OFF). With * %WIMAX_RF_QUERY, just the current state is returned. * * NOTE: * * This call will block until the operation is complete. */ int wimax_rfkill(struct wimax_dev *wimax_dev, enum wimax_rf_state state) { int result; struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); mutex_lock(&wimax_dev->mutex); result = wimax_dev_is_ready(wimax_dev); if (result < 0) { /* While initializing, < 1.4.3 wimax-tools versions use * this call to check if the device is a valid WiMAX * device; so we allow it to proceed always, * considering the radios are all off. */ if (result == -ENOMEDIUM && state == WIMAX_RF_QUERY) result = WIMAX_RF_OFF << 1 | WIMAX_RF_OFF; goto error_not_ready; } switch (state) { case WIMAX_RF_ON: case WIMAX_RF_OFF: result = __wimax_rf_toggle_radio(wimax_dev, state); if (result < 0) goto error; rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); break; case WIMAX_RF_QUERY: break; default: result = -EINVAL; goto error; } result = wimax_dev->rf_sw << 1 | wimax_dev->rf_hw; error: error_not_ready: mutex_unlock(&wimax_dev->mutex); d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n", wimax_dev, state, result); return result; }
/** * wimax_reset - Reset a WiMAX device * * @wimax_dev: WiMAX device descriptor * * Returns: * * %0 if ok and a warm reset was done (the device still exists in * the system). * * -%ENODEV if a cold/bus reset had to be done (device has * disconnected and reconnected, so current handle is not valid * any more). * * -%EINVAL if the device is not even registered. * * Any other negative error code shall be considered as * non-recoverable. * * Description: * * Called when wanting to reset the device for any reason. Device is * taken back to power on status. * * This call blocks; on successful return, the device has completed the * reset process and is ready to operate. */ int wimax_reset(struct wimax_dev *wimax_dev) { int result = -EINVAL; struct device *dev = wimax_dev_to_dev(wimax_dev); enum wimax_st state; might_sleep(); d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev); mutex_lock(&wimax_dev->mutex); dev_hold(wimax_dev->net_dev); state = wimax_dev->state; mutex_unlock(&wimax_dev->mutex); if (state >= WIMAX_ST_DOWN) { mutex_lock(&wimax_dev->mutex_reset); result = wimax_dev->op_reset(wimax_dev); mutex_unlock(&wimax_dev->mutex_reset); } dev_put(wimax_dev->net_dev); d_fnend(3, dev, "(wimax_dev %p) = %d\n", wimax_dev, result); return result; }
static int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info) { int result, ifindex; struct wimax_dev *wimax_dev; struct device *dev; enum wimax_rf_state new_state; d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); result = -ENODEV; if (info->attrs[WIMAX_GNL_RFKILL_IFIDX] == NULL) { printk(KERN_ERR "WIMAX_GNL_OP_RFKILL: can't find IFIDX " "attribute\n"); goto error_no_wimax_dev; } ifindex = nla_get_u32(info->attrs[WIMAX_GNL_RFKILL_IFIDX]); wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); if (wimax_dev == NULL) goto error_no_wimax_dev; dev = wimax_dev_to_dev(wimax_dev); result = -EINVAL; if (info->attrs[WIMAX_GNL_RFKILL_STATE] == NULL) { dev_err(dev, "WIMAX_GNL_RFKILL: can't find RFKILL_STATE " "attribute\n"); goto error_no_pid; } new_state = nla_get_u32(info->attrs[WIMAX_GNL_RFKILL_STATE]); /* */ result = wimax_rfkill(wimax_dev, new_state); error_no_pid: dev_put(wimax_dev->net_dev); error_no_wimax_dev: d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); return result; }
/* * Send a Report State Change message (as created with _alloc). * * @report_skb: as returned by wimax_gnl_re_state_change_alloc() * @header: as returned by wimax_gnl_re_state_change_alloc() * * Returns: 0 if ok, < 0 errno code on error. * * If the message is NULL, pretend it didn't happen. */ static int wimax_gnl_re_state_change_send( struct wimax_dev *wimax_dev, struct sk_buff *report_skb, void *header) { int result = 0; struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p report_skb %p)\n", wimax_dev, report_skb); if (report_skb == NULL) goto out; genlmsg_end(report_skb, header); result = genlmsg_multicast(report_skb, 0, wimax_gnl_mcg.id, GFP_KERNEL); if (result == -ESRCH) /* Nobody connected, ignore it */ result = 0; /* btw, the skb is freed already */ if (result < 0) { dev_err(dev, "RE_STCH: Error sending: %d\n", result); nlmsg_free(report_skb); } out: d_fnend(3, dev, "(wimax_dev %p report_skb %p) = %d\n", wimax_dev, report_skb, result); return result; }
/* * Register a new WiMAX device's RF Kill support * * WARNING: wimax_dev->mutex must be unlocked */ int wimax_rfkill_add(struct wimax_dev *wimax_dev) { int result; struct rfkill *rfkill; struct device *dev = wimax_dev_to_dev(wimax_dev); d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev); /* Initialize RF Kill */ result = -ENOMEM; rfkill = rfkill_alloc(wimax_dev->name, dev, RFKILL_TYPE_WIMAX, &wimax_rfkill_ops, wimax_dev); if (rfkill == NULL) goto error_rfkill_allocate; d_printf(1, dev, "rfkill %p\n", rfkill); wimax_dev->rfkill = rfkill; rfkill_init_sw_state(rfkill, 1); result = rfkill_register(wimax_dev->rfkill); if (result < 0) goto error_rfkill_register; /* If there is no SW toggle op, SW RFKill is always on */ if (wimax_dev->op_rfkill_sw_toggle == NULL) wimax_dev->rf_sw = WIMAX_RF_ON; d_fnend(3, dev, "(wimax_dev %p) = 0\n", wimax_dev); return 0; error_rfkill_register: rfkill_destroy(wimax_dev->rfkill); error_rfkill_allocate: d_fnend(3, dev, "(wimax_dev %p) = %d\n", wimax_dev, result); return result; }
/* * Set the current state of a WiMAX device [unlocking version of * wimax_state_change(). */ void __wimax_state_change(struct wimax_dev *wimax_dev, enum wimax_st new_state) { struct device *dev = wimax_dev_to_dev(wimax_dev); enum wimax_st old_state = wimax_dev->state; struct sk_buff *stch_skb; void *header; d_fnstart(3, dev, "(wimax_dev %p new_state %u [old %u])\n", wimax_dev, new_state, old_state); if (WARN_ON(new_state >= __WIMAX_ST_INVALID)) { dev_err(dev, "SW BUG: requesting invalid state %u\n", new_state); goto out; } if (old_state == new_state) goto out; header = NULL; /* gcc complains? can't grok why */ stch_skb = wimax_gnl_re_state_change_alloc( wimax_dev, new_state, old_state, &header); /* Verify the state transition and do exit-from-state actions */ switch (old_state) { case __WIMAX_ST_NULL: __check_new_state(old_state, new_state, 1 << WIMAX_ST_DOWN); break; case WIMAX_ST_DOWN: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_UNINITIALIZED | 1 << WIMAX_ST_RADIO_OFF); break; case __WIMAX_ST_QUIESCING: __check_new_state(old_state, new_state, 1 << WIMAX_ST_DOWN); break; case WIMAX_ST_UNINITIALIZED: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_RADIO_OFF); break; case WIMAX_ST_RADIO_OFF: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_READY); break; case WIMAX_ST_READY: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_RADIO_OFF | 1 << WIMAX_ST_SCANNING | 1 << WIMAX_ST_CONNECTING | 1 << WIMAX_ST_CONNECTED); break; case WIMAX_ST_SCANNING: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_RADIO_OFF | 1 << WIMAX_ST_READY | 1 << WIMAX_ST_CONNECTING | 1 << WIMAX_ST_CONNECTED); break; case WIMAX_ST_CONNECTING: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_RADIO_OFF | 1 << WIMAX_ST_READY | 1 << WIMAX_ST_SCANNING | 1 << WIMAX_ST_CONNECTED); break; case WIMAX_ST_CONNECTED: __check_new_state(old_state, new_state, 1 << __WIMAX_ST_QUIESCING | 1 << WIMAX_ST_RADIO_OFF | 1 << WIMAX_ST_READY); netif_tx_disable(wimax_dev->net_dev); netif_carrier_off(wimax_dev->net_dev); break; case __WIMAX_ST_INVALID: default: dev_err(dev, "SW BUG: wimax_dev %p is in unknown state %u\n", wimax_dev, wimax_dev->state); WARN_ON(1); goto out; } /* Execute the actions of entry to the new state */ switch (new_state) { case __WIMAX_ST_NULL: dev_err(dev, "SW BUG: wimax_dev %p entering NULL state " "from %u\n", wimax_dev, wimax_dev->state); WARN_ON(1); /* Nobody can enter this state */ break; case WIMAX_ST_DOWN: break; case __WIMAX_ST_QUIESCING: break; case WIMAX_ST_UNINITIALIZED: break; case WIMAX_ST_RADIO_OFF: break; case WIMAX_ST_READY: break; case WIMAX_ST_SCANNING: break; case WIMAX_ST_CONNECTING: break; case WIMAX_ST_CONNECTED: netif_carrier_on(wimax_dev->net_dev); netif_wake_queue(wimax_dev->net_dev); break; case __WIMAX_ST_INVALID: default: BUG(); } __wimax_state_set(wimax_dev, new_state); if (stch_skb) wimax_gnl_re_state_change_send(wimax_dev, stch_skb, header); out: d_fnend(3, dev, "(wimax_dev %p new_state %u [old %u]) = void\n", wimax_dev, new_state, old_state); return; }
static int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info) { int result, ifindex; struct wimax_dev *wimax_dev; struct device *dev; struct nlmsghdr *nlh = info->nlhdr; char *pipe_name; void *msg_buf; size_t msg_len; might_sleep(); d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); result = -ENODEV; if (info->attrs[WIMAX_GNL_MSG_IFIDX] == NULL) { printk(KERN_ERR "WIMAX_GNL_MSG_FROM_USER: can't find IFIDX " "attribute\n"); goto error_no_wimax_dev; } ifindex = nla_get_u32(info->attrs[WIMAX_GNL_MSG_IFIDX]); wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); if (wimax_dev == NULL) goto error_no_wimax_dev; dev = wimax_dev_to_dev(wimax_dev); /* */ result = -EINVAL; if (info->attrs[WIMAX_GNL_MSG_DATA] == NULL) { dev_err(dev, "WIMAX_GNL_MSG_FROM_USER: can't find MSG_DATA " "attribute\n"); goto error_no_data; } msg_buf = nla_data(info->attrs[WIMAX_GNL_MSG_DATA]); msg_len = nla_len(info->attrs[WIMAX_GNL_MSG_DATA]); if (info->attrs[WIMAX_GNL_MSG_PIPE_NAME] == NULL) pipe_name = NULL; else { struct nlattr *attr = info->attrs[WIMAX_GNL_MSG_PIPE_NAME]; size_t attr_len = nla_len(attr); /* */ result = -ENOMEM; pipe_name = kstrndup(nla_data(attr), attr_len + 1, GFP_KERNEL); if (pipe_name == NULL) goto error_alloc; pipe_name[attr_len] = 0; } mutex_lock(&wimax_dev->mutex); result = wimax_dev_is_ready(wimax_dev); if (result == -ENOMEDIUM) result = 0; if (result < 0) goto error_not_ready; result = -ENOSYS; if (wimax_dev->op_msg_from_user == NULL) goto error_noop; d_printf(1, dev, "CRX: nlmsghdr len %u type %u flags 0x%04x seq 0x%x pid %u\n", nlh->nlmsg_len, nlh->nlmsg_type, nlh->nlmsg_flags, nlh->nlmsg_seq, nlh->nlmsg_pid); d_printf(1, dev, "CRX: wimax message %zu bytes\n", msg_len); d_dump(2, dev, msg_buf, msg_len); result = wimax_dev->op_msg_from_user(wimax_dev, pipe_name, msg_buf, msg_len, info); error_noop: error_not_ready: mutex_unlock(&wimax_dev->mutex); error_alloc: kfree(pipe_name); error_no_data: dev_put(wimax_dev->net_dev); error_no_wimax_dev: d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); return result; }