1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: cec_MessageBox.h 4 5 Copyright 2009 Nintendo. 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 $Date:: 2010-09-27#$ 14 $Rev: 26754 $ 15 $Author: sato_yoshinobu $ 16 *---------------------------------------------------------------------------*/ 17 #ifndef __MESSAGE_BOX_H__ 18 #define __MESSAGE_BOX_H__ 19 20 #define MESSAGE_BOX_NUM_MAX (36) 21 #define CEC_OUTBOX_MESS_NUM_MAX (64) 22 #define CEC_MAX_MESSAGE_NUM (64) 23 24 /* 25 CEC/ 26 | 27 +-- MessageBoxList 28 \-- Message_BOX1/ 29 | | 30 | +-- MessageBoxInfo 31 | \-- InBox/ 32 | | | 33 | | +-- InBoxInfo 34 | | +-- Message1 35 | | 36 | \-- OutBox/ 37 | | 38 | +-- OutBoxIndex 39 | +-- OutBoxInfo 40 | +-- Message2 41 | 42 \-- Message_BOX2/ 43 | 44 45 */ 46 47 #define CEC_INBOX_SIZE_DEFAULT (512*1024) //! 受信Box サイズ初期値 48 #define CEC_OUTBOX_SIZE_DEFAULT (512*1024) //! 送信Box サイズ初期値 49 #define CEC_INBOX_MESSNUM_DEFAULT (99) 50 #define CEC_OUTBOX_MESSNUM_DEFAULT (99) 51 #define CEC_MESSSIZEMAX_DEFAULT (100*1024) 52 53 #define CEC_BOX_DATA_SIZE_MAX (10*1024) 54 55 #define CEC_BOXNUMMAX_APPLICATION (12) // 一般アプリケーション用 Box 最大数 56 #define CEC_BOXNUMMAX_SYSTEM (12) // System アプリケーション用 Box 最大数 57 #define CEC_BOXNUMMAX_SYSTEM2 (6) // System アプリケーション その2 用 Box 最大数 58 59 #define CEC_BOXDIR_NAMELEN_MAX (16) 60 61 #include <nn/cec/CTR/cec_Api.h> 62 namespace nn { 63 namespace cec { 64 namespace CTR { 65 //! @name MessageBoxFlag 66 //@{ 67 /*! 68 * @typedef MessageBoxFlag 69 * @brief MessageBox の属性を示すフラグです。 70 */ 71 typedef bit8 MessageBoxFlag; 72 /*! @brief 一般アプリケーション用<br>デフォルトでこの値が指定されています。 */ 73 static const bit8 MESSAGE_BOX_FLAG_APPLICATION = (0x1); 74 /* @brief System アプリケーション用 */ 75 static const bit8 MESSAGE_BOX_FLAG_SYSTEM = (0x2); 76 /* @brief System アプリケーション用 その2 */ 77 static const bit8 MESSAGE_BOX_FLAG_SYSTEM2 = (0x4); 78 /* @brief 接続時にBOXの存在を通知しない */ 79 static const bit8 MESSAGE_BOX_FLAG_HIDDEN = (0x80); 80 81 //@} 82 83 84 /*! 85 * @enum CecBoxType 86 * @brief 受信BOX/ 送信BOX の種別 87 */ 88 enum CecBoxType 89 { 90 CEC_BOXTYPE_INBOX = (0x0), //!< 受信BOX 91 CEC_BOXTYPE_OUTBOX = (0x1) //!< 送信BOX 92 }; 93 94 95 // 構造体 96 #define MESSAGEBOXLIST_MAGIC 0x6868 97 #define CEC_BOX_VERSION 0x00000001 98 struct MessageBoxList 99 { 100 u16 magic16; 101 NN_PADDING2; 102 u32 CecBoxVersion; 103 u32 DirNum; 104 u8 DirName[MESSAGE_BOX_NUM_MAX][CEC_BOXDIR_NAMELEN_MAX]; 105 }; 106 107 //ローカル管理用メッセージリスト 108 #define MESSAGEBOXINFO_MAGIC 0x6363 109 struct MessageBoxInfo 110 { 111 u16 magic16; 112 NN_PADDING2; 113 u32 cecTitleId; // Title固有ID 114 u32 privateId; // アプリがつける固有ID。アクセスする為のキーとなる。 115 MessageBoxFlag MessageBoxInfoFlag; // MessageBoxInfoのフラグ(Systemなど) 116 bool isActive; 117 NN_PADDING2; 118 char hmacKey[MESSAGE_HMAC_KEYLEN]; // HMACで署名を付けるときに使用するKey 119 u32 MessageBoxInfoSize; // MessageBoxInfoのサイズ(Byte) 120 nn::fnd::DateTimeParameters lastOpened; // アクセス時の時刻を記録 121 u8 reserved[32]; // reserved (名称・iconなどは別ファイルに書く) 122 }; 123 124 125 // 送信/受信 ボックス情報ファイル データ構造 126 127 /* 128 File : InBoxInfo/OutBoxInfo 129 +----------------------+ 130 | CEC Box Info Header | 131 +----------------------+ -+ 132 | CEC Message Header1 | | 133 +----------------------+ | CecMessageHeader_List 134 | CEC Message Header2 | | 135 +----------------------+ | 136 | CEC Message Header3 | | 137 +----------------------+ | 138 | .......... | | 139 | | | 140 +----------------------+ -+ 141 */ 142 143 144 //typedef std::vector<struct CecMessageHeader> CecMessageHeader_List; // MessageHeader のリストの配列定義 145 //typedef nn::fnd::IntrusiveLinkedList<struct CecMessageHeader> CecMessageHeader_List; // MessageHeader のリスト 146 147 #define CEC_BOXINFO_MAGIC 0x6262 148 #define CEC_SIZEOF_BOXINFO_HEADER (sizeof(struct CecBoxInfoHeader)) 149 struct CecBoxInfoHeader 150 { 151 u16 magic16; 152 NN_PADDING2; 153 u32 boxInfoSize; // BoxInfoのサイズ 154 u32 boxSizeMax; // MessageBoxのサイズ(Byte)最大値 155 u32 boxSize; // MessageBoxのサイズ(使用量)(Byte) 156 u32 messNumMax; // ボックスに格納可能な message数 の最大値 157 u32 messNum; // ボックスに格納されているmessage数 158 u32 groupNumMax; // ボックスに格納可能な Message Group 数 の最大値 159 u32 messSizeMax; // 1つのMessageの最大サイズ 160 }; 161 162 163 // 送信ボックス Index ファイル (送信順を示す) 164 #define CEC_OUTBOXINDEX_MAGIC 0x6767 165 struct CecOutBoxIndexHeader 166 { 167 u16 magic16; 168 NN_PADDING2; 169 size_t messageNum; // Message の 個数 170 }; 171 172 /* 173 struct CecOutBoxindex : public nn::fnd::IntrusiveLinkedList<CecOutBoxindex>::Item 174 { 175 CECMessageId messageId; 176 }; 177 178 //typedef std::vector<CecOutBoxindex> MessageId_List; // MessageId のリストの配列定義 179 typedef nn::fnd::IntrusiveLinkedList<CecOutBoxindex> MessageId_List; 180 */ 181 182 183 /* 184 // ボックス内のMessageのMessageIDのリスト 185 struct CecBoxMessageList 186 { 187 u32 messageNum; 188 CECMessageId messageId[CEC_OUTBOX_MESS_NUM_MAX]; 189 }; 190 */ 191 192 193 /*! 194 @brief CEC MessageBox にアクセスするためのクラスです。 195 196 */ 197 198 class MessageBox 199 { 200 protected: 201 u32 currentCecTitleId; 202 203 bool m_Initialized; 204 NN_PADDING3; 205 206 u8* cecBoxBuf; 207 208 struct MessageBoxList cecMessageBoxList; 209 struct MessageBoxInfo cecMessageBoxInfo; 210 211 struct CecBoxInfoHeader cecInboxInfo; 212 CecMessageHeader* cecInboxInfo_body[CEC_INBOX_MESSNUM_DEFAULT]; 213 u8* cecInboxInfoBuf; 214 struct CecBoxInfoHeader cecOutboxInfo; 215 CecMessageHeader* cecOutboxInfo_body[CEC_OUTBOX_MESSNUM_DEFAULT]; 216 u8* cecOutboxInfoBuf; 217 218 CecOutBoxIndexHeader cecOutboxIndex_header; 219 //u8* cecOutboxIndex[CEC_OUTBOX_MESSNUM_DEFAULT]; 220 CECMessageId cecOutboxIndex[CEC_OUTBOX_MESSNUM_DEFAULT]; 221 // u8* cecOutboxIndexBuf; 222 223 bool m_BoxAccessible; 224 NN_PADDING3; 225 226 public: 227 228 MessageBox(bool NoInitialize = false); 229 virtual ~MessageBox(); 230 231 nn::Result Initialize(); 232 nn::Result Finalize(); 233 234 nn::Result WriteMessageBoxList(); 235 size_t ReadMessageBoxList(); 236 size_t ReadMessageBoxList(void* bufOut, size_t size); 237 238 u32 GetMessageBoxNum(MessageBoxFlag flag); 239 nn::Result DeleteOldestMessageBox(MessageBoxFlag flag); 240 GetCurrentCecTitleId()241 inline u32 GetCurrentCecTitleId() const{return currentCecTitleId;} 242 243 244 //! @name Boxの作成/削除 245 //@{ 246 247 /*! 248 @brief MessageBoxを作成します。Box内に 受信BOX と 送信BOX が作成されます。<br> 249 送信BOX に Message をセットすることで、すれちがい通信時にデータ送信が行われ、受信BOXに相手からのデータが保持されます。 250 251 MessageBoxは、NAND領域に作成されます。1アプリにつき、作成できるBOXは1つです。BOXの最大数は12で、これを超える場合は新規にBOXを作成することはできません。<br> 252 253 privateId, hmacKey はアクセス可能な範囲を制限する為の値です。<br> 254 privateId はBOXをOpenするために必要なキーで、1本体内に閉じられた値を想定しています。<br> 255 hmacKey は同一アプリが共通して持つキーで、データの改竄・アプリの偽装を防ぐ目的にも使用されます。このキーはBOXに保持されます。<br> 256 複数セーブデータ・複数アプリから同一のBOXにアクセスする必要がある場合は、適切な範囲で共通するキーを設定してください。 257 258 259 @param[in] cecTitleId Title固有ID 260 @param[in] privateId BOXをOpenするために必要なキーとなります。→ @ref OpenMessageBox <br> 261 BOXにアクセスするアプリが保持している値を使用する必要があります。 262 263 @param[in] hmacKey Message を読み出すときに必要なキーを指定します。32文字の文字列で指定します。 264 通信相手と共通のキーである必要があります。<br> 265 この値は、送受信されるデータの改竄をチェックするために使用されます。送受信されるデータには、このキーを使用して生成された署名が付けられます。 266 アプリ内で保持している値を使用してください。 267 268 @param[in] icon アイコンを指定します。<br> 269 フォーマット: RGB565 (リトルエンディアン)<br> 270 サイズ: 48×48 (4.5KBytes) <br> 271 @param[in] iconSize アイコンのデータサイズを指定します。 272 @param[in] name アプリ名称を指定します。<br> 273 文字コード: UTF16-LE<br> 274 表示サイズ: 全角17文字で表示できる文字数<br> 275 バッファ最大: 64×2Bytes (NULL終端込み)<br> 276 @param[in] nameSize アプリ名称のデータサイズを指定します。 277 @param[in] inboxSizeMax 受信ボックスの最大保存サイズを指定します。受信BOXと送信BOXで合わせて 1MB 以内にする必要があります。デフォルトは 512*1024 バイトです。 278 @param[in] outboxSizeMax 送信ボックスの最大保存サイズを指定します。受信BOXと送信BOXで合わせて 1MB 以内にする必要があります。デフォルトは 512*1024 バイトです。 279 @param[in] inboxMessNumMax 受信ボックスの最大保存Message数を指定します。デフォルトは 99 で、この値より多い値を指定することはできません。 280 @param[in] outboxMessNumMax 送信ボックスの最大保存Message数を指定します。デフォルトは 99 で、この値より多い値を指定することはできません。 281 @param[in] messageSizeMax Messageの最大サイズを指定します。このサイズを超えるMessageは保存できず、WriteMessage でエラーとなります。 282 @return nn::Result 283 */ 284 nn::Result CreateMessageBox( 285 const TitleId cecTitleId, const u32 privateId, 286 const char* hmacKey, 287 void* icon, size_t iconSize, 288 wchar_t* name, size_t nameSize, 289 size_t inboxSizeMax = CEC_INBOX_SIZE_DEFAULT, 290 size_t outboxSizeMax = CEC_OUTBOX_SIZE_DEFAULT, 291 size_t inboxMessNumMax = CEC_INBOX_MESSNUM_DEFAULT, 292 size_t outboxMessNumMax = CEC_OUTBOX_MESSNUM_DEFAULT, 293 size_t messageSizeMax = CEC_MESSSIZEMAX_DEFAULT 294 ); 295 296 /*! 297 @brief MessageBoxを作成します。Box内に 受信BOX と 送信BOX が作成されます。<br> 298 299 (最終バージョンでは、アイコンとアプリ名称の設定が必須になります。この形式は過去のバージョンとの互換性のために残されています。) 300 301 @param[in] cecTitleId Title固有ID 302 @param[in] privateId BOXをOpenするために必要なキーとなります。→ @ref OpenMessageBox <br> 303 BOXにアクセスするアプリが保持している値を使用する必要があります。 304 305 @param[in] hmacKey Message を読み出すときに必要なキーを指定します。32文字の文字列で指定します。 306 通信相手と共通のキーである必要があります。<br> 307 この値は、送受信されるデータの改竄をチェックするために使用されます。送受信されるデータには、このキーを使用して生成された署名が付けられます。 308 アプリ内で保持している値を使用してください。 309 310 @param[in] inboxSizeMax 受信ボックスの最大保存サイズを指定します。受信BOXと送信BOXで合わせて 1MB 以内にする必要があります。デフォルトは 512*1024 バイトです。 311 @param[in] outboxSizeMax 送信ボックスの最大保存サイズを指定します。受信BOXと送信BOXで合わせて 1MB 以内にする必要があります。デフォルトは 512*1024 バイトです。 312 @param[in] inboxMessNumMax 受信ボックスの最大保存Message数を指定します。デフォルトは 99 で、この値より多い値を指定することはできません。 313 @param[in] outboxMessNumMax 送信ボックスの最大保存Message数を指定します。デフォルトは 99 で、この値より多い値を指定することはできません。 314 @param[in] messageSizeMax Messageの最大サイズを指定します。このサイズを超えるMessageは保存できず、WriteMessage でエラーとなります。 315 @return nn::Result 316 */ 317 nn::Result CreateMessageBox( 318 const TitleId cecTitleId, const u32 privateId, 319 const char* hmacKey, 320 size_t inboxSizeMax = CEC_INBOX_SIZE_DEFAULT, 321 size_t outboxSizeMax = CEC_OUTBOX_SIZE_DEFAULT, 322 size_t inboxMessNumMax = CEC_INBOX_MESSNUM_DEFAULT, 323 size_t outboxMessNumMax = CEC_OUTBOX_MESSNUM_DEFAULT, 324 size_t messageSizeMax = CEC_MESSSIZEMAX_DEFAULT 325 ); 326 327 void CreateInBox(const TitleId cecTitleId); 328 void CreateOutBox(const TitleId cecTitleId); 329 330 /*! 331 @brief MessageBox を削除します。 332 333 @ref OpenMessageBox で開いているBoxを削除します。<br> 334 また、記憶していた通信相手のリストも消去され、同じ相手と再接続することが可能になります。このとき、設定中のボックスだけでなく、全てのボックス(アプリ)のデータが、再度交換される可能性があります。<br> 335 リストの消去は、nn::cec::CTR::CecControl::StartScanning(true) で通信開始するときも行われます。 336 337 @return nn::Result 338 */ 339 nn::Result DeleteMessageBox(); 340 341 /*! 342 @brief MessageBox を削除します。CecTitleIdを指定して削除します。 343 MessageBoxをOpenできないときに強制的に削除するといった用途に使用します。別アプリのMessageBoxを削除しないでください。 344 345 @param[in] cecTitleId Title固有ID 346 @return nn::Result 347 */ 348 nn::Result DeleteMessageBox(const TitleId cecTitleId); 349 350 nn::Result DeleteAllBoxes(); 351 352 /*! 353 @brief MessageBox を開きます。Box内のMessageにアクセスするために、まずこの関数でBoxを開く必要があります。 354 @param[in] cecTitleId Title固有ID 355 @param[in] privateId @ref CreateMessageBox でBOXを作成したときに指定した値と同じ値を指定します。 356 値が異なる場合はアクセスできません。 357 @return nn::Result 358 */ 359 nn::Result OpenMessageBox(const TitleId cecTitleId, const u32 privateId); 360 361 bool IsOpened(); 362 363 //@} 364 365 /*! 366 @brief MessageBox の 有効/無効 を指定します。無効にされているBOXのデータは送受信されません。 367 @param[in] active 有効: true / 無効: false 368 @return nn::Result 369 */ 370 nn::Result SetBoxActivate(bool active); 371 372 /*! 373 @brief MessageBox の 有効/無効 を取得します。無効にされているBOXのデータは送受信されません。 374 @return 有効: true / 無効: false 375 */ 376 bool GetBoxActivate(); 377 378 nn::Result ReadMessageBoxInfo(struct MessageBoxInfo* outbuf) const; 379 380 nn::Result GetBoxInfo(struct CecBoxInfoHeader* boxinfo, CecMessageHeader** boxInfoBody, CecBoxType boxType) const ; 381 nn::Result ReadBoxInfo(struct CecBoxInfoHeader* boxinfo, CecMessageHeader** boxInfoBody, u8* buf, CecBoxType boxType); 382 383 protected: 384 nn::Result ReadMessageBoxInfo(struct MessageBoxInfo* outbuf, TitleId cecTitleId) const; 385 nn::Result ReadMessageBoxInfo() const; 386 nn::Result WriteMessageBoxInfo(); 387 388 nn::Result WriteBoxInfo( CecBoxType boxType ,CecBoxInfoHeader& boxInfo , CecMessageHeader** boxInfoBody); 389 nn::Result ReadInBoxInfo(); 390 391 nn::Result WriteInBoxInfo(); 392 nn::Result ReadOutBoxInfo(); 393 nn::Result WriteOutBoxInfo(); 394 395 396 public: 397 //! @name Message操作 398 //@{ 399 /*! 400 @brief Message を読み出します。 401 @param[out] cecMessage 読み出し先の @ref Message クラスのオブジェクト 402 @param[out] buf Message のバイナリ列を格納するバッファ 403 @param[in] bufLen バッファのサイズ 404 @param[in] boxType 受信BOX/送信BOXの指定 405 @param[in] messageId MessageId の指定 406 @return nn::Result 407 */ 408 nn::Result ReadMessage( 409 Message& cecMessage, void* buf, const size_t bufLen, const CecBoxType boxType, const MessageId& messageId); 410 /*! 411 :private 412 @brief Message を読み出します。 413 @param[out] bufOut Message のバイナリ列を格納するバッファ 414 @param[in] bufLen バッファのサイズ 415 @param[in] boxType 受信BOX/送信BOXの指定 416 @param[in] messageId MessageId の指定 417 @return nn::Result 418 */ 419 nn::Result ReadMessage( 420 void* bufOut, const size_t bufLen, const CecBoxType boxType, const MessageId& messageId); 421 422 /*! 423 @brief Message を本体保存領域に書きこみます。 424 425 Messageのサイズが 100KB を超える場合、またはBOXの最大保存容量/個数 をオーバーする場合は書き込むことができません。<br> 426 427 @param[in] cecMessage @ref Message クラスのオブジェクト 428 @param[in] boxType 受信BOX/送信BOXの指定 429 @param[out] messageIdOut 書き込むときに付与される MessageId が返ります。 430 @return nn::Result 431 */ 432 nn::Result WriteMessage( 433 const Message& cecMessage,const CecBoxType boxType, MessageId& messageIdOut); 434 WriteMessage(const Message & cecMessage,const CecBoxType boxType)435 nn::Result WriteMessage( 436 const Message& cecMessage,const CecBoxType boxType) 437 { 438 MessageId messageIdOut; 439 return WriteMessage(cecMessage, boxType, messageIdOut); 440 } 441 442 443 /*! 444 :private 445 @brief Message を本体保存領域に書きこみます。 446 447 Messageのサイズが 100KB を超える場合、またはBOXの最大保存容量/個数 をオーバーする場合は書き込むことができません。<br> 448 449 @param[in] message Message のバイナリ列を格納するバッファ 450 @param[in] messageLen バッファのサイズ 451 @param[in] boxType 受信BOX/送信BOXの指定 452 @param[out] messageIdOut 書き込むときに付与される MessageId が返ります。 453 @return nn::Result 454 */ 455 nn::Result WriteMessage( 456 const void* message, const size_t messageLen ,const CecBoxType boxType, MessageId& messageIdOut); 457 458 /*! 459 @brief Message を削除します。 460 461 @param[in] boxType 受信BOX/送信BOXの指定 462 @param[in] messageId MessageId の指定 463 @return nn::Result 464 */ 465 nn::Result DeleteMessage( const CecBoxType boxType, const MessageId& messageId); 466 467 //@} 468 469 protected: 470 u8 ReadInBoxMessage(void* bufOut, const size_t messageLen, const MessageId& messageId); 471 u8 WriteInBoxMessage(const void* message, const size_t messageLen, MessageId* pMessageIdOut); 472 u8 WriteInBoxMessage(Message& cecMessage, MessageId* pMessageId); 473 u8 DeleteInBoxMessage(const CECMessageId messageId); 474 u8 ReadOutBoxMessage(void* bufOut, const size_t messageLen, const MessageId& messageId); 475 u8 WriteOutBoxMessage(const void* message, const size_t messageLen, MessageId* pMessageIdOut); 476 u8 WriteOutBoxMessage(Message& cecMessage, MessageId* pMessageIdOut); 477 u8 DeleteOutBoxMessage(const MessageId& messageId); 478 479 public: 480 // Box List 481 482 //! @name BOX制御・情報取得 483 //@{ 484 485 /*! 486 @brief MessageBox に付随するデータを取得します。 487 @param[in] datatype データ種別を指定します。 @ref CecBoxDataType で指定します。 488 @param[out] dataBuf バッファを指定します。 489 @param[in] dataBufSize バッファサイズを指定します。 490 @return nn::Result 491 */ 492 nn::Result GetMessageBoxData(u32 datatype, void* dataBuf, size_t dataBufSize); 493 494 /*! 495 @brief MessageBox に付随するデータサイズを取得します。 496 @param[in] datatype データ種別を指定します。 @ref CecBoxDataType で指定します。 497 @return データサイズ 498 */ 499 size_t GetMessageBoxDataSize(const u32 datatype); 500 501 /*! 502 @brief MessageBox に付随するデータをセットします。 503 @param[in] datatype データ種別を指定します。 @ref CecBoxDataType で指定します。 504 @param[in] data データを指定します。 505 @param[in] dataSize データサイズを指定します。最大長は 10KB です。 506 @return nn::Result 507 */ 508 nn::Result SetMessageBoxData(u32 datatype, const void* data, size_t dataSize); 509 510 /*! 511 @brief MessageBox の名称をセットします。 512 @param[in] data データを指定します。<br> 513 文字コード: UTF16-LE<br> 514 表示サイズ: 全角17文字で表示できる文字数<br> 515 バッファ最大: 64×2Bytes (NULL終端込み)<br> 516 @param[in] dataSize データサイズを指定します。 517 @return nn::Result 518 */ 519 nn::Result SetMessageBoxName(const wchar_t* data, size_t dataSize); 520 521 /*! 522 @brief MessageBox のアイコンをセットします。 523 @param[in] data データを指定します。<br> 524 フォーマット: RGB565 (リトルエンディアン)<br> 525 サイズ: 48×48 (4.5KBytes) <br> 526 @param[in] dataSize データサイズを指定します。 527 @return nn::Result 528 */ 529 nn::Result SetMessageBoxIcon(const void* data, size_t dataSize); 530 531 /*! 532 @brief MessageBox の名称を取得します。 533 @param[out] dataBuf バッファを指定します。<br> 534 文字コード: UTF16-LE<br> 535 表示サイズ: 全角17文字で表示できる文字数<br> 536 バッファ最大: 64×2Bytes (NULL終端込み)<br> 537 @param[in] dataBufSize バッファサイズを指定します。 538 @return nn::Result 539 */ 540 nn::Result GetMessageBoxName(wchar_t* dataBuf, size_t dataBufSize); 541 542 /*! 543 @brief MessageBox のアイコンを取得します。 544 @param[out] dataBuf バッファを指定します。<br> 545 フォーマット: RGB565 (リトルエンディアン)<br> 546 サイズ: 48×48 (4.5KBytes) <br> 547 @param[in] dataBufSize バッファサイズを指定します。 548 @return nn::Result 549 */ 550 nn::Result GetMessageBoxIcon(void* dataBuf, size_t dataBufSize); 551 552 553 /*-----------------------------------------------*/ 554 555 //! @name BOX情報取得 556 //@{ 557 558 /*! 559 @brief MessageBox の属性 を取得します。 560 @return @ref MessageBoxFlag 561 */ 562 MessageBoxFlag GetBoxFlag(); 563 564 u32 GetInBoxSizeMax(); 565 u32 GetInBoxSize(); 566 567 u32 GetOutBoxSizeMax(); 568 u32 GetOutBoxSize(); 569 570 /*! 571 @brief 送信 BOX / 受信BOX の容量を取得します。 572 @param[in] boxType 送信 BOX / 受信BOXの指定 573 @return 容量の値が返ります。(BOX作成時に指定したものと同じです。) 574 */ 575 u32 GetBoxSizeMax(CecBoxType boxType); 576 /*! 577 @brief 送信 BOX / 受信BOX の使用量を取得します。 578 @param[in] boxType 送信 BOX / 受信BOXの指定 579 @return 使用量の値が返ります。 580 */ 581 u32 GetBoxSize(CecBoxType boxType); 582 583 584 /*-----------------------------------------------*/ 585 u32 GetInBoxMessNumMax(); 586 u32 GetInBoxMessNum(); 587 588 u32 GetOutBoxMessNumMax(); 589 u32 GetOutBoxMessNum(); 590 591 /*! 592 @brief 送信 BOX / 受信BOX の最大 Message 数を取得します。 593 @param[in] boxType 送信 BOX / 受信BOXの指定 594 @return 個数の値が返ります。(BOX作成時に指定したものと同じです。) 595 */ 596 u32 GetBoxMessNumMax(CecBoxType boxType); 597 /*! 598 @brief 送信 BOX / 受信BOX の Message 数を取得します。 599 @param[in] boxType 送信 BOX / 受信BOXの指定 600 @return 個数の値が返ります。 601 */ 602 u32 GetBoxMessNum(CecBoxType boxType); 603 604 605 /*-----------------------------------------------*/ 606 u32 GetInBoxGroupNumMax(); 607 u32 GetInBoxGroupNum(); 608 609 u32 GetOutBoxGroupNumMax(); 610 u32 GetOutBoxGroupNum(); 611 612 /*! 613 @brief 送信 BOX / 受信BOX の最大 Message Group 数を取得します。 614 @param[in] boxType 送信 BOX / 受信BOXの指定 615 @return Message Group 数の値が返ります。(SetBoxGroupNumMax で指定した値です。) 616 */ 617 u32 GetBoxGroupNumMax(CecBoxType boxType); 618 /*! 619 @brief 送信 BOX / 受信BOX の Message Group 数を取得します。 620 @param[in] boxType 送信 BOX / 受信BOXの指定 621 @return Message Group 数の値が返ります。 622 */ 623 u32 GetBoxGroupNum(CecBoxType boxType); 624 625 /*! 626 @brief 送信 BOX / 受信BOX の 最大 Message Group 数を指定します。 627 628 <br> 629 実際にこの値でGroup数が制限されることはありません。<br> 630 保存可能数としての目安として、ユーザに通知(表示)するための値です。<br> 631 受信BOXのサイズ(GetBoxSizeMax(CEC_BOXTYPE_INBOX)) ÷ 1Group のサイズ、<br> 632 または、 受信BOX の最大 Message 数(GetBoxMessNumMax(CEC_BOXTYPE_INBOX)) ÷ 1GroupのMessage数 の値を指定するのが目安となります。 633 634 @param[in] num 最大 Group 数 635 @param[in] boxType 送信 BOX / 受信BOXの指定 636 @return nn::Result 637 */ 638 nn::Result SetBoxGroupNumMax(u32 num, CecBoxType boxType); 639 nn::Result SetInBoxGroupNumMax(u32 num); 640 nn::Result SetOutBoxGroupNumMax(u32 num); 641 642 /*-----------------------------------------------*/ 643 644 //u32 GetInBoxSessionNumMax(); 645 u32 GetInBoxSessionNum(); 646 647 //u32 GetOutBoxSessionNumMax(); 648 //u32 GetOutBoxSessionNum(); 649 650 /*! 651 @brief 受信BOX の Session ID 数(=受信した回数)を取得します。 652 653 Session ID は、通信相手の検索に入る前に乱数で生成されます。<br> 654 相手を発見して通信するときに、相手にその ID を渡します。<br> 655 データ受信側は、相手の Session ID を 受信Message に書き込みます。<br> 656 1回のすれちがい通信で受信したデータ全てに、同じSession ID が書き込まれます。<br> 657 GroupIDが同じでも、Session ID が異なる場合は、別の通信で受信したデータであることがわかります。BOX内のMessageの Session 数をカウントすることで、受信した回数を知ることができます。<br> 658 659 660 @param[in] boxType CecBoxType で指定します。CEC_BOXTYPE_INBOX を指定します。 661 @return Session ID 数の値が返ります。 662 */ 663 u32 GetBoxSessionNum(CecBoxType boxType); 664 /*-----------------------------------------------*/ 665 //@} 666 667 #if 1 // BoxInfoReader の Message情報取得部を使用する。重複するため、元々Boxクラスにあった部分を将来的に削除。 668 //! @name Message情報取得(旧API) 669 //@{ 670 671 u32 GetInBoxMessHeader(CecMessageHeader& messHeader, const MessageId& messageId); 672 u32 GetInBoxMessHeaderByIndex(CecMessageHeader& messHeader, u32 messIndex); 673 674 /*! 675 @brief 受信BOXの n 番目 の Message の MessageID を取得します。 676 677 GetMessageMessId で取得できる値と同じです。 678 679 @param[in] messIndex n 番目 680 @return @ref CECMessageId が返ります。 681 */ 682 u8* GetInBoxMessIdByIndex(u32 messIndex); 683 684 u32 GetOutBoxMessHeader(CecMessageHeader& messHeader, const MessageId& messageId); 685 u32 GetOutBoxMessHeaderByIndex(CecMessageHeader& messHeader, u32 messIndex); 686 687 /*! 688 @brief 送信BOXの n 番目 の Message の MessageID を取得します。 689 690 GetMessageMessId で取得できる値と同じです。 691 692 @param[in] messIndex n 番目(n=0が先頭を示します。) 693 @return @ref CECMessageId が返ります。 694 */ 695 u8* GetOutBoxMessIdByIndex(u32 messIndex); 696 697 /*! 698 @brief MessageID を指定して Message のサイズを取得します。 699 700 GetMessageMessSize で取得できる値と同じです。 701 702 @param[in] boxType 送信 BOX / 受信BOXの指定 703 @param[in] messId MessageId 704 @return サイズの値が返ります。 705 */ 706 size_t GetMessSizeByMessId(CecBoxType boxType, const MessageId& messageId); 707 size_t GetBodySizeByMessId(CecBoxType boxType, const MessageId& messageId); 708 //@} 709 #endif 710 711 CecMessageHeader* GetMessHeaderByMessId(const CecBoxType boxType, const MessageId& messId); 712 CecMessageHeader* GetMessHeader(const CecBoxType boxType, const u32 messIndex); 713 714 bool MessageExists(CecBoxType boxType, const MessageId& messageId); 715 //! @name Message の情報取得 716 //@{ 717 718 /*! 719 * @brief BoxのMessageのサイズを取得します。 720 * @param[in] boxType @ref CecBoxType 721 * @param[in] messIndex n番目のMessage 722 * @return Messageのサイズ 723 */ 724 u32 GetMessageMessSize(const CecBoxType boxType, const u32 messIndex); 725 726 /*! 727 * @brief BoxのMessageの本文サイズを取得します。 728 * @param[in] boxType @ref CecBoxType 729 * @param[in] messIndex n番目のMessage 730 * @return Messageの本文サイズ 731 */ 732 u32 GetMessageBodySize(const CecBoxType boxType, const u32 messIndex); 733 734 /*! 735 * @brief BoxのMessageの Group ID を取得します。 736 * @param[in] boxType @ref CecBoxType 737 * @param[in] messIndex n番目のMessage 738 * @return Messageの Group ID 739 */ 740 u32 GetMessageGroupId(const CecBoxType boxType, const u32 messIndex); 741 742 /*! 743 * @brief 受信BoxのMessageの Session ID を取得します。(受信時に付与されるIDです) 744 * @param[in] boxType @ref CecBoxType 745 * @param[in] messIndex n番目のMessage 746 * @return Messageの Session ID 747 */ 748 u32 GetMessageSessionId(const CecBoxType boxType, const u32 messIndex); 749 750 /*! 751 * @brief BoxのMessageの @ref CecMessageTypeFlag を取得します。 752 * @param[in] boxType @ref CecBoxType 753 * @param[in] messIndex n番目のMessage 754 * @return @ref CecMessageTypeFlag 755 */ 756 MessageTypeFlag GetMessageMessTypeFlag(const CecBoxType boxType, const u32 messIndex); 757 758 /*! 759 * @brief BoxのMessageの @ref SendMode を取得します。 760 * @param[in] boxType @ref CecBoxType 761 * @param[in] messIndex n番目のMessage 762 * @return @ref SendMode 763 */ 764 SendMode GetMessageSendMode(const CecBoxType boxType, const u32 messIndex); 765 766 /*! 767 * @brief BoxのMessageの 送信回数 を取得します。 768 * @param[in] boxType @ref CecBoxType 769 * @param[in] messIndex n番目のMessage 770 * @return 送信回数 771 */ 772 u8 GetMessageSendCount(const CecBoxType boxType, const u32 messIndex); 773 774 /*! 775 * @brief BoxのMessageの 伝播回数 を取得します。 776 * @param[in] boxType @ref CecBoxType 777 * @param[in] messIndex n番目のMessage 778 * @return 伝播回数 779 */ 780 u8 GetMessagePropagationCount(const CecBoxType boxType, const u32 messIndex); 781 782 /*! 783 :private 784 * @brief BoxのMessageの 未読フラグ を取得します。 785 * @param[in] boxType @ref CecBoxType 786 * @param[in] messIndex n番目のMessage 787 * @return 未読フラグ 788 */ 789 bit8 GetMessageFlag_Unread(const CecBoxType boxType, const u32 messIndex); 790 791 /*! 792 :private 793 * @brief BoxのMessageの 新着フラグ を取得します。 794 * @param[in] boxType @ref CecBoxType 795 * @param[in] messIndex n番目のMessage 796 * @return 新着フラグ 797 */ 798 bit8 GetMessageFlag_New(const CecBoxType boxType, const u32 messIndex); 799 800 /*! 801 * @brief BoxのMessageの Tag を取得します。 802 * @param[in] boxType @ref CecBoxType 803 * @param[in] messIndex n番目のMessage 804 * @return Tag 805 */ 806 bit16 GetMessageTag(const CecBoxType boxType, const u32 messIndex); 807 808 /*! 809 * @brief Boxの受信Messageの 送信日時 を取得します。 810 * @param[in] boxType @ref CecBoxType 811 * @param[in] messIndex n番目のMessage 812 * @return @ref nn::fnd::DateTimeParameters 813 */ 814 nn::fnd::DateTimeParameters GetMessageSendDate(const CecBoxType boxType, const u32 messIndex); 815 816 /*! 817 * @brief Boxの受信Messageの 受信日時 を取得します。 818 * @param[in] boxType @ref CecBoxType 819 * @param[in] messIndex n番目のMessage 820 * @return @ref nn::fnd::DateTimeParameters 821 */ 822 nn::fnd::DateTimeParameters GetMessageRecvDate(const CecBoxType boxType, const u32 messIndex); 823 824 /*! 825 * @brief BoxのMessageの 作成日時 を取得します。 826 * @param[in] boxType @ref CecBoxType 827 * @param[in] messIndex n番目のMessage 828 * @return @ref nn::fnd::DateTimeParameters 829 */ 830 nn::fnd::DateTimeParameters GetMessageCreateDate(const CecBoxType boxType, const u32 messIndex); 831 832 /*! 833 * @brief 交換された Message の 対になる MessageID を取得します。 834 835 通信の方式に「交換」を 指定して通信したとき、対になる 送信 Message の MessageID が、受信 Message に記録されます。 836 837 * @param[out] messId @ref MessageId 838 * @param[in] boxType @ref CecBoxType 839 * @param[in] messIndex n番目のMessage 840 * @return nn::Result 841 */ 842 nn::Result GetMessageMessIdPair(MessageId& messId, const CecBoxType boxType, const u32 messIndex); 843 u8* GetMessageMessIdPair(const CecBoxType boxType, const u32 messIndex); 844 845 846 /*! 847 * @brief BoxのMessageの MessageID を取得します。 848 * @param[out] messId @ref MessageId 849 * @param[in] boxType @ref CecBoxType 850 * @param[in] messIndex n番目のMessage 851 * @return nn::Result 852 */ 853 nn::Result GetMessageMessId(MessageId& messId, const CecBoxType boxType, const u32 messIndex); 854 u8* GetMessageMessId(const CecBoxType boxType, const u32 messIndex); 855 856 857 /*! 858 * @brief MessageID から、何番目のMessageであるか(messIndex)を取得します。 859 * @param[in] boxType @ref CecBoxType 860 * @param[in] messId MessageId 861 * @return messIndex 862 */ 863 u32 GetMessIndex(CecBoxType boxType, MessageId& messId); 864 u32 GetMessIndex(CecBoxType boxType, u8* messId); 865 //@} 866 867 /*! 868 :private 869 @brief 送信BOX の Message 送信順リストの末尾に MessageID を追加します。 870 ( @ref WriteMessage で Message をセットした時点で自動的に追加されるので、 871 通常はこのAPIを使う必要はありません。) 872 @param[in] messageId MessageID を指定します。 873 @return リストの MessageID 数 が返ります。 874 */ 875 u32 AppendOutBoxIndex(const MessageId& messageId); 876 877 /*! 878 :private 879 @brief 送信BOX の Message 送信順リストから MessageID を削除します。 880 ( Message を削除した時点で自動的にリストから削除されるので、 881 通常はこのAPIを使う必要はありません。) 882 @param[in] messageId MessageID を指定します。 883 @return リストの MessageID 数 が返ります。 884 */ 885 u32 RemoveOutBoxIndex(const MessageId& messageId); 886 887 /*! 888 @brief 送信BOX の Message 送信順リスト内で、指定した MessageID の Message を末尾に回します。 889 ( Message を送信した時点で自動的に順番を変更されるので、 890 通常はこのAPIを使う必要はありません。) 891 892 @param[in] messageId MessageID を指定します。 893 @return リストの MessageID 数 が返ります。 894 */ 895 u32 RoundOutBoxIndex(const MessageId& messageId); 896 897 u32 ResetOutBoxIndex(); 898 u32 ReadOutBoxIndex(); 899 nn::Result WriteOutBoxIndex(); 900 901 protected: 902 //IPC 903 virtual nn::Result OpenFile(const u32 cecTitleId, const u32 dataType, const u32 option, size_t* filesize ) const ; 904 virtual nn::Result ReadFile(void* readBuf, size_t readBufLen, size_t* readLen) const; 905 virtual nn::Result WriteFile(const void* writeBuf, const size_t writeBufLen) const; 906 virtual nn::Result ReadMessageFile( 907 u32 cecTitleId, 908 u8 boxType, 909 const u8* pMessId, 910 size_t messIdLen, 911 size_t* pReadLen, 912 u8* pReadBuf, 913 size_t len); 914 915 virtual nn::Result ReadMessageFileWithHmac( 916 u32 cecTitleId, 917 u8 boxType, 918 const u8* pMessId, 919 size_t messIdLen, 920 size_t* pReadLen, 921 u8* pReadBuf, 922 size_t len, u8* pHmac); 923 924 virtual nn::Result WriteMessageFile( 925 u32 cecTitleId, 926 u8 boxType, 927 u8* pMessId, 928 size_t messIdLen, 929 const u8* pWriteBuf, 930 size_t len); 931 932 virtual nn::Result WriteMessageFileWithHmac( 933 u32 cecTitleId, 934 u8 boxType, 935 u8* pMessId, 936 size_t messIdLen, 937 const u8* pWriteBuf, 938 size_t len, u8* pHmac); 939 940 virtual nn::Result Delete( u32 cecTitleId, u32 dataType, u8 boxType, const u8 pMessId[], size_t messIdLen ); 941 virtual nn::Result SetData(u32 cecTitleId, const u8* pSetBuf, size_t len, u32 option); 942 virtual nn::Result ReadData(u8 *pReadBuf, size_t len, u32 option, const u8 optionData[], size_t optionDataLen); 943 944 }; 945 946 } // namespace CTR 947 } // namespace cec 948 } // namespace nn 949 950 /* 951 #define CEC_STATE_MFILTER_EXCHANGE (0x1) 952 #define CEC_STATE_ID_EXCHANGE (0x2) 953 #define CEC_STATE_LIST_EXCHANGE (0x4) 954 */ 955 956 #endif //__MESSAGE_BOX_H__ 957 958