2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
19 using System.Collections.ObjectModel;
21 using Tizen.Internals;
23 namespace Tizen.Network.WiFiDirect
25 [NativeStruct("wifi_direct_discovered_peer_info_s", Include="wifi-direct.h", PkgConfig="capi-network-wifi-direct")]
26 [StructLayout(LayoutKind.Sequential)]
27 internal struct DiscoveredPeerStruct
29 [MarshalAsAttribute(UnmanagedType.LPStr)]
30 internal string _name;
32 [MarshalAsAttribute(UnmanagedType.LPStr)]
33 internal string _macAddress;
35 [MarshalAsAttribute(UnmanagedType.LPStr)]
36 internal string _interfaceAddress;
38 internal int _channel;
40 [MarshalAsAttribute(UnmanagedType.I1)]
41 internal bool _isConnected;
43 [MarshalAsAttribute(UnmanagedType.I1)]
44 internal bool _isGroupOwner;
46 internal WiFiDirectPrimaryDeviceType _primaryType;
48 internal WiFiDirectSecondaryDeviceType _secondaryType;
50 internal int _wpsTypes;
52 [MarshalAsAttribute(UnmanagedType.I1)]
53 internal bool _isP2PInvitationSupported;
55 internal uint _serviceCount;
57 internal IntPtr _serviceList;
59 [MarshalAsAttribute(UnmanagedType.I1)]
60 internal bool _isMiracast;
63 [NativeStruct("wifi_direct_connected_peer_info_s", Include="wifi-direct.h", PkgConfig="capi-network-wifi-direct")]
64 [StructLayout(LayoutKind.Sequential)]
65 internal struct ConnectedPeerStruct
67 [MarshalAsAttribute(UnmanagedType.LPStr)]
68 internal string _name;
70 [MarshalAsAttribute(UnmanagedType.LPStr)]
71 internal string _ipAddress;
73 [MarshalAsAttribute(UnmanagedType.LPStr)]
74 internal string _macAddress;
76 [MarshalAsAttribute(UnmanagedType.LPStr)]
77 internal string _interfaceAddress;
79 internal int _channel;
81 [MarshalAsAttribute(UnmanagedType.I1)]
82 internal bool _isP2PSupport;
84 internal WiFiDirectPrimaryDeviceType _primaryType;
86 internal WiFiDirectSecondaryDeviceType _secondaryType;
88 internal uint _serviceCount;
90 internal IntPtr _serviceList;
92 [MarshalAsAttribute(UnmanagedType.I1)]
93 internal bool _isMiracast;
96 internal static class WiFiDirectUtils
98 internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer)
100 WiFiDirectPeer resultPeer = new WiFiDirectPeer();
101 resultPeer._peerDeviceName = peer._name;
102 resultPeer._peerMacAddress = peer._macAddress;
103 resultPeer._peerInterfaceAddress = peer._interfaceAddress;
104 resultPeer._peerChannel = peer._channel;
105 resultPeer._isPeerConnected = peer._isConnected;
106 resultPeer._isPeerGroupOwner = peer._isGroupOwner;
107 resultPeer._peerPrimaryType = peer._primaryType;
108 resultPeer._peerSecondaryType = peer._secondaryType;
109 resultPeer._peerWpsTypes = peer._wpsTypes;
110 resultPeer._p2PInvitationSupported = peer._isP2PInvitationSupported;
111 Collection<string> uuidList = null;
113 if (peer._serviceCount > 0)
115 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
116 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
117 uuidList = new Collection<string>();
118 foreach (IntPtr service in serviceList)
120 string registeredService = Marshal.PtrToStringAnsi(service);
121 uuidList.Add(registeredService);
124 resultPeer._peerServiceCount = peer._serviceCount;
125 resultPeer._peerServiceList = uuidList;
128 resultPeer._isPeerMiracastDevice = peer._isMiracast;
132 internal static WiFiDirectPeer ConvertStructToConnectedPeer(ConnectedPeerStruct peer)
134 WiFiDirectPeer resultPeer = new WiFiDirectPeer();
135 resultPeer._peerDeviceName = peer._name;
136 resultPeer._peerIpAddress = peer._ipAddress;
137 resultPeer._peerMacAddress = peer._macAddress;
138 resultPeer._peerInterfaceAddress = peer._interfaceAddress;
139 resultPeer._peerChannel = peer._channel;
140 resultPeer._peerP2PSupport = peer._isP2PSupport;
141 resultPeer._peerPrimaryType = peer._primaryType;
142 resultPeer._peerSecondaryType = peer._secondaryType;
143 Collection<string> uuidList = null;
145 if (peer._serviceCount > 0)
147 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
148 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
149 uuidList = new Collection<string>();
150 foreach (IntPtr service in serviceList)
152 string registeredService = Marshal.PtrToStringAnsi(service);
153 uuidList.Add(registeredService);
156 resultPeer._peerServiceCount = peer._serviceCount;
157 resultPeer._peerServiceList = uuidList;
160 resultPeer._isPeerMiracastDevice = peer._isMiracast;