• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 # Copyright (C) 2024 HiHope Open Source Organization .
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 
17 #include <stdbool.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include "securec.h"
22 #include "ohos_sle_common.h"
23 #include "ohos_sle_errcode.h"
24 #include "ohos_sle_ssap_server.h"
25 #include "ohos_sle_ssap_client.h"
26 #include "ohos_sle_device_discovery.h"
27 #include "ohos_sle_connection_manager.h"
28 
29 #define SLE_OH_LOG "[SLE_OH_LOG]"
30 
31 //设置本地设备地址,返回1设置成功,返回0设置失败
SetLocalSleAddress(SleAddr * addr)32 bool  SetLocalSleAddress(SleAddr *addr){
33     sle_addr_t sle_addr = {};
34     sle_addr.type  = 0;
35     memcpy(sle_addr.addr,addr->addr,OH_SLE_ADDR_LEN);
36     ErrCodeType errcode = sle_set_local_addr(&sle_addr);
37 	  if(errcode == 0){
38 		  return 1;
39 	  }else{
40 		  return 0;
41 	  }
42 }
43 
44 //注销 SSAP client
SsapcRegisterUnregister(uint8_t clientId)45 ErrCodeType  SsapcRegisterUnregister(uint8_t clientId){
46 	return ssapc_unregister_client(clientId);
47 }
48 
49 //客户端向对端发送写请求
SsapcWriteReq(uint8_t clientId,uint16_t connId,SsapcWriteParam * param)50 ErrCodeType SsapcWriteReq(uint8_t clientId, uint16_t connId, SsapcWriteParam *param){
51   ssapc_write_param_t ssapc_write_param = {};
52   ssapc_write_param.handle = param->handle;
53   ssapc_write_param.type = param->type;
54   ssapc_write_param.data_len = param->dataLen;
55   ssapc_write_param.data = param->data;
56   ErrCodeType errcode = ssapc_write_req(clientId,connId,&ssapc_write_param);
57  	return errcode;
58 }
59 
60 
61 //注册SSAP server
SsapsRegisterServer(SleUuid * appUuid,uint8_t * serverId)62 ErrCodeType SsapsRegisterServer(SleUuid *appUuid, uint8_t *serverId){
63   sle_uuid_t sle_uuid = {};
64   sle_uuid.len = appUuid->len;
65   memcpy(sle_uuid.uuid,appUuid->uuid,appUuid->len);
66   ErrCodeType errcode = ssaps_register_server(&sle_uuid,serverId);
67  	return errcode;
68  }
69 
70 //添加SSAP server
SsapsAddService(uint8_t serviceId,SleUuid * serviceUuid,bool isPrimary,uint16_t * handle)71 ErrCodeType SsapsAddService(uint8_t serviceId, SleUuid *serviceUuid, bool isPrimary, uint16_t *handle){
72    (void)handle;
73    sle_uuid_t sle_uuid = {};
74    sle_uuid.len = serviceUuid->len;
75    memcpy(sle_uuid.uuid,serviceUuid->uuid,serviceUuid->len);
76    ErrCodeType errcode = ssaps_add_service(serviceId, serviceUuid, isPrimary);
77    return errcode;
78 }
79 
80 //添加属性
SsapsAddProperty(uint8_t serviceId,uint16_t serviceHandle,SsapsPropertyInfo * property,uint16_t * handle)81 ErrCodeType  SsapsAddProperty(uint8_t serviceId, uint16_t serviceHandle, SsapsPropertyInfo *property, uint16_t *handle){
82   (void)handle;
83   ssaps_property_info_t sle_property = {};
84   sle_property.uuid.len = property->uuid.len;
85   memcpy(sle_property.uuid.uuid,property->uuid.uuid,property->uuid.len);
86   sle_property.permissions = property->permissions;
87   sle_property.operate_indication = property->operateIndication;
88   sle_property.value_len = property->valueLen;
89   sle_property.value = property->value;
90   ErrCodeType errcode = ssaps_add_property(serviceId, serviceHandle, &sle_property);
91   return errcode;
92 }
93 
94 
95 //添加描述符
SsapsAddDescriptor(uint8_t serviceId,uint16_t serviceHandle,uint16_t propertyHandle,SsapsDescInfo * descriptor)96 ErrCodeType SsapsAddDescriptor(uint8_t serviceId, uint16_t serviceHandle, uint16_t propertyHandle,
97     SsapsDescInfo *descriptor){
98   ssaps_desc_info_t ssaps_desc_info = {};
99   ssaps_desc_info.uuid.len = descriptor->uuid.len;
100   memcpy(ssaps_desc_info.uuid.uuid,descriptor->uuid.uuid,descriptor->uuid.len);
101   ssaps_desc_info.permissions = descriptor->permissions;
102   ssaps_desc_info.operate_indication = descriptor->operateIndication;
103   ssaps_desc_info.value_len = descriptor->valueLen;
104   ssaps_desc_info.value = descriptor->value;
105   ErrCodeType errcode = ssaps_add_descriptor(serviceId, serviceHandle, propertyHandle,&ssaps_desc_info);
106   return errcode;
107 }