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 internal WiFiDirectPrimaryDeviceType _primaryType;
45 internal WiFiDirectSecondaryDeviceType _secondaryType;
47 internal int _wpsTypes;
49 [MarshalAsAttribute(UnmanagedType.I1)]
50 internal bool _isP2PInvitationSupported;
52 internal uint _serviceCount;
54 internal IntPtr _serviceList;
56 [MarshalAsAttribute(UnmanagedType.I1)]
57 internal bool _isMiracast;
59 [StructLayout(LayoutKind.Sequential)]
60 internal struct ConnectedPeerStruct
62 [MarshalAsAttribute(UnmanagedType.LPStr)]
63 internal string _name;
65 [MarshalAsAttribute(UnmanagedType.LPStr)]
66 internal string _ipAddress;
68 [MarshalAsAttribute(UnmanagedType.LPStr)]
69 internal string _macAddress;
71 [MarshalAsAttribute(UnmanagedType.LPStr)]
72 internal string _interfaceAddress;
74 internal int _channel;
76 [MarshalAsAttribute(UnmanagedType.I1)]
77 internal bool _isP2PSupport;
79 internal WiFiDirectPrimaryDeviceType _primaryType;
81 internal WiFiDirectSecondaryDeviceType _secondaryType;
83 internal uint _serviceCount;
85 internal IntPtr _serviceList;
87 [MarshalAsAttribute(UnmanagedType.I1)]
88 internal bool _isMiracast;
91 internal static class WiFiDirectUtils
93 internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer)
95 WiFiDirectPeer resultPeer = new WiFiDirectPeer();
96 resultPeer._peerDeviceName = peer._name;
97 resultPeer._peerMacAddress = peer._macAddress;
98 resultPeer._peerInterfaceAddress = peer._interfaceAddress;
99 resultPeer._peerChannel = peer._channel;
100 resultPeer._isPeerConnected = peer._isConnected;
101 resultPeer._isPeerGroupOwner = peer._isGroupOwner;
102 resultPeer._peerPrimaryType = peer._primaryType;
103 resultPeer._peerSecondaryType = peer._secondaryType;
104 resultPeer._peerWpsTypes = peer._wpsTypes;
105 resultPeer._p2PInvitationSupported = peer._isP2PInvitationSupported;
106 Collection<string> uuidList = null;
108 if (peer._serviceCount > 0)
110 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
111 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
112 uuidList = new Collection<string>();
113 foreach (IntPtr service in serviceList)
115 string registeredService = Marshal.PtrToStringAnsi(service);
116 uuidList.Add(registeredService);
119 resultPeer._peerServiceCount = peer._serviceCount;
120 resultPeer._peerServiceList = uuidList;
123 resultPeer._isPeerMiracastDevice = peer._isMiracast;
127 internal static WiFiDirectPeer ConvertStructToConnectedPeer(ConnectedPeerStruct peer)
129 WiFiDirectPeer resultPeer = new WiFiDirectPeer();
130 resultPeer._peerDeviceName = peer._name;
131 resultPeer._peerIpAddress = peer._ipAddress;
132 resultPeer._peerMacAddress = peer._macAddress;
133 resultPeer._peerInterfaceAddress = peer._interfaceAddress;
134 resultPeer._peerChannel = peer._channel;
135 resultPeer._peerP2PSupport = peer._isP2PSupport;
136 resultPeer._peerPrimaryType = peer._primaryType;
137 resultPeer._peerSecondaryType = peer._secondaryType;
138 Collection<string> uuidList = null;
140 if (peer._serviceCount > 0)
142 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
143 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
144 uuidList = new Collection<string>();
145 foreach (IntPtr service in serviceList)
147 string registeredService = Marshal.PtrToStringAnsi(service);
148 uuidList.Add(registeredService);
151 resultPeer._peerServiceCount = peer._serviceCount;
152 resultPeer._peerServiceList = uuidList;
155 resultPeer._isPeerMiracastDevice = peer._isMiracast;