View | Details | Raw Unified | Return to bug 1879
Collapse All | Expand All

(-)a/src/lr-wpan/model/lr-wpan-capability-information.cc (+201 lines)
Line 0    Link Here 
1
2
#include "lr-wpan-capability-information.h"
3
4
namespace ns3 {
5
6
//NS_OBJECT_ENSURE_REGISTERED (LrWpanCapabilityInformation);
7
8
9
LrWpanCapabilityInformation::LrWpanCapabilityInformation ()
10
{
11
	SetNoAltrPanCoord ();			// Assume the device can't become a PAN coordinator
12
	SetNoFfdDevType ();				// Assume the Device is RFD
13
	SetNoPwrSrc ();					// Assume the device don't receive power from the alternating current mains
14
	SetRcvOnWhenIdleDisable ();		// Assume the receiver is disable during idle periods
15
	SetCapRes (0);					// Initialize the 2reserved bits to 0
16
	SetNoSecCap ();					// Assume the device isn't capable of sending or receiving protected MAC frames
17
	SetNoAllocAddr ();				// Allocate a 64-bit extended address
18
19
};
20
21
LrWpanCapabilityInformation::~LrWpanCapabilityInformation ()
22
{
23
}
24
25
26
uint16_t LrWpanCapabilityInformation::GetCapability (void) const
27
{
28
  uint16_t val;
29
  val = m_capInfAltPanCoord & 0x01;					// Bit 0
30
  val |= (m_capInfDevType << 1) & (0x01 << 1);			// Bit 1
31
  val |= (m_capInfPwrSrc<< 2) & (0x01 << 2);			// Bit 2
32
  val |= (m_capInfRcvOnWhenIdle << 3) & (0x01 << 3);	// Bit 3
33
  val |= (m_capInfReserved << 4) & (0x03 << 3);				// Bit 4-5
34
  val |= (m_capInfSecCap << 6) & (0x01 << 6);	// Bit 6
35
  val |= (m_capInfAllocAddr << 7) & (0x01 << 7);		// Bit 7
36
  return val;
37
}
38
39
bool
40
LrWpanCapabilityInformation::IsAltrPanCoord (void) const
41
{
42
	return (m_capInfAltPanCoord == 1);
43
}
44
45
bool
46
LrWpanCapabilityInformation::IsNoAltrPanCoord (void) const
47
{
48
	return (m_capInfAltPanCoord == 0);
49
}
50
51
bool
52
LrWpanCapabilityInformation::IsFfdDevType (void) const
53
{
54
	return (m_capInfDevType == 1);
55
}
56
57
bool
58
LrWpanCapabilityInformation::IsNoFfdDevType (void) const
59
{
60
	return (m_capInfDevType == 0);
61
}
62
63
bool
64
LrWpanCapabilityInformation::IsPwrSrc (void) const
65
{
66
	return (m_capInfPwrSrc == 1);
67
}
68
69
bool
70
LrWpanCapabilityInformation::IsNoPwrSrc (void) const
71
{
72
	return (m_capInfPwrSrc == 0);
73
}
74
75
bool
76
LrWpanCapabilityInformation::IsRcvOnWhenIdleEnable (void) const
77
{
78
	return (m_capInfRcvOnWhenIdle == 1);
79
}
80
81
bool
82
LrWpanCapabilityInformation::IsRcvOnWhenIdleDisable (void) const
83
{
84
	return (m_capInfRcvOnWhenIdle == 0);
85
}
86
87
bool
88
LrWpanCapabilityInformation::IsSecCap (void) const
89
{
90
	return (m_capInfSecCap == 1);
91
}
92
93
bool
94
LrWpanCapabilityInformation::IsNoSecCap (void) const
95
{
96
	return (m_capInfSecCap == 0);
97
}
98
99
bool
100
LrWpanCapabilityInformation::IsAllocAddr (void) const
101
{
102
	return (m_capInfAllocAddr == 1);
103
}
104
105
bool
106
LrWpanCapabilityInformation::IsNoAllocAddr (void) const
107
{
108
	return (m_capInfAllocAddr == 0);
109
}
110
111
void
112
LrWpanCapabilityInformation::SetCapability (uint16_t Capability)
113
{
114
	m_capInfAltPanCoord = Capability & 0x01;				// Bit 0
115
	m_capInfDevType |= (Capability >> 1) & (0x01);			// Bit 1
116
	m_capInfPwrSrc |= (Capability >> 2) & (0x01);			// Bit 2
117
	m_capInfRcvOnWhenIdle |= (Capability >> 3) & (0x01);	// Bit 3
118
	m_capInfReserved |= (Capability >> 4) & (0x03);			// Bit 4-5
119
	m_capInfSecCap |= (Capability >> 6) & (0x01);			// Bit 6
120
	m_capInfAllocAddr |= (Capability >> 7) & (0x01);		// Bit 7
121
}
122
123
void
124
LrWpanCapabilityInformation::SetAltrPanCoord (void)
125
{
126
	m_capInfAltPanCoord = 1;
127
}
128
129
void
130
LrWpanCapabilityInformation::SetNoAltrPanCoord (void)
131
{
132
	m_capInfAltPanCoord = 0;
133
}
134
135
void
136
LrWpanCapabilityInformation::SetFfdDevType (void)
137
{
138
	m_capInfDevType = 1;
139
}
140
141
void
142
LrWpanCapabilityInformation::SetNoFfdDevType (void)
143
{
144
	m_capInfDevType = 0;
145
}
146
147
void
148
LrWpanCapabilityInformation::SetPwrSrc (void)
149
{
150
	m_capInfPwrSrc = 1;
151
}
152
153
void
154
LrWpanCapabilityInformation::SetNoPwrSrc (void)
155
{
156
	m_capInfPwrSrc = 0;
157
}
158
159
void
160
LrWpanCapabilityInformation::SetRcvOnWhenIdleEnable (void)
161
{
162
	m_capInfRcvOnWhenIdle = 1;
163
}
164
165
void
166
LrWpanCapabilityInformation::SetRcvOnWhenIdleDisable (void)
167
{
168
	m_capInfRcvOnWhenIdle = 0;
169
}
170
171
void
172
LrWpanCapabilityInformation::SetCapRes (uint8_t res)
173
{
174
	m_capInfReserved = res;
175
}
176
177
void
178
LrWpanCapabilityInformation::SetSecCap (void)
179
{
180
	m_capInfSecCap = 1;
181
}
182
183
void
184
LrWpanCapabilityInformation::SetNoSecCap (void)
185
{
186
	m_capInfSecCap = 0;
187
}
188
189
void
190
LrWpanCapabilityInformation::SetAllocAddr (void)
191
{
192
	m_capInfAllocAddr = 1;
193
}
194
195
void
196
LrWpanCapabilityInformation::SetNoAllocAddr (void)
197
{
198
	m_capInfAllocAddr = 0;
199
}
200
201
} // namespace ns3
(-)a/src/lr-wpan/model/lr-wpan-capability-information.h (+70 lines)
Line 0    Link Here 
1
#ifndef LR_WPAN_CAPABILITY_INFORMATION_H
2
#define LR_WPAN_CAPABILITY_INFORMATION_H
3
4
#include <stdint.h>
5
#include <iostream>
6
7
namespace ns3 {
8
9
class Packet;
10
11
/*
12
 * \ingroup lr-wpan
13
 * Represent the Capability Information
14
 */
15
class LrWpanCapabilityInformation
16
{
17
public:
18
19
  LrWpanCapabilityInformation (void);
20
  ~LrWpanCapabilityInformation (void);
21
22
  uint16_t GetCapability(void) const;
23
  bool IsAltrPanCoord (void) const;
24
  bool IsNoAltrPanCoord (void) const;
25
  bool IsFfdDevType (void) const;
26
  bool IsNoFfdDevType (void) const;
27
  bool IsPwrSrc (void) const;
28
  bool IsNoPwrSrc (void) const;
29
  bool IsRcvOnWhenIdleEnable (void) const;
30
  bool IsRcvOnWhenIdleDisable (void) const;
31
  bool IsSecCap (void) const;
32
  bool IsNoSecCap (void) const;
33
  bool IsAllocAddr (void) const;
34
  bool IsNoAllocAddr (void) const;
35
36
  void SetCapability (uint16_t Capability);
37
  void SetAltrPanCoord (void);
38
  void SetNoAltrPanCoord (void);
39
  void SetFfdDevType (void);
40
  void SetNoFfdDevType (void);
41
  void SetPwrSrc (void);
42
  void SetNoPwrSrc (void);
43
  void SetRcvOnWhenIdleEnable (void);
44
  void SetRcvOnWhenIdleDisable (void);
45
  void SetCapRes (uint8_t res);
46
  void SetSecCap (void);
47
  void SetNoSecCap (void);
48
  void SetAllocAddr (void);
49
  void SetNoAllocAddr (void);
50
51
  std::string GetName(void) const;
52
  void PrintCapabilityInformation (std::ostream &os) const;
53
  void Print (std::ostream &os) const;
54
  //void Serialize (Buffer::Iterator start) const;
55
  //uint32_t Deserialize (Buffer::Iterator start);
56
57
private:
58
  /* Capability Information 1 Octet */
59
  /* Capability Information fields */
60
  uint8_t m_capInfAltPanCoord;          // Bit 0    = 0 - Not capable of becoming the PAN coordinator, 1 - Capable of becoming the PAN coordinator
61
  uint8_t m_capInfDevType;              // Bit 1    = 0 - RFD Device,  1 - FFD Device
62
  uint8_t m_capInfPwrSrc;               // Bit 2	= 0 - No receiving power from the alternating current mains, 1- receiving power from the alternating current mains
63
  uint8_t m_capInfRcvOnWhenIdle;        // Bit 3	= 0 - Disable receiver during idle periods, 1 - Enable receiver during idle periods
64
  uint8_t m_capInfReserved;             // Bit 4-5
65
  uint8_t m_capInfSecCap;	            // Bit 6    = 0 - No sending and receiving cryptographically protected MAC frames, 1 - Can sending and receiving cryptographically protected MAC frames
66
  uint8_t m_capInfAllocAddr;            // Bit 7    = 0 - No 16-bit short address, 1 - 16-bit short address
67
68
}; // LrWpanCapabilityInformation
69
}; // namespace ns-3
70
#endif /* LR_WPAN_CAPABILITY_INFORMATION_H */
(-)a/src/lr-wpan/model/lr-wpan-mac.cc (+78 lines)
 Lines 26-31    Link Here 
