mirror of
https://github.com/espressif/openthread.git
synced 2026-10-06 15:57:39 +00:00
Remove Netif name and rely on enumerated Interface Id's for netif. (#833)
* Remove Netif name and rely on enumerated Interface Id's for netif.
This commit is contained in:
@@ -843,6 +843,14 @@ typedef struct otNetifAddress
|
||||
struct otNetifAddress *mNext; ///< A pointer to the next network interface address.
|
||||
} otNetifAddress;
|
||||
|
||||
/**
|
||||
* This enumeration represents the list of allowable values for an InterfaceId.
|
||||
*/
|
||||
typedef enum otNetifInterfaceId
|
||||
{
|
||||
OT_NETIF_INTERFACE_ID_THREAD = 1, ///< The Thread Network interface ID.
|
||||
} otNetifInterfaceId;
|
||||
|
||||
/**
|
||||
* This structure represents data used by Semantically Opaque IID Generator.
|
||||
*
|
||||
|
||||
+1
-1
@@ -1107,7 +1107,7 @@ void Interpreter::ProcessPing(int argc, char *argv[])
|
||||
|
||||
memset(&sMessageInfo, 0, sizeof(sMessageInfo));
|
||||
SuccessOrExit(error = sMessageInfo.GetPeerAddr().FromString(argv[0]));
|
||||
sMessageInfo.mInterfaceId = 1;
|
||||
sMessageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
|
||||
|
||||
sLength = 8;
|
||||
sCount = 1;
|
||||
|
||||
@@ -227,7 +227,7 @@ void Joiner::HandleUdpTransmit(void)
|
||||
messageInfo.GetPeerAddr().mFields.m16[0] = HostSwap16(0xfe80);
|
||||
messageInfo.GetPeerAddr().SetIid(mJoinerRouter);
|
||||
messageInfo.mPeerPort = mJoinerUdpPort;
|
||||
messageInfo.mInterfaceId = 1;
|
||||
messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
|
||||
|
||||
SuccessOrExit(error = mSocket.SendTo(*mTransmitMessage, messageInfo));
|
||||
|
||||
|
||||
+2
-24
@@ -58,8 +58,7 @@ Ip6::Ip6(void):
|
||||
mReceiveIp6DatagramCallback(NULL),
|
||||
mReceiveIp6DatagramCallbackContext(NULL),
|
||||
mIsReceiveIp6FilterEnabled(false),
|
||||
mNetifListHead(NULL),
|
||||
mNextInterfaceId(1)
|
||||
mNetifListHead(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -609,7 +608,7 @@ ThreadError Ip6::AddNetif(Netif &aNetif)
|
||||
|
||||
do
|
||||
{
|
||||
if (netif == &aNetif)
|
||||
if (netif == &aNetif || netif->mInterfaceId == aNetif.mInterfaceId)
|
||||
{
|
||||
ExitNow(error = kThreadError_Already);
|
||||
}
|
||||
@@ -621,11 +620,6 @@ ThreadError Ip6::AddNetif(Netif &aNetif)
|
||||
|
||||
aNetif.mNext = NULL;
|
||||
|
||||
if (aNetif.mInterfaceId < 0)
|
||||
{
|
||||
aNetif.mInterfaceId = mNextInterfaceId++;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
@@ -682,22 +676,6 @@ exit:
|
||||
return netif;
|
||||
}
|
||||
|
||||
Netif *Ip6::GetNetifByName(char *aName)
|
||||
{
|
||||
Netif *netif;
|
||||
|
||||
for (netif = mNetifListHead; netif; netif = netif->mNext)
|
||||
{
|
||||
if (strcmp(netif->GetName(), aName) == 0)
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
return netif;
|
||||
}
|
||||
|
||||
bool Ip6::IsUnicastAddress(const Address &aAddress)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
@@ -282,16 +282,6 @@ public:
|
||||
*/
|
||||
Netif *GetNetifById(int8_t aInterfaceId);
|
||||
|
||||
/**
|
||||
* This method returns the network interface identified by @p aName.
|
||||
*
|
||||
* @param[in] aName A pointer to a NULL-terminated string.
|
||||
*
|
||||
* @returns A pointer to the network interface or NULL if none is found.
|
||||
*
|
||||
*/
|
||||
Netif *GetNetifByName(char *aName);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not @p aAddress is assigned to a network interface.
|
||||
*
|
||||
@@ -363,7 +353,6 @@ private:
|
||||
bool mIsReceiveIp6FilterEnabled;
|
||||
|
||||
Netif *mNetifListHead;
|
||||
int8_t mNextInterfaceId;
|
||||
};
|
||||
|
||||
static inline Ip6 *Ip6FromTaskletScheduler(TaskletScheduler *aTaskletScheduler)
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
namespace Thread {
|
||||
namespace Ip6 {
|
||||
|
||||
Netif::Netif(Ip6 &aIp6):
|
||||
Netif::Netif(Ip6 &aIp6, int8_t aInterfaceId):
|
||||
mIp6(aIp6),
|
||||
mStateChangedTask(aIp6.mTaskletScheduler, &Netif::HandleStateChangedTask, this)
|
||||
{
|
||||
mCallbacks = NULL;
|
||||
mUnicastAddresses = NULL;
|
||||
mMulticastAddresses = NULL;
|
||||
mInterfaceId = -1;
|
||||
mInterfaceId = aInterfaceId;
|
||||
mAllRoutersSubscribed = false;
|
||||
mNext = NULL;
|
||||
mMaskExtUnicastAddresses = 0;
|
||||
|
||||
+3
-10
@@ -233,10 +233,11 @@ public:
|
||||
/**
|
||||
* This constructor initializes the network interface.
|
||||
*
|
||||
* @param[in] aIp6 A reference to the IPv6 network object.
|
||||
* @param[in] aIp6 A reference to the IPv6 network object.
|
||||
* @param[in] aInterfaceId The interface ID for this object.
|
||||
*
|
||||
*/
|
||||
Netif(Ip6 &aIp6);
|
||||
Netif(Ip6 &aIp6, int8_t aInterfaceId);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the IPv6 network object.
|
||||
@@ -418,14 +419,6 @@ public:
|
||||
*/
|
||||
virtual ThreadError SendMessage(Message &aMessage) = 0;
|
||||
|
||||
/**
|
||||
* This virtual method returns a NULL-terminated string that names the network interface.
|
||||
*
|
||||
* @returns A NULL-terminated string that names the network interface.
|
||||
*
|
||||
*/
|
||||
virtual const char *GetName(void) const = 0;
|
||||
|
||||
/**
|
||||
* This virtual method fills out @p aAddress with the link address.
|
||||
*
|
||||
|
||||
@@ -53,10 +53,8 @@ static const uint8_t kThreadMasterKey[] =
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
|
||||
};
|
||||
|
||||
static const char name[] = "thread";
|
||||
|
||||
ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
|
||||
Netif(aIp6),
|
||||
Netif(aIp6, OT_NETIF_INTERFACE_ID_THREAD),
|
||||
mCoapServer(aIp6.mUdp, kCoapUdpPort),
|
||||
mCoapClient(*this),
|
||||
mAddressResolver(*this),
|
||||
@@ -88,11 +86,6 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
|
||||
mKeyManager.SetMasterKey(kThreadMasterKey, sizeof(kThreadMasterKey));
|
||||
}
|
||||
|
||||
const char *ThreadNetif::GetName(void) const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
ThreadError ThreadNetif::Up(void)
|
||||
{
|
||||
if (!mIsUp)
|
||||
|
||||
@@ -116,14 +116,6 @@ public:
|
||||
*/
|
||||
bool IsUp(void) const;
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a NULL-terminated string that names the interface.
|
||||
*
|
||||
* @returns A pointer to a NULL-terminated string that names the interface.
|
||||
*
|
||||
*/
|
||||
const char *GetName(void) const;
|
||||
|
||||
/**
|
||||
* This method retrieves the link address.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user