1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     uds_NetworkDescription.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 26090 $
14  *---------------------------------------------------------------------------*/
15 
16 /*! @file
17     @brief    UDS ネットワーク情報クラスの定義
18 */
19 
20 #ifndef LIBRARIES_UDS_CTR_UDS_NETWORK_DESCRIPTION_H_
21 #define LIBRARIES_UDS_CTR_UDS_NETWORK_DESCRIPTION_H_
22 
23 #include <nn.h>
24 
25 #include <nn/uds/CTR/uds_Type.h>
26 #include <nn/uds/CTR/uds_Result.h>
27 #include <nn/uds/CTR/uds_InfoElement.h>
28 
29 namespace nn {
30 namespace uds {
31 namespace CTR {
32 
33 /*!
34   @name  @ref nn::uds::Scan 関連
35   @{
36 */
37 
38 /*!
39     @class nn::uds::CTR::NetworkDescription
40     @brief @ref nn::uds::CTR::NetworkDescriptionReader から取得出来る、ネットワーク情報を示すクラスです。
41 */
42 class NetworkDescription
43 {
44 
45 public:
46 
47 /*!
48   :private
49   @brief        NetworkDescription の初期化を行います。
50                 通常、アプリは @ref nn::uds::CTR::NetworkDescriptionReader から NetworkDescription を取得するので
51                 Initialize() をする必要はありません。
52 
53   @param[in]    localId   ローカル通信 ID です。
54   @param[in]    subId      アプリが自由に設定可能な通信モード識別用 ID です。
55   @param[in]    maxEntry   ネットワークに接続可能なノードの最大数です。
56   @param[in]    channel    ネットワークが存在するチャンネルです。
57   @return
58 */
59     void Initialize( u32 localId, u8 subId, u8 maxEntry, u8 channel );
60 
61 /*!
62   :private
63   @brief        NetworkDescription の初期化を行います。
64                 通常、アプリは @ref nn::uds::CTR::NetworkDescriptionReader から NetworkDescription を取得するので
65                 Initialize() をする必要はありません。
66 
67   @param[in]    element    ビーコン内に含まれる NetworkDescription IE のペイロードです。
68   @param[in]    channel    ネットワークが存在するチャンネルです。
69   @param[in]    bssid      ネットワークの BSSID (Master の MAC アドレス) です。
70   @return
71 */
72     void Initialize( const detail::NetworkDescriptionElement* element, u8 channel, const bit8 bssid[MAC_ADDRESS_SIZE]);
73 
74 /*!
75   :private
76   @brief        NetworkDescription の終了処理を行います。
77                 不正なビーコンを検知した際に実行されます。
78   @return
79 */
Finalize()80     void Finalize() { m_IsInitialized = false; std::memset(m_Bssid, 0x00, MAC_ADDRESS_SIZE); }
81 
GetBssid()82     const bit8* GetBssid() const{ return m_Bssid; }                                                             //!< BSSID (Master の MAC アドレス)を取得します。
GetGameId()83     u32         GetGameId() const {return this->GetLocalCommunicationId(); }                  //!< ローカル通信 ID を取得します。本関数は @ref GetLocalCommunicationId 関数と同一で互換性維持のために残されている API です。
GetLocalCommunicationId()84     u32         GetLocalCommunicationId() const {return m_IsInitialized? detail::UDS_BE2LE32(m_Element.gameId):0; }                  //!< ローカル通信 ID を取得します。 @ref Scan で指定した値と同一になります。
GetSubId()85     u8          GetSubId() const {return m_IsInitialized? m_Element.subId:0; }                                 //!< SubId を取得します。
GetTemporaryId()86     u32         GetTemporaryId() const {return m_IsInitialized? detail::UDS_BE2LE32(m_Element.temporaryId):0; }        //!< TemporaryId を取得します。ネットワークの識別に利用できますが、BSSID もしくは Master の NodeInformation の使用を推奨します。
GetChannel()87     u16         GetChannel() const { return m_IsInitialized? m_Channel:0; }                                    //!< 通信に使用しているチャンネルを取得します。通常参照する必要はありません。
GetNowEntry()88     u8          GetNowEntry() const { return m_IsInitialized? m_Element.nowEntry:0 ; }                          //!< 現在の接続台数を取得します。
GetMaxEntry()89     u8          GetMaxEntry() const { return m_IsInitialized? m_Element.maxEntry:0 ; }                          //!< 最大接続台数を取得します。
90     size_t      GetApplicationData(bit8* buffer, const size_t bufferSize) const;            //!< SetApplicationDataToBeacon() でセットしたデータを取得します。
CanConnectAsSpectator()91     bool        CanConnectAsSpectator() const { return m_IsInitialized? !(m_Element.attribute & detail::EJECT_SPECTAOTR_FLAG):false ; }  //!<Spectator としての接続が許可されているかをチェックします。
92 
93 /*!
94   @brief        NetworkDescriptionクラスのオブジェクトを比較し、同値であればtrueを返します。
95                     同じネットワークでも接続台数やSetApplicationDataによりデータがセットされるとfalseになります。
96   @param[in]   networkDescription 比較するNetworkDescriptionクラスのオブジェクト
97 */
98     bool         operator==(NetworkDescription networkDescription);
99 /*!
100   @brief        NetworkDescriptionクラスのオブジェクトを比較し、同値でなければtrueを返します。
101                     同じネットワークでも接続台数やSetApplicationDataによりデータがセットされるとtrueになります。
102   @param[in]   networkDescription 比較するNetworkDescriptionクラスのオブジェクト
103 */
104     bool         operator!=(NetworkDescription networkDescription);
105 
106 private:
107     bit8        m_Bssid[MAC_ADDRESS_SIZE];        //!< BSSID
108     u16         m_Channel;      //!< チャンネル (0:Auto)
109     bool        m_IsInitialized;
110     NN_PADDING3;
111     detail::NetworkDescriptionElement m_Element;  //!< システムの都合上ネットワークバイトオーダーとなっていることに注意
112 
113 };
114 /*!
115   @}
116 */
117 } // end of namespace CTR
118 } // end of namespace uds
119 } // end of namespace nn
120 
121 #endif /* LIBRARIES_UDS_CTR_UDS_NETWORK_DESCRIPTION_H_ */
122