ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

api.c
Go to the documentation of this file.
00001 /* $Id: $
00002  *
00003  * COPYRIGHT:        See COPYING in the top level directory
00004  * PROJECT:          ReactOS kernel
00005  * FILE:             subsys/system/dhcp/api.c
00006  * PURPOSE:          DHCP client api handlers
00007  * PROGRAMMER:       arty
00008  */
00009 
00010 #include "rosdhcp.h"
00011 
00012 #define NDEBUG
00013 #include <reactos/debug.h>
00014 
00015 static CRITICAL_SECTION ApiCriticalSection;
00016 
00017 extern HANDLE AdapterStateChangedEvent;
00018 
00019 VOID ApiInit() {
00020     InitializeCriticalSection( &ApiCriticalSection );
00021 }
00022 
00023 VOID ApiLock() {
00024     EnterCriticalSection( &ApiCriticalSection );
00025 }
00026 
00027 VOID ApiUnlock() {
00028     LeaveCriticalSection( &ApiCriticalSection );
00029 }
00030 
00031 VOID ApiFree() {
00032     DeleteCriticalSection( &ApiCriticalSection );
00033 }
00034 
00035 /* This represents the service portion of the DHCP client API */
00036 
00037 DWORD DSLeaseIpAddress( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00038     COMM_DHCP_REPLY Reply;
00039     PDHCP_ADAPTER Adapter;
00040     struct protocol* proto;
00041 
00042     ApiLock();
00043 
00044     Adapter = AdapterFindIndex( Req->AdapterIndex );
00045 
00046     Reply.Reply = Adapter ? 1 : 0;
00047 
00048     if( Adapter ) {
00049         proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
00050         if (proto)
00051             remove_protocol(proto);
00052 
00053         add_protocol( Adapter->DhclientInfo.name,
00054                       Adapter->DhclientInfo.rfdesc, got_one,
00055                       &Adapter->DhclientInfo );
00056 
00057         Adapter->DhclientInfo.client->state = S_INIT;
00058         state_reboot(&Adapter->DhclientInfo);
00059 
00060         if (AdapterStateChangedEvent != NULL)
00061             SetEvent(AdapterStateChangedEvent);
00062     }
00063 
00064     ApiUnlock();
00065 
00066     return Send( &Reply );
00067 }
00068 
00069 DWORD DSQueryHWInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00070     COMM_DHCP_REPLY Reply;
00071     PDHCP_ADAPTER Adapter;
00072 
00073     ApiLock();
00074 
00075     Adapter = AdapterFindIndex( Req->AdapterIndex );
00076 
00077     Reply.Reply = Adapter ? 1 : 0;
00078 
00079     if (Adapter) {
00080         Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex;
00081         Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType;
00082         Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu;
00083         Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed;
00084     }
00085 
00086     ApiUnlock();
00087 
00088     return Send( &Reply );
00089 }
00090 
00091 DWORD DSReleaseIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00092     COMM_DHCP_REPLY Reply;
00093     PDHCP_ADAPTER Adapter;
00094     struct protocol* proto;
00095 
00096     ApiLock();
00097 
00098     Adapter = AdapterFindIndex( Req->AdapterIndex );
00099 
00100     Reply.Reply = Adapter ? 1 : 0;
00101 
00102     if( Adapter ) {
00103         if (Adapter->NteContext)
00104         {
00105             DeleteIPAddress( Adapter->NteContext );
00106             Adapter->NteContext = 0;
00107         }
00108         if (Adapter->RouterMib.dwForwardNextHop)
00109         {
00110             DeleteIpForwardEntry( &Adapter->RouterMib );
00111             Adapter->RouterMib.dwForwardNextHop = 0;
00112         }
00113 
00114         proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
00115         if (proto)
00116            remove_protocol(proto);
00117 
00118         Adapter->DhclientInfo.client->active = NULL;
00119         Adapter->DhclientInfo.client->state = S_INIT;
00120 
00121         if (AdapterStateChangedEvent != NULL)
00122             SetEvent(AdapterStateChangedEvent);
00123     }
00124 
00125     ApiUnlock();
00126 
00127     return Send( &Reply );
00128 }
00129 
00130 DWORD DSRenewIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00131     COMM_DHCP_REPLY Reply;
00132     PDHCP_ADAPTER Adapter;
00133     struct protocol* proto;
00134 
00135     ApiLock();
00136 
00137     Adapter = AdapterFindIndex( Req->AdapterIndex );
00138 
00139     if( !Adapter || Adapter->DhclientState.state == S_STATIC ) {
00140         Reply.Reply = 0;
00141         ApiUnlock();
00142         return Send( &Reply );
00143     }
00144 
00145     Reply.Reply = 1;
00146 
00147     proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
00148     if (proto)
00149         remove_protocol(proto);
00150 
00151     add_protocol( Adapter->DhclientInfo.name,
00152                   Adapter->DhclientInfo.rfdesc, got_one,
00153                   &Adapter->DhclientInfo );
00154 
00155     Adapter->DhclientInfo.client->state = S_INIT;
00156     state_reboot(&Adapter->DhclientInfo);
00157 
00158     if (AdapterStateChangedEvent != NULL)
00159         SetEvent(AdapterStateChangedEvent);
00160 
00161     ApiUnlock();
00162 
00163     return Send( &Reply );
00164 }
00165 
00166 DWORD DSStaticRefreshParams( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00167     NTSTATUS Status;
00168     COMM_DHCP_REPLY Reply;
00169     PDHCP_ADAPTER Adapter;
00170     struct protocol* proto;
00171 
00172     ApiLock();
00173 
00174     Adapter = AdapterFindIndex( Req->AdapterIndex );
00175 
00176     Reply.Reply = Adapter ? 1 : 0;
00177 
00178     if( Adapter ) {
00179         if (Adapter->NteContext)
00180         {
00181             DeleteIPAddress( Adapter->NteContext );
00182             Adapter->NteContext = 0;
00183         }
00184         if (Adapter->RouterMib.dwForwardNextHop)
00185         {
00186             DeleteIpForwardEntry( &Adapter->RouterMib );
00187             Adapter->RouterMib.dwForwardNextHop = 0;
00188         }
00189         
00190         Adapter->DhclientState.state = S_STATIC;
00191         proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
00192         if (proto)
00193             remove_protocol(proto);
00194         Status = AddIPAddress( Req->Body.StaticRefreshParams.IPAddress,
00195                                Req->Body.StaticRefreshParams.Netmask,
00196                                Req->AdapterIndex,
00197                                &Adapter->NteContext,
00198                                &Adapter->NteInstance );
00199         Reply.Reply = NT_SUCCESS(Status);
00200 
00201         if (AdapterStateChangedEvent != NULL)
00202             SetEvent(AdapterStateChangedEvent);
00203     }
00204 
00205     ApiUnlock();
00206 
00207     return Send( &Reply );
00208 }
00209 
00210 DWORD DSGetAdapterInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
00211     COMM_DHCP_REPLY Reply;
00212     PDHCP_ADAPTER Adapter;
00213 
00214     ApiLock();
00215 
00216     Adapter = AdapterFindIndex( Req->AdapterIndex );
00217 
00218     Reply.Reply = Adapter ? 1 : 0;
00219 
00220     if( Adapter ) {
00221         Reply.GetAdapterInfo.DhcpEnabled = (S_STATIC != Adapter->DhclientState.state);
00222         if (S_BOUND == Adapter->DhclientState.state) {
00223             if (sizeof(Reply.GetAdapterInfo.DhcpServer) ==
00224                 Adapter->DhclientState.active->serveraddress.len) {
00225                 memcpy(&Reply.GetAdapterInfo.DhcpServer,
00226                        Adapter->DhclientState.active->serveraddress.iabuf,
00227                        Adapter->DhclientState.active->serveraddress.len);
00228             } else {
00229                 DPRINT1("Unexpected server address len %d\n",
00230                         Adapter->DhclientState.active->serveraddress.len);
00231                 Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
00232             }
00233             Reply.GetAdapterInfo.LeaseObtained = Adapter->DhclientState.active->obtained;
00234             Reply.GetAdapterInfo.LeaseExpires = Adapter->DhclientState.active->expiry;
00235         } else {
00236             Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
00237             Reply.GetAdapterInfo.LeaseObtained = 0;
00238             Reply.GetAdapterInfo.LeaseExpires = 0;
00239         }
00240     }
00241 
00242     ApiUnlock();
00243 
00244     return Send( &Reply );
00245 }

Generated on Sat May 26 2012 04:20:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.