26
#include "lr-wpan-csmaca.h"
26
#include "lr-wpan-csmaca.h"
27
#include "lr-wpan-mac-header.h"
27
#include "lr-wpan-mac-header.h"
28
#include "lr-wpan-mac-trailer.h"
28
#include "lr-wpan-mac-trailer.h"
29
#include "lr-wpan-capability-information.h"
29
#include <ns3/simulator.h>
30
#include <ns3/simulator.h>
30
#include <ns3/log.h>
31
#include <ns3/log.h>
31
#include <ns3/uinteger.h>
32
#include <ns3/uinteger.h>
 Lines 203-208    Link Here 
203
  NS_LOG_FUNCTION (this);
204
  NS_LOG_FUNCTION (this);
204
  return m_selfExt;
205
  return m_selfExt;
205
}
206
}
207
208
void
209
LrWpanMac::MlmeAssociateRequest (MlmeAssociateRequestParams params, Ptr<Packet> p)
210
{
211
  NS_LOG_FUNCTION (this << p);
212
213
  //Create a MAC Header
214
  //Type: Command Frame
215
  LrWpanMacHeader macHdr (LrWpanMacHeader::LRWPAN_MAC_COMMAND, (uint8_t)m_macDsn.GetValue ());
216
217
  //Create a Capability Information Header
218
  LrWpanCapabilityInformation capInf;
219
220
  m_macDsn++;
221
  if (m_macDsn > SequenceNumber16 (255))
222
    {
223
	  m_macDsn = m_macDsn - SequenceNumber16 (255);
224
    }
225
226
  if (params.m_coordAddrMode != SHORT_ADDR || params.m_coordAddrMode != EXT_ADDR)
227
    {
228
	  NS_LOG_ERROR (this << " Invalid Address field" );
229
      return;
230
    }
231
   SetPanId(params.m_coordPanId);
232
  //extract the last 4 bits in Capability Information Field and map to macHdr
233
  // Section 7.3.1.2; Figure 56
234
  int b0 = params.m_capability & CAPABILITY_ALTERNATE_PAN_COORD;
235
  int b1 = params.m_capability & CAPABILITY_DEVICE_TYPE;
236
  int b2 = params.m_capability & CAPABILITY_POWER_SOURCE;
237
  int b3 = params.m_capability & CAPABILITY_RECEIVER_ON_WHEN_IDLE;
238
239
  // TODO: The Alternate PAN Coordinator is set to 1 if the device is capable of becoming the PAN coordinator
240
  //        else the Alternate PAN Coordinator subfield shall be set to zero.
241
  if (b0 == CAPABILITY_ALTERNATE_PAN_COORD)
242
    {
243
	  capInf.SetAltrPanCoord();
244
    }
245
  else if(b0 == 0)
246
    {
247
	  capInf.SetNoAltrPanCoord();
248
    }
249
  // TODO: The Device Type is set to 1 if the device is an FFD
250
  //        else the Device type is set be zero to indicate an RFD
251
  if (b1 == CAPABILITY_DEVICE_TYPE)
252
    {
253
	  capInf.SetFfdDevType();
254
    }
255
  else if (b1 == 0)
256
    {
257
	  capInf.SetNoFfdDevType();
258
    }
259
  // TODO: The Power Source is set to 1 if the device is receiving power from the alternating current mains
260
  //        else the Power Source is set to zero
261
  if (b2 == CAPABILITY_POWER_SOURCE)
262
    {
263
	  capInf.SetPwrSrc();
264
    }
265
  else if (b2 == 0)
266
    {
267
	  capInf.SetNoPwrSrc();
268
    }
269
  //TODO: The Receiver On When Idle subfield is set to 1 if the device does not disable its receiver
270
  //      to conserve power during idle periods
271
  //      else the receiver subfield is set to 0
272
  if (b3 == CAPABILITY_RECEIVER_ON_WHEN_IDLE)
273
    {
274
	  capInf.SetRcvOnWhenIdleEnable();
275
    }
276
  else if (b3 == 0)
277
  	{
278
	  capInf.SetRcvOnWhenIdleDisable();
279
  	}
280
281
}
282
206
void
283
void
207
LrWpanMac::McpsDataRequest (McpsDataRequestParams params, Ptr<Packet> p)
284
LrWpanMac::McpsDataRequest (McpsDataRequestParams params, Ptr<Packet> p)
208
{
285
{
 Lines 980-983    Link Here 
980
  m_macMaxFrameRetries = retries;
1057
  m_macMaxFrameRetries = retries;
981
}
1058
}
982
1059
1060
983
} // namespace ns3
1061
} // namespace ns3
(-)a/src/lr-wpan/model/lr-wpan-mac.h (-1 / +33 lines)
 Lines 104-109    Link Here 
