Changeset 8052 for trunk/src


Ignore:
Timestamp:
Mar 8, 2002, 12:37:56 PM (23 years ago)
Author:
sandervl
Message:

PH: Netbios updates (currently disabled)

Location:
trunk/src/wnetap32
Files:
2 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wnetap32/makefile

    r6676 r8052  
    1 # $Id: makefile,v 1.19 2001-09-07 08:20:58 phaller Exp $
     1# $Id: makefile,v 1.20 2002-03-08 11:37:10 sandervl Exp $
    22
    33#
     
    4242$(ODIN32_LIB)/user32.lib \
    4343$(ODIN32_LIB)/$(ODINCRT).lib \
     44netapi32.lib \
    4445OS2386.LIB \
    4546$(RTLLIB_O)
     
    4748
    4849#
    49 # Target and original target names - names of the dll without extention and path
     50# Target and original target names - names of the dll without extension and path
    5051#
     52# @@@PH TARGET      = wnetap32
     53# @@@PH ORGTARGET   = netapi32
    5154TARGET      = wnetap32
    52 ORGTARGET   = netapi32
    53 
    5455
    5556#
  • trunk/src/wnetap32/oslibnet.cpp

    r6672 r8052  
    1 /*  $Id: oslibnet.cpp,v 1.5 2001-09-06 22:23:40 phaller Exp $
     1/*  $Id: oslibnet.cpp,v 1.6 2002-03-08 11:37:10 sandervl Exp $
    22 *
    33 * Wrappers for OS/2 Netbios/Network/LAN API
     
    3030#include <netstats.h>
    3131#include <server.h>
     32#include <ncb.h>
     33#include <netbios.h>
     34// #include <netb_1_c.h>
     35// #include <netb_2_c.h>
     36// #include <netb_4_c.h>
     37
     38#include "wnetap32.h"
     39#include "oslibnet.h"
    3240
    3341
     
    301309  return rc;
    302310}
     311
     312
     313/*****************************************************************************
     314 * Name      : OSLibNetBIOS
     315 * Purpose   :
     316 * Parameters: PNCB pncb (Win32-style of the structure!!!)
     317 * Variables :
     318 * Result    :
     319 * Remark    :
     320 * Status    : TESTED
     321 *
     322 * Author    : Patrick Haller 2002/02/26 01:42
     323 *****************************************************************************/
     324
     325UCHAR OSLibNetBIOS_Passthru(PNCB_w pncb)
     326{
     327  // IBM NETBIOS 3.0 as defined in ncb.h
     328  // UCHAR rc = NetBios( (struct ncb LSFAR *)pncb );
     329 
     330  // Note:
     331  // asynchronous operation probably not really supported here,
     332  // this has to be done with a wrapper thread!
     333 
     334  // @@@PH
     335  // open / close the right adapter based upon
     336  // the LANA number specified inside the NCB
     337 
     338  USHORT sel = RestoreOS2FS();
     339  UCHAR rc = NetBios32Submit(0, // send automatically to first adapter
     340                                // open & close are implicit
     341                             0, // single NCB w/o error retry!
     342                             (struct ncb LSFAR *)pncb );
     343  SetFS(sel);
     344  return rc;
     345}
     346
     347
     348/*****************************************************************************
     349 * Name      : OSLibNetBIOSEnum
     350 * Purpose   :
     351 * Parameters: PNCB pncb (Win32-style of the structure!!!)
     352 * Variables :
     353 * Result    :
     354 * Remark    :
     355 * Status    : TESTED
     356 *
     357 * Author    : Patrick Haller 2002/02/26 01:42
     358 *****************************************************************************/
     359
     360UCHAR OSLibNetBIOS_Enum(PNCB_w pncb)
     361{
     362  static BOOL flagEnumAvailable = FALSE;
     363  static UCHAR arrLANA[ MAX_LANA_w ];
     364  static int iLANALength = 0;
     365  USHORT sel = RestoreOS2FS();
     366
     367  if (FALSE == flagEnumAvailable)
     368  {
     369    ULONG ulEntriesReturned  = 0;
     370    ULONG ulEntriesAvailable = 0;
     371    ULONG rc;
     372    PVOID pBuffer;
     373    ULONG ulBufferLength;
     374    struct netbios_info_1* pNBI1;
     375   
     376    // reset the array first
     377    memset( arrLANA, 0, sizeof( arrLANA ) );
     378   
     379   
     380    // determine number of available entries
     381    rc = NetBios32Enum(NULL,
     382                       0,
     383                       NULL,
     384                       0,
     385                       &ulEntriesReturned,
     386                       &ulEntriesAvailable);
     387   
     388    // if network adapters are available ...
     389    iLANALength = ulEntriesAvailable;
     390    if (0 != ulEntriesAvailable)
     391    {
     392      // allocate buffer of sufficient size
     393      ulBufferLength = ulEntriesAvailable * sizeof( struct netbios_info_1 );
     394      pBuffer = malloc( ulBufferLength );
     395      if (NULL == pBuffer)
     396      {
     397        SetFS(sel);
     398        pncb->ncb_retcode  = NRC_SYSTEM_w;
     399        return NRC_SYSTEM_w;
     400      }
     401       
     402      // enumerate all network drivers (net1, net2, ...)
     403      // and build the array of LANA numbers
     404      rc = NetBios32Enum(NULL,  // local machine
     405                         1,
     406                         (PUCHAR)pBuffer,
     407                         ulBufferLength,
     408                         &ulEntriesReturned,
     409                         &ulEntriesAvailable);
     410      pNBI1 = (struct netbios_info_1 *)pBuffer;
     411      for (ULONG ulCount = 0;
     412           ulCount < ulEntriesReturned;
     413           ulCount++)
     414      {
     415        arrLANA[ ulCount ] = pNBI1->nb1_lana_num;
     416        pNBI1++;
     417      }
     418     
     419      free( pBuffer );
     420    }
     421    // else no network adapters are available
     422   
     423    flagEnumAvailable = TRUE;
     424  }
     425 
     426  // copy the result
     427  PLANA_ENUM_w pLE = (PLANA_ENUM_w)pncb->ncb_buffer;
     428  pLE->length      = iLANALength;
     429 
     430  // compensate UCHAR size for the length field
     431  memcpy( pLE->lana,
     432          arrLANA,
     433          pncb->ncb_length - sizeof(UCHAR) );
     434  pncb->ncb_retcode  = NRC_GOODRET_w;
     435         
     436  SetFS(sel);
     437  return pncb->ncb_retcode;
     438}
     439
     440
     441
     442
     443/*****************************************************************************
     444 * Name      : OSLibNetBIOS
     445 * Purpose   :
     446 * Parameters: PNCB pncb (Win32-style of the structure!!!)
     447 * Variables :
     448 * Result    :
     449 * Remark    : this is for synchronous operation only!
     450 * Status    : TESTED
     451 *
     452 * Author    : Patrick Haller 2002/02/26 01:42
     453 *****************************************************************************/
     454
     455UCHAR OSLibNetBIOS(PNCB_w pncb)
     456{
     457  dprintf(("NETBIOS: Netbios NCB: command=%02xh, retcode=%d, lsn=%d, num=%d, buffer=%08xh, "
     458           "length=%d callname='%s' name='%s' rto=%d sto=%d pfnCallback=%08xh, lana=%d, "
     459           "cmd_cplt=%d event=%08xh\n",
     460           pncb->ncb_command,
     461           pncb->ncb_retcode,
     462           pncb->ncb_lsn,
     463           pncb->ncb_num,
     464           pncb->ncb_buffer,
     465           pncb->ncb_length,
     466           pncb->ncb_callname,
     467           pncb->ncb_name,
     468           pncb->ncb_rto,
     469           pncb->ncb_sto,
     470           pncb->ncb_post,
     471           pncb->ncb_lana_num,
     472           pncb->ncb_cmd_cplt,
     473           pncb->ncb_event));
     474 
     475  // Request Router
     476  // The request router is responsible for mapping the incoming commands
     477  // and NCBs to their OS/2 NetBIOS pendant plus support of synchronous /
     478  // asynchronous handling of NCB processing.
     479 
     480  // Note:
     481  // for a first attempt at NetBIOS support, we just try to pass through
     482  // all supported commands and assume the structures are essentially
     483  // compatible.
     484  UCHAR rc;
     485
     486  switch (pncb->ncb_command & ~ASYNCH_w)
     487  {
     488    case NCBENUM_w:
     489    {
     490      // enumerate all network drivers (net1, net2, ...)
     491      // and build the array of LANA numbers
     492      rc = OSLibNetBIOS_Enum( pncb );
     493      break;
     494    }
     495 
     496    // Note: NCBLANSTALERT_w
     497    // seems to be supported in asynchronous manner only,
     498    // we just try to pass it through!
     499 
     500    case NCBACTION_w:
     501      dprintf(("NCBACTION not yet implemented"));
     502      break;
     503 
     504    case NCBTRACE_w:
     505      dprintf(("NCBTRACE not yet implemented"));
     506      break;
     507   
     508    case NCBRESET_w:
     509      // This seems to cause the requester to go wild
     510      // (netbios session limit exceeded)
     511      // rc = OSLibNetBIOS_Passthru( pncb );
     512   
     513      // Win32 and OS/2 do have different behaviour upon RESET calls.
     514      // Returning OK here is experimental.
     515      pncb->ncb_retcode  = NRC_GOODRET_w;
     516      pncb->ncb_cmd_cplt = NRC_GOODRET_w;
     517      rc = NRC_GOODRET_w;
     518      break;
     519   
     520   
     521    default:
     522      rc = OSLibNetBIOS_Passthru( pncb );
     523      break;
     524  }
     525 
     526  dprintf(("NETBIOS: Netbios NCB: command=%02xh --> rc=%d\n",
     527           pncb->ncb_command,
     528           rc));
     529  return rc;
     530}
     531
     532
     533/*****************************************************************************
     534 * Name      :
     535 * Purpose   :
     536 * Parameters: PNCB pncb (Win32-style of the structure!!!)
     537 * Variables :
     538 * Result    :
     539 * Remark    :
     540 * Status    : TESTED
     541 *
     542 * Author    : Patrick Haller 2002/02/26 01:42
     543 *****************************************************************************/
     544
     545DWORD WIN32API OSLibNetbiosHlpHandler(LPVOID lpParam)
     546{
     547  PNCB_w pncb = (PNCB_w)lpParam;
     548  UCHAR ncb_cmd_original = pncb->ncb_command;
     549  void (* CALLBACK ncb_post_original)( struct _NCB_w * ) = pncb->ncb_post;
     550
     551  // rewrite ncb for synchronous operation
     552  pncb->ncb_command &= ~ASYNCH_w;
     553  pncb->ncb_post    = 0;
     554  // ncb_cmd_cplt is expected to be NRC_PENDING_w
     555  // when we come here (set by the main Netbios() function)
     556 
     557  // synchronous operation
     558  // return code is expected to be stored inside pncb
     559  dprintf(("NETBIOS: async NETBIOS for command %02xh\n",
     560           pncb->ncb_command));
     561 
     562  OSLibNetBIOS( pncb );
     563 
     564  dprintf(("NETBIOS: async NETBIOS for command %02xh returned %d\n",
     565           pncb->ncb_command,
     566           pncb->ncb_retcode));
     567 
     568  // restore original command
     569  pncb->ncb_command = ncb_cmd_original;
     570  pncb->ncb_post    = ncb_post_original;
     571 
     572  // propagate the command complete value as netbios is expected
     573  // to do for asynchronous operation
     574  pncb->ncb_cmd_cplt= pncb->ncb_retcode;
     575 
     576  // perform post-operation notification!
     577  if (pncb->ncb_event)
     578  {
     579    // Netbios seems to use PulseEvent instead of SetEvent.
     580   
     581    // SetEvent( pncb->ncb_event );
     582    PulseEvent( pncb->ncb_event );
     583  }
     584 
     585  if (pncb->ncb_post != NULL)
     586  {
     587    // callback into post function
     588    (pncb->ncb_post)( pncb );
     589  }
     590 
     591  return pncb->ncb_retcode;
     592}
  • trunk/src/wnetap32/oslibnet.h

    r6672 r8052  
    1 /* $Id: oslibnet.h,v 1.3 2001-09-06 22:23:40 phaller Exp $ */
     1/* $Id: oslibnet.h,v 1.4 2002-03-08 11:37:10 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Netbios/Network/LAN API
     
    1717
    1818#define NERR_OK   0
     19
     20#ifndef NERR_BASE
    1921#define NERR_BASE 1 /* @@@PH DUMMY ! */
     22#endif
    2023
    2124
  • trunk/src/wnetap32/wnetap32.cpp

    r6676 r8052  
    1 /* $Id: wnetap32.cpp,v 1.16 2001-09-07 08:20:59 phaller Exp $ */
     1/* $Id: wnetap32.cpp,v 1.17 2002-03-08 11:37:10 sandervl Exp $ */
    22
    33/*
     
    3838#include <winconst.h>
    3939
     40#include "wnetap32.h"
     41#include "lanman.h"
    4042#include "oslibnet.h"
    41 #include "lanman.h"
    4243
    4344ODINDEBUGCHANNEL(WNETAP32-WNETAP32)
     45
     46
     47extern DWORD WIN32API OSLibNetbiosHlpHandler(LPVOID lpParam);
    4448
    4549
     
    4852 ****************************************************************************/
    4953
    50 #define NCBNAMSZ        16
    51 #define MAX_LANA       254
    52 
    53 typedef struct _NCB {
    54     UCHAR   ncb_command;
    55     UCHAR   ncb_retcode;
    56     UCHAR   ncb_lsn;
    57     UCHAR   ncb_num;
    58     PUCHAR  ncb_buffer;
    59     WORD    ncb_length;
    60     UCHAR   ncb_callname[NCBNAMSZ];
    61     UCHAR   ncb_name[NCBNAMSZ];
    62     UCHAR   ncb_rto;
    63     UCHAR   ncb_sto;
    64     void (* CALLBACK ncb_post)( struct _NCB * );
    65     UCHAR   ncb_lana_num;
    66     UCHAR   ncb_cmd_cplt;
    67     UCHAR   ncb_reserve[10];
    68     HANDLE  ncb_event;
    69 } NCB, *PNCB;
    70 
    71 #define NRC_GOODRET     0x00
    72 #define NRC_BUFLEN      0x01
    73 #define NRC_ILLCMD      0x03
    74 #define NRC_CMDTMO      0x05
    75 #define NRC_INCOMP      0x06
    76 #define NRC_BADDR       0x07
    77 #define NRC_SNUMOUT     0x08
    78 #define NRC_NORES       0x09
    79 #define NRC_SCLOSED     0x0a
    80 #define NRC_CMDCAN      0x0b
    81 #define NRC_DUPNAME     0x0d
    82 #define NRC_NAMTFUL     0x0e
    83 #define NRC_ACTSES      0x0f
    84 #define NRC_LOCTFUL     0x11
    85 #define NRC_REMTFUL     0x12
    86 #define NRC_ILLNN       0x13
    87 #define NRC_NOCALL      0x14
    88 #define NRC_NOWILD      0x15
    89 #define NRC_INUSE       0x16
    90 #define NRC_NAMERR      0x17
    91 #define NRC_SABORT      0x18
    92 #define NRC_NAMCONF     0x19
    93 #define NRC_IFBUSY      0x21
    94 #define NRC_TOOMANY     0x22
    95 #define NRC_BRIDGE      0x23
    96 #define NRC_CANOCCR     0x24
    97 #define NRC_CANCEL      0x26
    98 #define NRC_DUPENV      0x30
    99 #define NRC_ENVNOTDEF   0x34
    100 #define NRC_OSRESNOTAV  0x35
    101 #define NRC_MAXAPPS     0x36
    102 #define NRC_NOSAPS      0x37
    103 #define NRC_NORESOURCES 0x38
    104 #define NRC_INVADDRESS  0x39
    105 #define NRC_INVDDID     0x3B
    106 #define NRC_LOCKFAIL    0x3C
    107 #define NRC_OPENERR     0x3f
    108 #define NRC_SYSTEM      0x40
    109 
    110 #define NRC_PENDING     0xff
    111 
    11254
    11355//******************************************************************************
     56// Note:
     57// The major difference between OS/2 and Win32 regarding NetBIOS is
     58// all operations and resources are per-process for Win32 and
     59// global for OS/2. So we might probably end up with stray netbios names etc.
     60// long after a process has vanished.
    11461//******************************************************************************
     62//#define NETBIOS_ENABLED
    11563ODINFUNCTION1(UCHAR, OS2Netbios,
    116               PNCB, pncb)
    117 {
    118 #ifdef DEBUG
    119   WriteLog("OS2Netbios; pretend no network available\n");
    120 #endif
    121   return(NRC_OPENERR);
    122 }
    123 //******************************************************************************
    124 //******************************************************************************
     64              PNCB_w, pncb)
     65{
     66#ifndef NETBIOS_ENABLED
     67  pncb->ncb_retcode = NRC_OPENERR_w;
     68  return pncb->ncb_retcode;
     69 
     70#else
     71  UCHAR rc;
     72
     73  // Note: OS/2 specific documentation is found in DSSPGR1+DSSPGR2
     74 
     75  // fork for asynchronous operation:
     76  if (pncb->ncb_command & ASYNCH_w)
     77  {
     78    // either event or post may be specified
     79    if ( (pncb->ncb_event != 0) &&
     80         (pncb->ncb_post  != 0) )
     81    {
     82      pncb->ncb_retcode = NRC_ILLCMD_w;
     83      return NRC_ILLCMD_w;
     84    }
     85   
     86   
     87    // @@@PH
     88    // we might go for one or more statically allocated
     89    // worker threads instead of creating and destroying
     90    // a thread for each single request.
     91   
     92    // we're to start an ODIN thread ourself and do
     93    // the operation itself synchronously!
     94   
     95    // say the netbios operation is still pending ...
     96    pncb->ncb_cmd_cplt = NRC_PENDING_w;
     97   
     98    UCHAR  ucCommand = pncb->ncb_command;
     99    DWORD  tidNetbios;
     100    HANDLE hNetbiosThread = CreateThread(NULL,
     101                                         0x8000,
     102                                         OSLibNetbiosHlpHandler,
     103                                         (LPVOID)pncb,
     104                                         0, // thread creation flags
     105                                         &tidNetbios);
     106    if (hNetbiosThread == NULL)
     107    {
     108      // in case the thread could not be launched,
     109      // return with error
     110      pncb->ncb_retcode  = NRC_SYSTEM_w;
     111      pncb->ncb_cmd_cplt = NRC_SYSTEM_w;
     112      return pncb->ncb_retcode;
     113    }
     114    else
     115    {
     116      dprintf(("NETBIOS: Netbios helper thread %d started for command %02xh\n",
     117               tidNetbios,
     118               ucCommand));
     119     
     120      // verify if the operation has completed already
     121      if (pncb->ncb_cmd_cplt != NRC_PENDING_w)
     122      {
     123        // Docs say in this case return as if the request was synchronous
     124        rc = pncb->ncb_retcode;
     125      }
     126      else
     127      {
     128        // this is the "operation pending" return code
     129        rc = 0;
     130      }
     131    }
     132  }
     133  else
     134  {
     135    // verify request
     136    if ( (pncb->ncb_event != 0) ||
     137         (pncb->ncb_post  != 0) )
     138    {
     139      pncb->ncb_retcode = NRC_ILLCMD_w;
     140      return NRC_ILLCMD_w;
     141    }
     142   
     143    // call the Request Router
     144    rc = OSLibNetBIOS( pncb );
     145  }
     146
     147  return( rc );
     148#endif /* NETBIOS_ENABLED */
     149}
     150
    125151
    126152/*****************************************************************************
     
    10731099 * Name      : NET_API_STATUS I_NetPathType
    10741100 * Purpose   :
     1101
    10751102 * Parameters: wrong
    10761103 * Variables :
     
    10961123/*****************************************************************************
    10971124 * Name      : NET_API_STATUS NetapipBufferAllocate
     1125
    10981126 * Purpose   :
    10991127 * Parameters: wrong
Note: See TracChangeset for help on using the changeset viewer.