Skip to content

Commit f618129

Browse files
committed
- reverts FLAVOR_WIN changes from NETMF#399 to fix build targeting windows (emulator and the new Windows native build this commit is adding)
- Added LONG and ULONG typedefs for compat. with WIn32 builds - Fixed calls to Interlocked API declarations and calls to use LONG to match windows API (Its still a 32 bit integer so no functional change) - updated Lwip and sockets vcxproj files to VS14 - Added DeviceCode\Targets\OS\Win32 for the native Win32 OS porting - Added Solutions\Windows for native Win32 OS port solution - Update solution file to VS14 as it wasn't saved for last commit - reverting NETMF#392 as it was choking on malformed paths - updated uvision files, git ignore and added readme.md for crypto
1 parent 7a4f4e3 commit f618129

File tree

98 files changed

+9377
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+9377
-48
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ License (Crypto).rtf
4747
PKCryptoWelcome.rtf
4848
REDIST_CRYPTO.TXT
4949
ReleaseNotesCrypto.txt
50+
*.tlog
51+
/Solutions/Windows/TinyCLR/Debug
52+
/Solutions/Windows/TinyCLR/FLASH_MEMORY.bin
53+
*.opendb
54+
*.dbgconf
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// This file is part of the Microsoft .NET Micro Framework Porting Kit Code Samples and is unsupported.
3+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License.
6+
// You may obtain a copy of the License at:
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
//
14+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15+
16+
#include <OsIrqLock.h>
17+
18+
namespace
19+
{
20+
class CriticalSection
21+
{
22+
public:
23+
CriticalSection( )
24+
{
25+
::InitializeCriticalSection( &CritSect );
26+
}
27+
28+
void lock( )
29+
{
30+
::EnterCriticalSection( &CritSect );
31+
Owner = ::GetCurrentThreadId();
32+
}
33+
34+
void unlock( )
35+
{
36+
ASSERT( owned() );
37+
if( !owned() )
38+
return;
39+
40+
Owner = UINT32_MAX;
41+
::LeaveCriticalSection( &CritSect );
42+
}
43+
44+
bool owned() { return ::GetCurrentThreadId() == Owner; }
45+
46+
static bool InIsr()
47+
{
48+
return false;
49+
}
50+
51+
private:
52+
DWORD Owner;
53+
CRITICAL_SECTION CritSect;
54+
};
55+
}
56+
57+
// Mutex, and state flag used to indicate global IRQ enable state.
58+
// The CLR thread will block on this as it is used to simulate
59+
// disabling/enabling interrupts in the CPU as well as when an ISR
60+
// runs. Background threads in the OS essentially simulate real world
61+
// external activity and interrupts to the CPU, so they must block
62+
// on this mutex before they can modify CLR global data structs etc...
63+
typedef MsOpenTech::NETMF::OsIrqLock< CriticalSection > Lock_t;
64+
static Lock_t IrqsEnabledMutex;
65+
66+
// IRQ state modeling how most MCUs use bit(s) in a global status register
67+
// this helps make the code easier to port and also allows for simple
68+
// testing of the current state.
69+
static uint32_t IrqsEnabledState = 0;
70+
const uint32_t IrqsDisabledFlag = 1;
71+
72+
inline bool IrqsDisabled( uint32_t state )
73+
{
74+
return ( state & IrqsDisabledFlag ) == IrqsDisabledFlag;
75+
}
76+
77+
inline bool IrqsEnabled( uint32_t state )
78+
{
79+
return ( state & IrqsDisabledFlag ) == 0;
80+
}
81+
82+
// internal function to simulate common interrupt enable state query for embedded MCUs
83+
inline bool irqs_enabled( )
84+
{
85+
return IrqsEnabled( IrqsEnabledState );
86+
}
87+
88+
// internal function to simulate common interrupt enable intrinsics for embedded MCUs
89+
uint32_t enable_irqs( )
90+
{
91+
// capture and update current state with lock held
92+
uint32_t retVal = IrqsEnabledState;
93+
IrqsEnabledState &= ~IrqsDisabledFlag;
94+
IrqsEnabledMutex.unlock( );
95+
return retVal;
96+
}
97+
98+
// internal function to simulate common interrupt disable intrinsics for embedded MCUs
99+
uint32_t disable_irqs( )
100+
{
101+
IrqsEnabledMutex.lock( );
102+
// capture and update current state with lock held
103+
uint32_t retVal = IrqsEnabledState;
104+
IrqsEnabledState |= IrqsDisabledFlag;
105+
return retVal;
106+
}
107+
108+
// allow an "interrupt" to occur
109+
inline void irq_yield()
110+
{
111+
//__NOP();
112+
if( !::SwitchToThread( ) )
113+
::Sleep( 0 );
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The WinPcap_Eth driver interface is dependent on library files from the
2+
WinPcap Developer Pack. These files are not included in the NETMF source
3+
distribution. In order to sucesfully compile and use the WinPCAP Ethernet
4+
driver for NETMF you first need to download the WinPcap Developer Pack
5+
from:
6+
7+
http://www.winpcap.org/devel.htm
8+
9+
Unzip the contents and copy the "WpdPack" folder and its subfolders to:
10+
"$(SPOCLIENT)\DeviceCode\Targets\OS\Win32\DeviceCode\WinPcap_Eth\Dependencies\"
11+
12+
The final directory structure should look like this:
13+
14+
$(SPOCLIENT)\DeviceCode\Targets\OS\Win32\DeviceCode\WinPcap_Eth\Dependencies\WpdPack\
15+
|-- docs
16+
|-- Examples-pcap
17+
|-- Examples-remote
18+
|-- Include
19+
|-- Lib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4+
5+
#include <tinyhal.h>
6+
#include <lwip\netif.h>
7+
#include <lwip\tcpip.h>
8+
#include <lwip\dhcp.h>
9+
#include <netif\etharp.h>
10+
11+
#include "WinPcap_Eth_lwIP_Adapter.h"
12+
13+
extern "C"
14+
{
15+
#include "pcapif.h"
16+
}
17+
18+
extern WINPCAP_ETH_LWIP_DEVICE_CONFIG g_WINPCAP_ETH_LWIP_Config;
19+
extern NETWORK_CONFIG g_NetworkConfig;
20+
21+
static BOOL LwipNetworkStatus = FALSE;
22+
static struct netif g_WinPcap_ETH_NetIF;
23+
24+
static WINPCAP_ETH_LWIP_Driver g_WINPCAP_ETH_LWIP_Driver;
25+
26+
BOOL Network_Interface_Bind(int index)
27+
{
28+
NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();
29+
30+
return g_WINPCAP_ETH_LWIP_Driver.Bind();
31+
}
32+
33+
int Network_Interface_Open(int index)
34+
{
35+
NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();
36+
if(index >= ARRAYSIZE(g_WINPCAP_ETH_LWIP_Config.DeviceConfigs))
37+
return -1;
38+
39+
HAL_CONFIG_BLOCK::ApplyConfig( WINPCAP_ETH_LWIP_DEVICE_CONFIG::GetDriverName(), &g_WINPCAP_ETH_LWIP_Config, sizeof(g_WINPCAP_ETH_LWIP_Config) );
40+
41+
return g_WINPCAP_ETH_LWIP_Driver.Open(&g_WINPCAP_ETH_LWIP_Config.DeviceConfigs[index], index);
42+
}
43+
44+
BOOL Network_Interface_Close(int index)
45+
{
46+
NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();
47+
48+
return g_WINPCAP_ETH_LWIP_Driver.Close(index);
49+
}
50+
51+
int WINPCAP_ETH_LWIP_Driver::Open(WINPCAP_ETH_LWIP_DRIVER_CONFIG* config, int index)
52+
{
53+
/* Network interface variables */
54+
struct ip_addr ipaddr, subnetmask, gateway;
55+
BOOL isDHCPenabled;
56+
const SOCK_NetworkConfiguration *iface;
57+
58+
if(config == NULL)
59+
{
60+
return -1;
61+
}
62+
63+
/* Apply network configuration */
64+
iface = &g_NetworkConfig.NetworkInterfaces[index];
65+
isDHCPenabled = (iface->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP)? TRUE: FALSE;
66+
67+
if(!isDHCPenabled)
68+
{
69+
/* Set network address variables for static ip configuration */
70+
ipaddr.addr = iface->ipaddr;
71+
gateway.addr = iface->gateway;
72+
subnetmask.addr = iface->subnetmask;
73+
}
74+
else
75+
{
76+
/* Set network address variables - this will be set by either DHCP or when the configuration is applied */
77+
IP4_ADDR(&gateway, 0, 0, 0, 0);
78+
IP4_ADDR(&ipaddr , 0, 0, 0, 0);
79+
IP4_ADDR(&subnetmask, 255, 255, 255, 0);
80+
}
81+
82+
/* Configure the MAC address */
83+
if(iface->macAddressLen != ETHARP_HWADDR_LEN)
84+
{
85+
return -1;
86+
}
87+
88+
memcpy(g_WinPcap_ETH_NetIF.hwaddr, iface->macAddressBuffer, iface->macAddressLen);
89+
90+
auto pNetIf = netif_add( &g_WinPcap_ETH_NetIF, &ipaddr, &subnetmask, &gateway, (void*) config->adapterGuid, pcapif_init, tcpip_input );
91+
if( pNetIf == nullptr )
92+
return -1;
93+
94+
netif_set_default( &g_WinPcap_ETH_NetIF );
95+
96+
LwipNetworkStatus = TRUE;
97+
98+
return g_WinPcap_ETH_NetIF.num;
99+
}
100+
101+
BOOL WINPCAP_ETH_LWIP_Driver::Close(int index)
102+
{
103+
const SOCK_NetworkConfiguration *iface;
104+
105+
LwipNetworkStatus = FALSE;
106+
107+
iface = &g_NetworkConfig.NetworkInterfaces[index];
108+
109+
netif_remove( &g_WinPcap_ETH_NetIF );
110+
111+
pcapif_shutdown(&g_WinPcap_ETH_NetIF);
112+
113+
memset( &g_WinPcap_ETH_NetIF, 0, sizeof g_WinPcap_ETH_NetIF );
114+
115+
return TRUE;
116+
}
117+
118+
/* Bind function doesn't actually do anything for this implementation */
119+
BOOL WINPCAP_ETH_LWIP_Driver::Bind(void)
120+
{
121+
return TRUE;
122+
}
123+
124+
125+
126+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4+
5+
#include <tinyhal.h>
6+
7+
#ifndef _WINPCAP_ETH_LWIP_ADAPTER_H_
8+
#define _WINPCAP_ETH_LWIP_ADAPTER_H_ 1
9+
// 1 2 3
10+
//01234567890123456789012345678901234567
11+
//{00000000-0000-0000-0000-000000000000}
12+
const size_t GuidStringLen = 39; //38 chars + 1 for terminating \0
13+
14+
struct WINPCAP_ETH_LWIP_DRIVER_CONFIG
15+
{
16+
char adapterGuid[GuidStringLen];
17+
};
18+
19+
#ifndef NETWORK_INTERFACE_COUNT
20+
#define NETWORK_INTERFACE_COUNT 1
21+
#endif
22+
23+
struct WINPCAP_ETH_LWIP_DEVICE_CONFIG
24+
{
25+
WINPCAP_ETH_LWIP_DRIVER_CONFIG DeviceConfigs[ NETWORK_INTERFACE_COUNT ];
26+
27+
static LPCSTR GetDriverName( )
28+
{
29+
return "WINPCAP_ETH_LWIP";
30+
}
31+
};
32+
33+
struct WINPCAP_ETH_LWIP_Driver
34+
{
35+
static int Open( WINPCAP_ETH_LWIP_DRIVER_CONFIG* config, int index );
36+
static BOOL Close( int index );
37+
static BOOL Bind( void );
38+
};
39+
40+
//
41+
// _WINPCAP_ETH_LWIP_ADAPTER_H_
42+
//////////////////////////////////////////////////////////////////////////////
43+
44+
#endif
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<AssemblyName>WinPcap_Eth</AssemblyName>
5+
<Size>
6+
</Size>
7+
<ProjectGuid>{8BA0D2BB-CAFA-4279-BB5D-9013ABEFF9B5}</ProjectGuid>
8+
<Description>WinPcap Ethernet Driver</Description>
9+
<Level>HAL</Level>
10+
<LibraryFile>WinPcap_Eth.$(LIB_EXT)</LibraryFile>
11+
<ProjectPath>$(SPOCLIENT)\DeviceCode\Targets\OS\Win32\DeviceCode\WinPcap_Eth\dotNetMF.proj</ProjectPath>
12+
<ManifestFile>WinPcap_Eth.$(LIB_EXT).manifest</ManifestFile>
13+
<PlatformIndependent>False</PlatformIndependent>
14+
<CustomFilter>
15+
</CustomFilter>
16+
<Required>False</Required>
17+
<IgnoreDefaultLibPath>False</IgnoreDefaultLibPath>
18+
<IsStub>False</IsStub>
19+
<Directory>DeviceCode\Targets\OS\Win32\DeviceCode\WinPcap_Eth</Directory>
20+
<OutputType>Library</OutputType>
21+
<PlatformIndependentBuild>false</PlatformIndependentBuild>
22+
<Version>4.0.0.0</Version>
23+
</PropertyGroup>
24+
<Import Project="$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Settings" />
25+
<PropertyGroup />
26+
<ItemGroup>
27+
<IncludePaths Include="DeviceCode\pal\lwip_1_4_1_os\LWIP\src\include" />
28+
<IncludePaths Include="DeviceCode\pal\lwip_1_4_1_os\LWIP\src\include\lwip" />
29+
<!-- lwIP does NOT support ipv4 and ipv6 at the same time -->
30+
<IncludePaths Include="DeviceCode\pal\lwip_1_4_1_os\LWIP\src\include\ipv4" />
31+
<IncludePaths Include="DeviceCode\pal\lwip_1_4_1_os\LWIP\src\include\netif" />
32+
<IncludePaths Include="DeviceCode\Targets\OS\Win32\lwip_1_4_1_os\arch" />
33+
<IncludePaths Include="DeviceCode\Targets\OS\Win32\DeviceCode\WinPcap_Eth\Dependencies\WpdPack\Include" />
34+
<HFiles Include="WinPcap_Eth_lwIP_Adapter.h" />
35+
<HFiles Include="pcapif.h" />
36+
<HFiles Include="pcapif_helper.h" />
37+
<Compile Include="WinPcap_Eth_lwIP_Adapter.cpp" />
38+
<Compile Include="pcapif.c" />
39+
<Compile Include="pcapif_helper.c" />
40+
</ItemGroup>
41+
<Import Project="$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Targets" />
42+
</Project>

0 commit comments

Comments
 (0)