From: Felix Varghese <felixvarg...@gmail.com>

Adds the implementation for MLME-GET primitive in mac802154.
This is according to IEEE 802.15.4-2006 specification.

Signed-off-by: Felix Varghese <felixvarg...@gmail.com>
Signed-off-by: Prajosh Premdas <premdas.praj...@gmail.com>
---
 net/mac802154/mlme_pib.c |  211 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 209 insertions(+), 2 deletions(-)

diff --git a/net/mac802154/mlme_pib.c b/net/mac802154/mlme_pib.c
index e52a4c7..74573b4 100644
--- a/net/mac802154/mlme_pib.c
+++ b/net/mac802154/mlme_pib.c
@@ -42,8 +42,6 @@ struct mlme_set_req_notify_work {
 /* MLME_GET request worker functions */
 static void internal_mlme_get_req_worker(struct work_struct *work);
 
-/* MLME_SET request worker functions */
-static void internal_mlme_set_req_worker(struct work_struct *work);
 
 void mac_pib_reset_def(struct net_device *dev)
 {
@@ -137,9 +135,218 @@ void mac_pib_reset_def(struct net_device *dev)
 
 int mlme_get_req(struct net_device *dev, u8 PIBattr)
 {
+       struct mac802154_sub_if_data *priv = netdev_priv(dev);
+       struct mlme_get_req_notify_work *work;
+
+       work = kzalloc(sizeof(*work), GFP_ATOMIC);
+       if (!work) {
+               /* Out of memory */
+               return -ENOMEM;
+       }
+
+       INIT_WORK(&work->work, internal_mlme_get_req_worker);
+       work->dev               = dev;
+       work->PIBattr   = PIBattr;
+       queue_work(priv->hw->dev_workqueue, &work->work);
+
        return 0;
 }
 
+static void internal_mlme_get_req_worker(struct work_struct *work)
+{
+       struct mlme_get_req_notify_work *nw = container_of(work,
+                       struct mlme_get_req_notify_work, work);
+
+       union pib_value_t *PIBvalue;
+       int ret;
+
+       PIBvalue = kmalloc(sizeof(union pib_value_t), GFP_ATOMIC);
+       if (!PIBvalue) {
+               /* Out of memory */
+               goto error_no_buff;
+       }
+
+       /*
+        * Call the mlme_get_req with parameters
+        * 1. struct dev : nw->dev
+        * 2. attribute to be read: nw->PIBattr
+        * 3. memory location where the value should be stored so that
+        * can be communicated in te confirm: conf_work->PIBval
+        */
+
+       ret = internal_get_mac_pib(nw->dev, nw->PIBattr, (char *)(PIBvalue));
+
+       ieee802154_nl_get_confirm(nw->dev, nw->PIBattr, PIBvalue, ret);
+
+       kfree(PIBvalue);
+error_no_buff:
+
+       kfree(nw);
+}
+
+int internal_get_mac_pib(struct net_device *dev, u8 PIBattr, void *PIBval)
+{
+       struct mac802154_sub_if_data *priv = netdev_priv(dev);
+       struct mac802154_priv *trx = priv->hw;
+       int ret;
+
+       /*
+        * Try the radio first so that it can override, in case it supports
+        * some of MAC attributes also (eg., for address filtering).
+        */
+       ret = trx->ops->get(&trx->hw, PIBattr, PIBval);
+
+       /*
+        * If radio doesnt support the attribute, try the MAC pib. In case
+        * of any other error, or success, return the status back.
+        */
+       if (ret != -EOPNOTSUPP)
+               return ret;
+
+       mutex_lock(&priv->macPIB_lock);
+
+       switch (PIBattr) {
+       case macAssociatedPANCoord:
+               *((u8 *)PIBval) = priv->macPIB.AssociatedPANCoord;
+               ret = sizeof(priv->macPIB.AssociatedPANCoord);
+               break;
+
+       case macAssociationPermit:
+               *((u8 *)PIBval) = priv->macPIB.AssociationPermit;
+               ret = sizeof(priv->macPIB.AssociationPermit);
+               break;
+
+       case macAutoRequest:
+               *((u8 *)PIBval) = priv->macPIB.AutoRequest;
+               ret = sizeof(priv->macPIB.AutoRequest);
+               break;
+
+       case macBattLifeExt:
+               *((u8 *)PIBval) = priv->macPIB.BattLifeExt;
+               ret = sizeof(priv->macPIB.BattLifeExt);
+               break;
+
+       case macBattLifeExtPeriods:
+               *((u8 *)PIBval) = priv->macPIB.BattLifeExtPeriods;
+               ret = sizeof(priv->macPIB.BattLifeExtPeriods);
+               break;
+
+       case macBeaconPayload:
+               memcpy(PIBval,
+               priv->macPIB.BeaconPayload,
+               priv->macPIB.BeaconPayloadLength);
+               ret = priv->macPIB.BeaconPayloadLength;
+               break;
+
+       case macBeaconPayloadLength:
+               *((u8 *)PIBval) = priv->macPIB.BeaconPayloadLength;
+               ret = sizeof(priv->macPIB.BeaconPayloadLength);
+               break;
+
+       case macBeaconOrder:
+               *((u8 *)PIBval) = priv->macPIB.BeaconOrder;
+               ret = sizeof(priv->macPIB.BeaconOrder);
+               break;
+
+       case macBeaconTxTime:
+               *((u32 *)PIBval) = priv->macPIB.BeaconTxTime;
+               ret = sizeof(priv->macPIB.BeaconTxTime);
+               break;
+
+       case macBSN:
+               *((u8 *)PIBval) = priv->macPIB.BSN;
+               ret = sizeof(priv->macPIB.BSN);
+               break;
+
+       case macCoordExtendedAddress:
+               *((u64 *)PIBval) = priv->macPIB.CoordExtendedAddress;
+               ret = sizeof(priv->macPIB.CoordExtendedAddress);
+               break;
+
+       case macCoordShortAddress:
+               *((u16 *)PIBval) = priv->macPIB.CoordShortAddress;
+               ret = sizeof(priv->macPIB.CoordShortAddress);
+               break;
+
+       case macDSN:
+               *((u8 *)PIBval) = priv->macPIB.DSN;
+               ret = sizeof(priv->macPIB.DSN);
+               break;
+
+       case macMaxBE:
+               *((u8 *)PIBval) = priv->macPIB.MaxBE;
+               ret = sizeof(priv->macPIB.MaxBE);
+               break;
+
+       case macMaxCSMABackoffs:
+               *((u8 *)PIBval) = priv->macPIB.MaxCSMABackoffs;
+               ret = sizeof(priv->macPIB.MaxCSMABackoffs);
+               break;
+
+       case macMaxFrameTotalWaitTime:
+               *((u16 *)PIBval) = priv->macPIB.MaxFrameTotalWaitTime;
+               ret = sizeof(priv->macPIB.MaxFrameTotalWaitTime);
+               break;
+
+       case macMaxFrameRetries:
+               *((u8 *)PIBval) = priv->macPIB.MaxFrameRetries;
+               ret = sizeof(priv->macPIB.MaxFrameRetries);
+               break;
+
+       case macMinBE:
+               *((u8 *)PIBval) = priv->macPIB.MinBE;
+               ret = sizeof(priv->macPIB.MinBE);
+               break;
+
+       case macPANId:
+               *((u16 *)PIBval) = priv->macPIB.PANId;
+               ret = sizeof(priv->macPIB.PANId);
+               break;
+
+       case macPromiscuousMode:
+               *((u8 *)PIBval) = priv->macPIB.PromiscuousMode;
+               ret = sizeof(priv->macPIB.PromiscuousMode);
+               break;
+
+       case macResponseWaitTime:
+               *((u16 *)PIBval) = priv->macPIB.ResponseWaitTime;
+               ret = sizeof(priv->macPIB.ResponseWaitTime);
+               break;
+
+       case macRxOnWhenIdle:
+               *((u8 *)PIBval) = priv->macPIB.RxOnWhenIdle;
+               ret = sizeof(priv->macPIB.RxOnWhenIdle);
+               break;
+
+       case macSecurityEnabled:
+               *((u8 *)PIBval) = priv->macPIB.SecurityEnabled;
+               ret = sizeof(priv->macPIB.SecurityEnabled);
+               break;
+
+       case macShortAddress:
+               *((u16 *)PIBval) = priv->macPIB.ShortAddress;
+               ret = sizeof(priv->macPIB.ShortAddress);
+               break;
+
+       case macSuperframeOrder:
+               *((u8 *)PIBval) = priv->macPIB.SuperFrameOrder;
+               ret = sizeof(priv->macPIB.SuperFrameOrder);
+               break;
+
+       case macTransactionPersistenceTime:
+               *((u16 *)PIBval) = priv->macPIB.TransactionPersistenceTime;
+               ret = sizeof(priv->macPIB.TransactionPersistenceTime);
+               break;
+
+       default:
+               ret = -EOPNOTSUPP;
+               break;
+       }
+
+       mutex_unlock(&priv->macPIB_lock);
+       return ret;
+}
+
 /*
  * MLME SET REQUEST related functions
  */
-- 
1.7.4.1


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to