1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PBAP_PCE_HEADER_MSG_H 17 #define PBAP_PCE_HEADER_MSG_H 18 19 #include <cstdint> 20 #include <cstring> 21 #include <memory> 22 #include "../obex/obex_client.h" 23 #include "../obex/obex_headers.h" 24 #include "btstack.h" 25 #include "message.h" 26 #include "pbap_pce_def.h" 27 #include "pbap_pce_gap.h" 28 29 namespace OHOS { 30 namespace bluetooth { 31 /// pbap pce state mathine message 32 enum PbapPceStmMessage { 33 PCE_SDP_FINISH = 0x1001, // sdp search success 34 PCE_SDP_FAILED, // sdp search failed 35 PCE_GAP_FINISH, // gap security success 36 PCE_GAP_FAILED, // gap security failed 37 PCE_REQ_DISCONNECTED, // disconnect request 38 PCE_PASSWORD_INPUT, // when device password is input by user 39 PCE_OBEX_CONNECTED, // obex connected 40 PCE_OBEX_CONNECT_FAILED, // obex connect failed 41 PCE_TRANSPORT_FAILED, // transport failed 42 PCE_OBEX_DISCONNECTED, // obex disconnected 43 PCE_REQ_SET_TARGET_STATE, // request setting target state 44 PCE_REQ_TRANSIT_TARGET_STATE, // transit target state 45 PCE_REQ_PULLPHONEBOOKSIZE, // pull phonebooksize 46 PCE_PULLPHONEBOOKSIZE_COMPLETED, // pull phonebooksize completed 47 PCE_REQ_PULLPHONEBOOK, // pull phonebook 48 PCE_PULLPHONEBOOK_COMPLETED, // pull phonebook completed 49 PCE_REQ_SETPHONEBOOK, // set phonebook 50 PCE_SETPHONEBOOK_COMPLETED, // pull setphonebook completed 51 PCE_REQ_PULLVCARDLISTINGSIZE, // pull vcardlisting size 52 PCE_PULLVCARDLISTINGSIZE_COMPLETED, // pull vcardlisting size completed 53 PCE_REQ_PULLVCARDLISTING, // pull vcard listing 54 PCE_PULLVCARDLISTING_COMPLETED, // pull pullvcardlisting completed 55 PCE_REQ_PULLVCARDENTRY, // pull vcard entry 56 PCE_PULLVCARDENTRY_COMPLETED, // pull pullvcardentry completed 57 PCE_REQ_ABORTDOWNLOADING, // abort downloading 58 PCE_ABORTDOWNLOADING_COMPLETED, // abort downloading completed 59 }; 60 61 /** 62 * @brief pbap pce message 63 * pbap pce message 64 */ 65 class PbapPceHeaderSdpMsg { 66 public: 67 /** 68 * @brief constructor 69 * @details constructor 70 * @param obexConfig obex config 71 * @param versionNumber version number 72 * @param supportedRes supported repositories 73 * @param supportedFeature supported features 74 * @param featureFlag 75 * @return 76 */ PbapPceHeaderSdpMsg(ObexClientConfig & obexConfig,uint16_t versionNumber,uint8_t supportedRes,uint32_t supportedFeature,bool featureFlag)77 explicit PbapPceHeaderSdpMsg(ObexClientConfig &obexConfig, uint16_t versionNumber, uint8_t supportedRes, 78 uint32_t supportedFeature, bool featureFlag) 79 : obexConfig_(obexConfig), 80 versionNumber_(versionNumber), 81 supportedRes_(supportedRes), 82 supportedFeature_(supportedFeature), 83 featureFlag_(featureFlag) 84 {} 85 /** 86 * @brief copy contructor 87 * @details copy contructor 88 */ 89 PbapPceHeaderSdpMsg(const PbapPceHeaderSdpMsg &other) = default; 90 /** 91 * @brief operator= 92 * @details operator= 93 */ 94 PbapPceHeaderSdpMsg &operator=(const PbapPceHeaderSdpMsg &other) = default; 95 /** 96 * @brief destructor 97 * @details destructor 98 */ 99 virtual ~PbapPceHeaderSdpMsg() = default; 100 101 /** 102 * @brief get obex config 103 * @details get obex config 104 * @return reference to ObexClientConfig 105 */ GetObexClientConfig()106 const ObexClientConfig &GetObexClientConfig() const 107 { 108 return obexConfig_; 109 } 110 111 /** 112 * @brief get version number 113 * @details get version number 114 * @return uint16_t 115 */ GetVersionNumber()116 uint16_t GetVersionNumber() const 117 { 118 return versionNumber_; 119 } 120 121 /** 122 * @brief get supported repositories 123 * @details get supported repositories 124 * @return uint8_t 125 */ GetSupportedRes()126 uint8_t GetSupportedRes() const 127 { 128 return supportedRes_; 129 } 130 131 /** 132 * @brief get supported features 133 * @details get supported features 134 * @return uint32_t 135 */ GetSupportedFeature()136 uint32_t GetSupportedFeature() const 137 { 138 return supportedFeature_; 139 } 140 141 /** 142 * @brief get feature flag 143 * @details get feature flag 144 * @return bool 145 */ GetFeatureFlag()146 bool GetFeatureFlag() const 147 { 148 return featureFlag_; 149 } 150 151 /** 152 * @brief get gap pointer 153 * @details get gap pointer 154 * @return reference to PbapPceGap 155 */ GetPbapPceGap()156 PbapPceGap &GetPbapPceGap() const 157 { 158 return *pbapPceGapPtr_; 159 } 160 161 /** 162 * @brief set gap pointer 163 * @details set gap pointer 164 * @param gap reference to gap 165 */ SetPbapPceGap(PbapPceGap & gap)166 void SetPbapPceGap(PbapPceGap &gap) 167 { 168 pbapPceGapPtr_ = ⪆ 169 } 170 171 private: 172 ObexClientConfig obexConfig_ {}; // obex config 173 uint16_t versionNumber_ = 0; // received from pse version number 174 uint8_t supportedRes_ = 0; // received from pse Supported Repositories 175 uint32_t supportedFeature_ = 0; // received from pse Supported feature 176 bool featureFlag_ = false; // true:can received feature; false:cannot received feature 177 PbapPceGap *pbapPceGapPtr_ = nullptr; // gap pointer 178 }; 179 180 /** 181 * @brief pbap pce obex message 182 * pbap pce obex message 183 */ 184 class PbapPceObexMessage { 185 public: 186 /** 187 * @brief constructor 188 * @details constructor 189 * @param client obex client 190 * @param resp obex header 191 */ PbapPceObexMessage(ObexClient & client,const ObexHeader & resp)192 explicit PbapPceObexMessage(ObexClient &client, const ObexHeader &resp) : 193 client_(&client), resp_(std::make_unique<ObexHeader>(resp)) 194 { 195 } 196 197 /** 198 * @brief destructor 199 * @details destructor 200 */ 201 virtual ~PbapPceObexMessage() = default; 202 203 /** 204 * @brief get obex client 205 * @details get obex client 206 * @return ObexClient* 207 */ GetObexClient()208 ObexClient *GetObexClient() const 209 { 210 return this->client_; 211 } 212 213 /** 214 * @brief get obex header 215 * @details get obex header 216 * @return ObexHeader* 217 */ GetObexHeader()218 const ObexHeader *GetObexHeader() const 219 { 220 return this->resp_.get(); 221 } 222 223 private: 224 ObexClient *client_ = nullptr; // obex client 225 std::unique_ptr<ObexHeader> resp_ {nullptr}; // obex header 226 BT_DISALLOW_COPY_AND_ASSIGN(PbapPceObexMessage); 227 }; 228 229 /** 230 * @brief pbap pce obex message for action 231 * pbap pce message for action 232 */ 233 class PbapPceActionObexMessage : public PbapPceObexMessage { 234 public: PbapPceActionObexMessage(ObexClient & client,const ObexHeader & resp,const std::u16string & name,uint8_t flags)235 explicit PbapPceActionObexMessage( 236 ObexClient &client, const ObexHeader &resp, const std::u16string &name, uint8_t flags) 237 : PbapPceObexMessage(client, resp), name_(name), flags_(flags) 238 {} 239 240 ~PbapPceActionObexMessage() override = default; 241 GetName()242 std::u16string GetName() const 243 { 244 return name_; 245 } 246 GetFlags()247 uint8_t GetFlags() const 248 { 249 return flags_; 250 } 251 252 private: 253 std::u16string name_; 254 uint8_t flags_; 255 }; 256 257 /** 258 * @brief Pbap Pce Password InputMsg 259 * Pbap Pce Password InputMsg 260 */ 261 class PbapPcePasswordInputMsg { 262 public: PbapPcePasswordInputMsg(const std::string & password,const std::string & userId)263 explicit PbapPcePasswordInputMsg(const std::string &password, const std::string &userId) 264 : password_(password), userId_(userId) 265 {} PbapPcePasswordInputMsg(const std::string & password)266 explicit PbapPcePasswordInputMsg(const std::string &password) : password_(password), userId_("") 267 {} 268 269 virtual ~PbapPcePasswordInputMsg() = default; 270 GetPassword()271 std::string GetPassword() const 272 { 273 return password_; 274 } 275 GetUserId()276 std::string GetUserId() const 277 { 278 return userId_; 279 } 280 281 private: 282 std::string password_ = ""; 283 std::string userId_ = ""; 284 }; 285 286 /** 287 * @brief Pbap Pce PullPhoneBookMsg for interthread 288 * Pbap Pce PullPhoneBook Msg 289 */ 290 class PbapPcePullPhoneBookMsg { 291 public: 292 explicit PbapPcePullPhoneBookMsg() = default; 293 virtual ~PbapPcePullPhoneBookMsg() = default; 294 GetName()295 std::u16string GetName() const 296 { 297 return name_; 298 } 299 SetName(const std::u16string & name)300 void SetName(const std::u16string& name) 301 { 302 name_ = name; 303 } 304 GetPropertySelector()305 uint64_t GetPropertySelector() const 306 { 307 return propertySelector_; 308 } 309 SetPropertySelector(uint64_t selector)310 void SetPropertySelector(uint64_t selector) 311 { 312 propertySelector_ = selector; 313 } 314 GetFormat()315 uint8_t GetFormat() const 316 { 317 return format_; 318 } 319 SetFormat(uint8_t fmt)320 void SetFormat(uint8_t fmt) 321 { 322 format_ = fmt; 323 } 324 GetMaxListCount()325 uint16_t GetMaxListCount() const 326 { 327 return maxListCount_; 328 } 329 SetMaxListCount(uint16_t max)330 void SetMaxListCount(uint16_t max) 331 { 332 maxListCount_ = max; 333 } 334 GetListStartOffset()335 uint16_t GetListStartOffset() const 336 { 337 return listStartOffset_; 338 } 339 SetListStartOffset(uint16_t offset)340 void SetListStartOffset(uint16_t offset) 341 { 342 listStartOffset_ = offset; 343 } 344 GetResetNewMissedCalls()345 uint8_t GetResetNewMissedCalls() const 346 { 347 return resetNewMissedCalls_; 348 } 349 SetResetNewMissedCalls(uint8_t reset)350 void SetResetNewMissedCalls(uint8_t reset) 351 { 352 resetNewMissedCalls_ = reset; 353 } 354 GetvCardSelector()355 uint64_t GetvCardSelector() const 356 { 357 return vCardSelector_; 358 } 359 SetvCardSelector(uint64_t selector)360 void SetvCardSelector(uint64_t selector) 361 { 362 vCardSelector_ = selector; 363 } 364 GetvCardSelectorOp()365 uint8_t GetvCardSelectorOp() const 366 { 367 return vCardSelectorOp_; 368 } 369 SetvCardSelectorOp(uint8_t op)370 void SetvCardSelectorOp(uint8_t op) 371 { 372 vCardSelectorOp_ = op; 373 } 374 GetSpecifiedBitset()375 uint64_t GetSpecifiedBitset() const 376 { 377 return specifiedBitset_; 378 } 379 SetSpecifiedBitset(uint64_t bitSet)380 void SetSpecifiedBitset(uint64_t bitSet) 381 { 382 specifiedBitset_ = bitSet; 383 } 384 385 private: 386 std::u16string name_ = u""; 387 uint64_t propertySelector_ = 0ULL; 388 uint8_t format_ = 0; 389 uint16_t maxListCount_ = 0; 390 uint16_t listStartOffset_ = 0; 391 uint8_t resetNewMissedCalls_ = 0; 392 uint64_t vCardSelector_ = 0ULL; 393 uint8_t vCardSelectorOp_ = 0; 394 uint64_t specifiedBitset_ = 0ULL; 395 }; 396 397 /** 398 * @brief Pbap Pce SetPhoneBookMsg for interthread 399 * Pbap Pce SetPhoneBook Msg 400 */ 401 class PbapPceSetPhoneBookMsg { 402 public: PbapPceSetPhoneBookMsg(const std::u16string & name,uint8_t flag)403 explicit PbapPceSetPhoneBookMsg(const std::u16string &name, uint8_t flag) : name_(name), flag_(flag) 404 {} 405 virtual ~PbapPceSetPhoneBookMsg() = default; 406 GetName()407 std::u16string GetName() const 408 { 409 return name_; 410 } 411 GetFlag()412 uint8_t GetFlag() const 413 { 414 return flag_; 415 } 416 417 private: 418 std::u16string name_ = u""; 419 uint8_t flag_ = 0; 420 }; 421 422 /** 423 * @brief Pbap Pce PullvCardListing Msg for interthread 424 * Pbap Pce PullvCardListing Msg 425 */ 426 class PbapPcePullvCardListingMsg { 427 public: 428 explicit PbapPcePullvCardListingMsg() = default; 429 virtual ~PbapPcePullvCardListingMsg() = default; 430 GetName()431 std::u16string GetName() const 432 { 433 return name_; 434 } 435 SetName(const std::u16string & name)436 void SetName(const std::u16string& name) 437 { 438 name_ = name; 439 } 440 GetOrder()441 uint8_t GetOrder() const 442 { 443 return order_; 444 } 445 SetOrder(uint8_t order)446 void SetOrder(uint8_t order) 447 { 448 order_ = order; 449 } 450 GetSearchValue()451 std::string GetSearchValue() const 452 { 453 return searchValue_; 454 } 455 SetSearchValue(const std::string & val)456 void SetSearchValue(const std::string& val) 457 { 458 searchValue_ = val; 459 } 460 GetSearchProperty()461 uint8_t GetSearchProperty() const 462 { 463 return searchProperty_; 464 } 465 SetSearchProperty(uint8_t prop)466 void SetSearchProperty(uint8_t prop) 467 { 468 searchProperty_ = prop; 469 } 470 GetMaxListCount()471 uint16_t GetMaxListCount() const 472 { 473 return maxListCount_; 474 } 475 SetMaxListCount(uint16_t max)476 void SetMaxListCount(uint16_t max) 477 { 478 maxListCount_ = max; 479 } 480 GetListStartOffset()481 uint16_t GetListStartOffset() const 482 { 483 return listStartOffset_; 484 } 485 SetListStartOffset(uint16_t offset)486 void SetListStartOffset(uint16_t offset) 487 { 488 listStartOffset_ = offset; 489 } 490 GetResetNewMissedCalls()491 uint8_t GetResetNewMissedCalls() const 492 { 493 return resetNewMissedCalls_; 494 } 495 SetResetNewMissedCalls(uint8_t reset)496 void SetResetNewMissedCalls(uint8_t reset) 497 { 498 resetNewMissedCalls_ = reset; 499 } 500 GetvCardSelector()501 uint64_t GetvCardSelector() const 502 { 503 return vCardSelector_; 504 } 505 SetvCardSelector(uint64_t selector)506 void SetvCardSelector(uint64_t selector) 507 { 508 vCardSelector_ = selector; 509 } 510 GetvCardSelectorOp()511 uint8_t GetvCardSelectorOp() const 512 { 513 return vCardSelectorOp_; 514 } 515 SetvCardSelectorOp(uint8_t op)516 void SetvCardSelectorOp(uint8_t op) 517 { 518 vCardSelectorOp_ = op; 519 } 520 GetSpecifiedBitset()521 uint64_t GetSpecifiedBitset() const 522 { 523 return specifiedBitset_; 524 } 525 SetSpecifiedBitset(uint64_t bitSet)526 void SetSpecifiedBitset(uint64_t bitSet) 527 { 528 specifiedBitset_ = bitSet; 529 } 530 531 private: 532 std::u16string name_ = u""; 533 uint8_t order_ = 0; 534 std::string searchValue_ = ""; 535 uint8_t searchProperty_ = 0; 536 uint16_t maxListCount_ = 0; 537 uint16_t listStartOffset_ = 0; 538 uint8_t resetNewMissedCalls_ = 0; 539 uint64_t vCardSelector_ = 0ULL; 540 uint8_t vCardSelectorOp_ = 0; 541 uint64_t specifiedBitset_ = 0ULL; 542 }; 543 544 /** 545 * @brief Pbap Pce PullvCardEntry Msg for interthread 546 * Pbap Pce PullvCardEntry Msg 547 */ 548 class PbapPcePullvCardEntryMsg { 549 public: PbapPcePullvCardEntryMsg(const std::u16string & name,uint64_t propertySelector,uint8_t format,uint64_t specifiedBitset)550 explicit PbapPcePullvCardEntryMsg( 551 const std::u16string &name, uint64_t propertySelector, uint8_t format, uint64_t specifiedBitset) 552 : name_(name), propertySelector_(propertySelector), format_(format), specifiedBitset_(specifiedBitset) 553 {} 554 555 virtual ~PbapPcePullvCardEntryMsg() = default; 556 GetName()557 std::u16string GetName() const 558 { 559 return name_; 560 } 561 GetPropertySelector()562 uint64_t GetPropertySelector() const 563 { 564 return propertySelector_; 565 } 566 GetFormat()567 uint8_t GetFormat() const 568 { 569 return format_; 570 } 571 GetSpecifiedBitset()572 uint64_t GetSpecifiedBitset() const 573 { 574 return specifiedBitset_; 575 } 576 577 private: 578 std::u16string name_ = u""; 579 uint64_t propertySelector_ = 0ULL; 580 uint8_t format_ = 0; 581 uint64_t specifiedBitset_ = 0ULL; 582 }; 583 584 /** 585 * @brief Pbap Pce abort action Msg for interthread 586 * Pbap Pce abort action Msg 587 */ 588 class PbapPceAbortMsg { 589 public: PbapPceAbortMsg(const std::u16string & name)590 explicit PbapPceAbortMsg(const std::u16string &name) : name_(name) 591 {} 592 593 virtual ~PbapPceAbortMsg() = default; 594 GetName()595 std::u16string GetName() const 596 { 597 return name_; 598 } 599 600 private: 601 std::u16string name_; 602 }; 603 } // namespace bluetooth 604 } // namespace OHOS 605 #endif // PBAP_PCE_HEADER_MSG_H 606