104
  IEEE_802_15_4_INVALID_PARAMETER      = 11
104
  IEEE_802_15_4_INVALID_PARAMETER      = 11
105
} LrWpanMcpsDataConfirmStatus;
105
} LrWpanMcpsDataConfirmStatus;
106
106
107
typedef enum
108
{
109
  CAPABILITY_ALTERNATE_PAN_COORD   = 0,  //alternate PAN coordinator
110
  CAPABILITY_DEVICE_TYPE           = 1,  //device type (1=FFD,0=RFD)
111
  CAPABILITY_POWER_SOURCE 		   = 2,  //power source (1=mains powered,0=non mains powered)
112
  CAPABILITY_RECEIVER_ON_WHEN_IDLE = 3,  //receiver on when idle
113
  CAPABILITY_RESERVED 			   = 4,  //reserved
114
  CAPABILITY_SECURITY_CAPABILITY   = 6,  //security capability
115
  CAPABILITY_ALLOCATE_ADDRESS      = 7  //allocate address (asking for allocation of a short address during association)
116
} LrWpanCapabilityInformationOption;
117
107
struct McpsDataRequestParams
118
struct McpsDataRequestParams
108
{
119
{
109
  McpsDataRequestParams () :
120
  McpsDataRequestParams () :
 Lines 118-123    Link Here 
118
  uint8_t m_txOptions;  // bitmap
129
  uint8_t m_txOptions;  // bitmap
119
};
130
};
120
131
132
struct MlmeAssociateRequestParams
133
{
134
  MlmeAssociateRequestParams () :
135
    m_coordAddrMode (SHORT_ADDR), m_coordPanId (0),m_coordAddr (),
136
    m_capability (0)
137
  { };
138
  LrWpanAddressMode m_coordAddrMode;
139
  uint16_t m_coordPanId;
140
  Mac16Address m_coordAddr;
141
  uint8_t m_capability;  // bitmap
142
};
143
121
struct McpsDataConfirmParams
144
struct McpsDataConfirmParams
122
{
145
{
123
  uint8_t m_msduHandle;
146
  uint8_t m_msduHandle;
 Lines 257-263    Link Here 
257
   */
280
   */
258
  void PlmeSetAttributeConfirm (LrWpanPhyEnumeration status,
281
  void PlmeSetAttributeConfirm (LrWpanPhyEnumeration status,
259
                                LrWpanPibAttributeIdentifier id);
282
                                LrWpanPibAttributeIdentifier id);
260
283
  /**
284
     *  Added By Abdelwahed
285
     *  IEEE 802.15.4-2006 section 7.1.3.1
286
     *  PLME-GET.confirm
287
     *  MLME-ASSOCIATE.request
288
     *  Set attributes per definition from Table 47 in section 7.1.3.1.1
289
     * @param p the packet to send
290
     */
291
  void MlmeAssociateRequest (MlmeAssociateRequestParams params, Ptr<Packet> p);
261
292
262
  /**
293
  /**
263
   * CSMA-CA algorithm calls back the MAC after executing channel assessment
294
   * CSMA-CA algorithm calls back the MAC after executing channel assessment
 Lines 293-298    Link Here 
293
  uint8_t GetMacMaxFrameRetries (void) const;
324
  uint8_t GetMacMaxFrameRetries (void) const;
294
  void SetMacMaxFrameRetries (uint8_t retries);
325
  void SetMacMaxFrameRetries (uint8_t retries);
295
326
327
296
protected:
328
protected:
297
  virtual void DoInitialize (void);
329
  virtual void DoInitialize (void);
298
  virtual void DoDispose (void);
330
  virtual void DoDispose (void);
(-)a/src/lr-wpan/wscript (+2 lines)
 Lines 13-18    Link Here 
13
        'model/lr-wpan-spectrum-value-helper.cc',
13
        'model/lr-wpan-spectrum-value-helper.cc',
14
        'model/lr-wpan-spectrum-signal-parameters.cc',
14
        'model/lr-wpan-spectrum-signal-parameters.cc',
15
        'model/lr-wpan-lqi-tag.cc',
15
        'model/lr-wpan-lqi-tag.cc',
16
        'model/lr-wpan-capability-information.cc',
16
        'helper/lr-wpan-helper.cc',
17
        'helper/lr-wpan-helper.cc',
17
        ]
18
        ]
18
19
 Lines 37-42    Link Here 
37
        'model/lr-wpan-spectrum-value-helper.h',
38
        'model/lr-wpan-spectrum-value-helper.h',
38
        'model/lr-wpan-spectrum-signal-parameters.h',
39
        'model/lr-wpan-spectrum-signal-parameters.h',
39
        'model/lr-wpan-lqi-tag.h',
40
        'model/lr-wpan-lqi-tag.h',
41
        'model/lr-wpan-capability-information.h',
40
        'helper/lr-wpan-helper.h',
42
        'helper/lr-wpan-helper.h',
41
        ]
43
        ]
42
44

Return to bug 1879