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 namespace Tizen.Network.WiFiDirect
23 [StructLayout(LayoutKind.Sequential)]
24 internal struct DiscoveredPeerStruct
26 [MarshalAsAttribute(UnmanagedType.LPStr)]
27 internal string _name;
29 [MarshalAsAttribute(UnmanagedType.LPStr)]
30 internal string _macAddress;
32 [MarshalAsAttribute(UnmanagedType.LPStr)]
33 internal string _interfaceAddress;
35 internal int _channel;
37 [MarshalAsAttribute(UnmanagedType.I1)]
38 internal bool _isConnected;
40 [MarshalAsAttribute(UnmanagedType.I1)]
41 internal bool _isGroupOwner;
43 [MarshalAsAttribute(UnmanagedType.I1)]
44 internal bool _isPersistentGroupOwner;
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 [StructLayout(LayoutKind.Sequential)]
64 internal struct ConnectedPeerStruct
66 [MarshalAsAttribute(UnmanagedType.LPStr)]
67 internal string _name;
69 [MarshalAsAttribute(UnmanagedType.LPStr)]
70 internal string _ipAddress;
72 [MarshalAsAttribute(UnmanagedType.LPStr)]
73 internal string _macAddress;
75 [MarshalAsAttribute(UnmanagedType.LPStr)]
76 internal string _interfaceAddress;
78 internal int _channel;
80 [MarshalAsAttribute(UnmanagedType.I1)]
81 internal bool _isP2PSupport;
83 internal WiFiDirectPrimaryDeviceType _primaryType;
85 internal WiFiDirectSecondaryDeviceType _secondaryType;
87 internal uint _serviceCount;
89 internal IntPtr _serviceList;
91 [MarshalAsAttribute(UnmanagedType.I1)]
92 internal bool _isMiracast;
95 internal static class WiFiDirectUtils
97 internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer)
99 WiFiDirectPeer resultPeer = new WiFiDirectPeer();
100 resultPeer._peerDeviceName = peer._name;
101 resultPeer._peerMacAddress = peer._macAddress;
102 resultPeer._peerInterfaceAddress = peer._interfaceAddress;
103 resultPeer._peerChannel = peer._channel;
104 resultPeer._isPeerConnected = peer._isConnected;
105 resultPeer._isPeerGroupOwner = peer._isGroupOwner;
106 resultPeer._isPeerPersistentGroupOwner = peer._isPersistentGroupOwner;
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;