?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE: Network Access : Network Initialization Task' ??
MODULE nam$initialize_networks_r3;

{
{     PURPOSE:
{       The purpose of this module is to perform network initialization.
{
{     DESIGN:
{       This module is designed to be contained in the OSF$JOB_TEMPLATE_23D library and execute only
{       within the system job.  The module causes the initialization of a limited set of NAM/VE tables.
{
{       The primary goal of this module is to initialize NAM/VE.  Most all processes in the initialization
{       phase must succeed for NAM/VE to be viable.  That is, a failure in a specific process is either
{       is catastrophic at instance of occurance or implies that a subsequent process will fail. There
{       are processes that may not be totally successful, but allow NAM/VE to execute in a degraded mode.
{       Assuming a catastrophic or implied failure, the results of predecessor processes are undone.
{       This permits the initialization process to be restarted.
{
{           NOTE: Generally, a catastrophic or implied failure is the result of some software defect
{                 occuring as the result of modification of the process.
{
?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc cme$reserve_element
*copyc cml$ica_failure_data
*copyc cml$ica_usage_data
*copyc cml$ivb_failure_data
*copyc cml$ivb_usage_data
*copyc cml$mdi_failure_data
*copyc cml$mdi_usage_data
*copyc cmt$element_state
*copyc dse$resource_errors
*copyc nac$reserved_saps
*copyc nae$initialization_interfaces
*copyc nae$namve_conditions
*copyc nat$nam_attributes
*copyc nat$network_message_priority
*copyc nlt$device_count
*copyc nlt$network_device
*copyc nlt$network_device_list
*copyc oss$job_paged_literal
*copyc oss$task_shared
*copyc ost$status
*copyc pmt$program_parameters
?? POP ??
*copyc cmp$pc_get_element
*copyc cmp$process_state_change
*copyc nap$activate_network_config
*copyc nap$build_master_control_table
*copyc nap$change_network_device_state
*copyc nap$close_network_sap
*copyc nap$display_message
*copyc nap$free_pp_buffer_descriptor
*copyc nap$free_pp_buffer_pools
*copyc nap$free_pp_send_queue_tails
*copyc nap$get_nam_attributes_r1
*copyc nap$idle_network_applications
*copyc nap$initialize_application_defn
*copyc nap$init_pp_send_queue_tails
*copyc nap$initialize_pp_buffer_descr
*copyc nap$initialize_network_pp
*copyc nap$initialize_request_blocks
*copyc nap$idle_pp
*copyc nap$open_network_sap
*copyc nap$reserve_network_elements
*copyc nap$replenish_pp_buffer_pools
*copyc nap$return_network_elements
*copyc nap$reset_network_responses
*copyc nap$gt_initialize
*copyc nlp$cc_terminate_connections
*copyc nlp$na_initialize
*copyc nlp$se_initialize
*copyc nlp$sk_tcp_initialize
*copyc nlp$tm_initialize
*copyc nlp$sm_initialize
*copyc nlp$bm_free_buffer_pools
*copyc nlp$bm_initialize_buffer_pools
*copyc nlp$get_exclusive_access
*copyc nlp$la_initialize
*copyc nlp$release_exclusive_access
*copyc nlp$udp_initialize
*copyc osp$append_status_parameter
*copyc osp$free_heap_pages
*copyc osp$reset_heap
*copyc osp$set_status_abnormal
*copyc osp$set_status_condition
*copyc pmp$ready_task
*copyc sfp$activate_system_statistic
*copyc jmv$executing_within_system_job
*copyc nav$completed_output_taskid
*copyc nav$global_osi_statistics
*copyc nav$global_statistics
*copyc nav$intranet_mgmt_work_list
*copyc nav$namve_active
*copyc nav$network_paged_heap
*copyc nav$network_wired_heap
*copyc nlv$configured_network_devices
*copyc nlv$device_usage_data
*copyc nlv$timer_monitor_task
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

    TYPE
      device_type = SET OF nat$device_type,

      initialization_phase = (uninitialized, activate_network_configuration,
            initialize_access_agents, initialize_buffer_pools,
            initialize_pp_buffer_descriptor, initialize_request_blocks, initialize_response_list,
            initialize_device_usage_data, initialize_pp_send_queue_tails,
            replenish_pp_buffer_pools, reserve_network_elements, activate_statistics,
            open_directory_sap, install_applications, initialized),

      initialization_phases = SET OF initialization_phase;

    VAR
      nav$initialization_complete: [XDCL, oss$task_shared] initialization_phases :=
            $initialization_phases [];

?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] nap$terminate_namve', EJECT ??

  PROCEDURE [XDCL, #GATE] nap$terminate_namve (ignore_parameters: pmt$program_parameters;
    VAR status: ost$status);

{ PURPOSE:
{   The purpose of this procedure is to shut down NAM/VE and release the associated
{   allocated data structures.
{ METHOD:
{   This procedure is to be called when NAM/VE has been idled by nap$idle_namve.  The remaining
{   steps of NAM/VE initialization are undone.

    VAR
      current_connections: nat$nam_attribute;

    IF NOT jmv$executing_within_system_job THEN
      osp$set_status_abnormal ('NA', nae$insufficient_privilege, 'nap$terminate_namve', status);
      RETURN;
    IFEND;

    status.normal := TRUE;

    return_namve_to_null_state;
    nav$namve_active := FALSE;

  PROCEND nap$terminate_namve;

?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] nap$idle_namve', EJECT ??

  PROCEDURE [XDCL, #GATE] nap$idle_namve (ignore_parameters: pmt$program_parameters;
    VAR status: ost$status);

{ PURPOSE:
{   The purpose of this procedure is to shut down NAM/VE applications and devices, and return all associated
{   system resources.
{ METHOD:
{   This procedure is intended to be called repeatedly by the SCL procedure, DEACTIVATE_NETWORK, until all
{   NAM/VE activity has stopped.  This is necessary since this procedure executes in ring 3 and, therefore,
{   is not interruptable.  Since a successful idling of NAM/VE requires that all jobs with network connections
{   acknowledge the disconnect signal, it is quite possible for this process to loop endlessly.  The operator
{   is allowed to terminate the idling process at any time.  The current state of the idling process is
{   maintained so that it can be resumed after an interrupt.  NAM/VE can also be reactivated after an idle
{   request is interrupted.
{
{   First, all network applications are terminated and their definitions deleted by application management.
{   Next, all network devices are idled and the system resources (PPs, channels, etc.) are returned.  This
{   has the side effect of terminating any remaining management connections.  The completed_output task is
{   invoked to clean up the PP interface structures, and the timer_monitor task is invoked to return any
{   remaining terminated connections.
{
{   When the current connection count reaches zero, normal status is returned to indicate that the idling
{   process is complete.
{
{ NOTE:
{   This procedure can be invoked only in the system job.

    VAR
      current_connections: nat$nam_attribute,
      i: integer,
      ignore_status: ost$status,
      network_device_list: ^nlt$network_device_list,
      terminate_inactive_connections: boolean;

    IF NOT jmv$executing_within_system_job THEN
      osp$set_status_abnormal ('NA', nae$insufficient_privilege, 'nap$idle_namve', status);
      RETURN;
    IFEND;

    status.normal := TRUE;

    terminate_inactive_connections := install_applications IN nav$initialization_complete;
    nap$idle_network_applications (terminate_inactive_connections, status);
    nav$initialization_complete := nav$initialization_complete - $initialization_phases
          [install_applications];
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    network_device_list := nlv$configured_network_devices.network_device_list;
    IF network_device_list <> NIL THEN
      FOR i := LOWERBOUND (network_device_list^) TO UPPERBOUND (network_device_list^) DO
        { Return the element if the network elements have been reserved for NAM/VE. }
        IF (network_device_list^[i].path_status <> nlc$path_down) THEN
          nap$change_network_device_state (network_device_list^[i].element, {new_state =} cmc$down,
            {old_state = } cmc$on, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;
      FOREND;
    IFEND;

    nav$initialization_complete := nav$initialization_complete - $initialization_phases
          [reserve_network_elements];

    pmp$ready_task (nav$completed_output_taskid, ignore_status);
    pmp$ready_task (nlv$timer_monitor_task, ignore_status);

    nap$get_nam_attributes_r1 (nac$current_connections_status, current_connections);
    IF current_connections.current_connections > 0 THEN
      osp$set_status_condition (nae$connections_still_active, status);
      RETURN;
    IFEND;

  PROCEND nap$idle_namve;

?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] nap$initialize_networks', EJECT ??

  PROCEDURE [XDCL, #GATE] nap$initialize_networks (ignore_parameters: pmt$program_parameters;
    VAR status: ost$status);

{     NOTE: the directory Service Access Point MUST be opened before applications are installed. }
{           Otherwise, 'nap$initialize_applications_defn' may not be able to accurately perform  }
{           its function.                                                                        }

    VAR
      required_successful: [STATIC, READ, oss$job_paged_literal] initialization_phases :=
        $initialization_phases [activate_network_configuration,
        initialize_access_agents, initialize_buffer_pools,
        initialize_pp_buffer_descriptor, initialize_request_blocks, initialize_response_list,
        initialize_device_usage_data, initialize_pp_send_queue_tails,
        replenish_pp_buffer_pools, reserve_network_elements,
        open_directory_sap, install_applications],

      failed: [STATIC, READ, oss$job_paged_literal] array [activate_network_configuration ..
            install_applications] of string (31) := [
        'activate network configuration', 'initialize access agents',
        'initialize buffer pools', 'initialize pp buffer descriptor',
        'initialize request blocks', 'initialize response list', 'initialize_device_usage_data',
        'initialize_pp_send_queue_tails', 'replenish pp buffer pools',
        'reserve network elements', 'activate statistics',
        'open directory sap', 'install applications'];


?? NEWTITLE := 'activate_network_pp', EJECT ??

    PROCEDURE activate_network_pp (network_device: ^nlt$network_device);

      { Initialize the network PPs (i.e., communicate all the required addresses to the PPs). }

      { Initialize the PP if the network elements have been reserved for NAM/VE. }
      IF network_device^.logical_unit <> 0 THEN
        nap$build_master_control_table (network_device^.logical_unit, network_device^.
          device_id);
        nap$initialize_network_pp (network_device);
      IFEND;
    PROCEND activate_network_pp;
?? OLDTITLE ??
?? NEWTITLE := 'initialize_device_specific_stat', EJECT ??

{ PURPOSE:
{   The purpose of this procedure is to allocate space for the OSI device specific
{   statistics and initialize the statistic values to zero.
{

  PROCEDURE initialize_device_specific_stat;

    VAR
      i: nlt$device_count,
      network_device_list: ^nlt$network_device_list,
      networks_count: nlt$device_count;

    networks_count := 0;
    network_device_list := nlv$configured_network_devices.network_device_list;
    IF network_device_list <> NIL THEN
      networks_count := UPPERBOUND (network_device_list^);
      REPEAT
        ALLOCATE nav$global_osi_statistics.channel_connection_device: [1 .. networks_count]
              IN nav$network_paged_heap^;
        IF nav$global_osi_statistics.channel_connection_device = NIL THEN
          syp$cycle;
        IFEND;
      UNTIL nav$global_osi_statistics.channel_connection_device <> NIL;
    IFEND;

{ Initialize the statistic values.

    FOR i := 1 TO networks_count DO
      nav$global_osi_statistics.channel_connection_device^ [i].credit_pdus_received := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].credit_pdus_sent := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].current_normal_connections := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].current_priority_connections := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].device_resets := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].duplicate_connect_indications := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].normal_send_pdus_queued := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].pdus_processed_out_of_order := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_receive.value := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_receive_expedited_pdus := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_receive_pdus_discarded := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_send.value := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_send_expedited_pdus := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_send_pdus_discarded := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].priority_send_pdus_queued := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].receive.value := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].receive_pdus_discarded := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].received_expedited_pdus := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].send.value := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].send_expedited_pdus := 0;
      nav$global_osi_statistics.channel_connection_device^ [i].send_pdus_discarded := 0;
    FOREND;
  PROCEND initialize_device_specific_stat;
?? OLDTITLE ??
?? NEWTITLE := 'initialize_intranet_stats', EJECT ??

{ PURPOSE:
{   The purpose of this procedure is to allocate space for the intranet statistics
{   and initialize the statistic values to zero.
{

  PROCEDURE initialize_intranet_stats;

    VAR
      i: nlt$device_count,
      network_device_list: ^nlt$network_device_list,
      networks_count: nlt$device_count;

    networks_count := 0;
    network_device_list := nlv$configured_network_devices.network_device_list;
    IF network_device_list <> NIL THEN
      networks_count := UPPERBOUND (network_device_list^);
      IF nav$global_statistics.intranet = NIL THEN

{ Allocate space for the intranet statistic data structure.

        REPEAT
          ALLOCATE nav$global_statistics.intranet: [1 .. networks_count] IN nav$network_paged_heap^;
          IF nav$global_statistics.intranet = NIL THEN
            syp$cycle;
          IFEND;
        UNTIL nav$global_statistics.intranet <> NIL;
      IFEND;

{ Initialize the statistic values.

      FOR i := 1 TO networks_count DO
        nav$global_statistics.intranet^ [i].current_send_pdus_queued := 0;
        nav$global_statistics.intranet^ [i].logical_unit_number := network_device_list^[i].
          logical_unit;
        nav$global_statistics.intranet^ [i].multicasts_received := 0;
        nav$global_statistics.intranet^ [i].multicasts_sent := 0;
        nav$global_statistics.intranet^ [i].receive.value := 0;
        nav$global_statistics.intranet^ [i].receive_pdus_discarded := 0;
        nav$global_statistics.intranet^ [i].send.value := 0;
        nav$global_statistics.intranet^ [i].send_pdus_discarded := 0;
      FOREND;
    IFEND;
  PROCEND initialize_intranet_stats;
?? OLDTITLE ??
?? NEWTITLE := 'off_network_element', EJECT ??

    PROCEDURE [INLINE] off_network_element (network_device: ^nlt$network_device;
      VAR status: ost$status);

      VAR
        element_definition: ^cmt$element_definition,
        element_descriptor: cmt$element_descriptor,
        ignore_status: ost$status,
        iou_name: cmt$element_name;

      status.normal := TRUE;
      cmp$pc_get_element (network_device^.element, {not used} iou_name, element_definition, ignore_status);
      element_descriptor.element_type := element_definition^.element_type;
      element_descriptor.peripheral_descriptor.use_logical_identification := TRUE;
      element_descriptor.peripheral_descriptor.element_name := network_device^.element;
      cmp$process_state_change ({tape_element=} FALSE, TRUE, element_descriptor,
            {System critical element} FALSE, cmc$on, cmc$off, status);

    PROCEND off_network_element;
?? OLDTITLE, EJECT ??

    VAR
      configured_devices: SET OF nat$device_type,
      phase: initialization_phase,
      i: integer,
      iou_name: cmt$element_name,
      network_device: ^nlt$network_device,
      network_device_list: ^nlt$network_device_list,
      element_state: cmt$element_state,
      current_limit: integer,
      warning: ost$status;

{
{ NOTE: The section "NAM/VE Activation Error Troubleshooting" in the Software Release Bulletin (SRB)
{       describes site recovery from abnormalities in the initialization phases
{            activate_network_configuration,
{            reserve_network_elements, and
{            install_applications.
{       If the logic in these phases changes such that diagnostics or recovery techniques change,
{       the SRB must be updated.  Currently abnormalities detected in other phases are software defects
{       and are not documented in the SRB.
{

    status.normal := TRUE;
    warning.normal := TRUE;
    IF jmv$executing_within_system_job THEN

      nlp$get_exclusive_access (nlv$configured_network_devices.access_control);

      phase := SUCC (uninitialized);

    /initialize_networks/
      WHILE (status.normal AND (phase < initialized)) DO
        IF NOT(phase IN nav$initialization_complete) THEN
        CASE phase OF
        = activate_network_configuration =
          nap$activate_network_config (status);
          IF NOT status.normal THEN
            nlv$configured_network_devices.network_device_list := NIL;
          IFEND;

        = initialize_access_agents =
          nap$gt_initialize;
          nlp$se_initialize;
          nlp$sm_initialize;
          nlp$na_initialize;
          nlp$la_initialize;
          nlp$sk_tcp_initialize;
          nlp$udp_initialize;
          nlp$tm_initialize;

        = initialize_buffer_pools =
          nlp$bm_initialize_buffer_pools (status);

        = initialize_pp_buffer_descriptor =
          nap$initialize_pp_buffer_descr; { NOTE: due to the implementation of the mainframe wired heap,
{                                                 if the heap is full a ring 1 error system will occur and
{                                                 prevent returning of NAM/VE to a null state.

        = initialize_request_blocks =
          nap$initialize_request_blocks;
{
{

        = initialize_response_list =
          nap$initialize_response_list (status);

        = initialize_device_usage_data =
          init_device_usage_data (status);

        = initialize_pp_send_queue_tails =
          nap$init_pp_send_queue_tails;      { NOTE: due to the implementation of the mainframe wired heap,
{                                                    if the heap is full a ring 1 system error will occur and
{                                                    prevent returning of NAM/VE to a null state.

        = replenish_pp_buffer_pools =
          nap$replenish_pp_buffer_pools;

        = reserve_network_elements =

          { Reserve network elements for each configured network, provided the elements are ON. }
          network_device_list := nlv$configured_network_devices.network_device_list;
          configured_devices := $device_type [];

        /reserve_network_element/
          FOR i := LOWERBOUND (network_device_list^) TO UPPERBOUND (network_device_list^) DO
            network_device := ^network_device_list^[i];
            configured_devices := configured_devices + $device_type [network_device^.kind];

            nap$reserve_network_elements (network_device^.element, network_device^.
                  channel, network_device^. channel_address, network_device^.
                  driver_name, network_device^.logical_unit, network_device^.
                  pp_identification, network_device^.pp_number, status);
            IF (NOT status.normal AND ((status.condition = cme$element_state_not_proper) OR
                   (status.condition = dse$resource_not_available) OR
                   (status.condition = dse$pp_not_available_to_ve))) THEN
              IF (status.condition = dse$resource_not_available) OR
                      (status.condition = dse$pp_not_available_to_ve) THEN
                nap$display_message (status);
                off_network_element (network_device, status);
                IF NOT status.normal THEN
                  EXIT /reserve_network_element/;
                IFEND;
                osp$set_status_condition (nae$initialization_warning, warning);
              ELSE
                status.normal := TRUE;
              IFEND;
              network_device^.path_status := nlc$path_down;
            IFEND;

            IF status.normal THEN
              activate_network_pp (network_device);
            ELSE

            /software_defect/
              BEGIN
                { In case of unexpected error in reserving elements for any network, return all previously
                { reserved elements and free the network device list.  An unexpected error implies a breakage
                { among 'activate network configuration', 'reserve networks elements', and 'configuration
                { management'.
                EXIT /reserve_network_element/;
              END /software_defect/;
            IFEND;
          FOREND /reserve_network_element/;

        = activate_statistics =

{ Initialize the intranet periodic statistics.
          IF nav$global_statistics.intranet = NIL THEN
            initialize_intranet_stats;
          IFEND;

{ Initialize the osi device specific periodic statistics.
          IF nav$global_osi_statistics.channel_connection_device = NIL THEN
            initialize_device_specific_stat;
          IFEND;

{         NOTE: at Release 1.3.1 required statistics will be activated outside the NAM/VE initialization   }
{               process.  At that time the 'activate statistics' phase MUST be removed.                    }

          IF nac$di IN configured_devices THEN
{ Activate statistics code for MCI logging.

            sfp$activate_system_statistic (cml$mdi_failure_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;

            sfp$activate_system_statistic (cml$mdi_usage_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;
          IFEND;

          IF nac$ica_2 IN configured_devices THEN

{ Activate statistics code for ICA logging.

            sfp$activate_system_statistic (cml$ica_failure_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;

            sfp$activate_system_statistic (cml$ica_usage_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;
          IFEND;

          IF nac$expresslink IN configured_devices THEN

{ Activate statistics code for IVB logging.

            sfp$activate_system_statistic (cml$ivb_failure_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;

            sfp$activate_system_statistic (cml$ivb_usage_data, $sft$binary_logset [pmc$engineering_log],
                  status);
            IF NOT status.normal THEN
              nap$display_message (status);
            IFEND;
          IFEND;

          status.normal := TRUE;

        = open_directory_sap =
          nav$namve_active := TRUE;
          nlp$release_exclusive_access (nlv$configured_network_devices.access_control);
          nap$open_network_sap (nac$system_message_priority, nac$xi_cdna_directory_sap, status);
          nlp$get_exclusive_access (nlv$configured_network_devices.access_control);


        = install_applications =
          nlp$release_exclusive_access (nlv$configured_network_devices.access_control);
          nap$initialize_application_defn (status);
          nlp$get_exclusive_access (nlv$configured_network_devices.access_control);

        CASEND;
        IFEND;

        IF status.normal THEN
          nav$initialization_complete := nav$initialization_complete + $initialization_phases [phase];
          phase := SUCC (phase);
        ELSEIF NOT (phase IN required_successful) THEN
          IF (status.condition <> nae$initialization_error) THEN
            osp$set_status_abnormal (nac$status_id, nae$initialization_error, failed [phase], status);
          ELSE
            osp$append_status_parameter (osc$status_parameter_delimiter, failed [phase], status);
          IFEND;
          nap$display_message (status);
          osp$set_status_condition (nae$initialization_warning, warning);
          phase := SUCC (phase);
          status.normal := TRUE;
        ELSE
          IF (status.condition <> nae$initialization_fatal) THEN
            nap$display_message (status);
            CASE phase OF
            = activate_network_configuration =
              osp$set_status_condition (nae$activate_network_config, status);
            = install_applications =
              osp$set_status_condition (nae$install_applications, status);
            ELSE
              osp$set_status_abnormal (nac$status_id, nae$initialization_fatal, failed [phase], status);
            CASEND;
          ELSE
            osp$append_status_parameter (osc$status_parameter_delimiter, failed [phase], status);
          IFEND;
          return_namve_to_null_state;
        IFEND;
      WHILEND /initialize_networks/;
      nav$namve_active := status.normal;
      nlp$release_exclusive_access (nlv$configured_network_devices.access_control);
      IF status.normal THEN
        status := warning;
      IFEND;
    IFEND;
  PROCEND nap$initialize_networks;
?? OLDTITLE ??
?? NEWTITLE := 'nap$initialize_response_list', EJECT ??

  PROCEDURE nap$initialize_response_list (VAR status: ost$status);

{     The purpose of this procedure is to initialize the free queue in the intranet
{  management work list. A maximum of 25 response buffers are setup in the free
{  queue. The responses are communicated from the monitor mode process to the
{  intranet layer management task via these response buffers.

    CONST
      max_responses = 25;

    VAR
      i: integer,
      response_buffer: ^^nat$network_driver_response;

    status.normal := TRUE;
    response_buffer := ^nav$intranet_mgmt_work_list.free_responses.next_entry;
    FOR i := 1 to max_responses DO
      ALLOCATE response_buffer^ IN nav$network_wired_heap^;
      response_buffer := ^response_buffer^^.next_entry;
    FOREND;
    response_buffer^ := NIL;
    IF (i < (max_responses DIV 2)) THEN
      nap$free_response_list;
      osp$set_status_condition (nae$initialization_fatal, status);
    IFEND;
  PROCEND nap$initialize_response_list;
?? OLDTITLE ??
?? NEWTITLE := 'nap$free_response_list', EJECT ??

  PROCEDURE nap$free_response_list;

{
{     The purpose of this procedure is to clear the intranet management work list.
{     Entries are freed as the result of resetting the network wired.
{

    nav$intranet_mgmt_work_list.free_responses.next_entry := NIL;
    nav$intranet_mgmt_work_list.outstanding_responses.next_entry := NIL;
  PROCEND nap$free_response_list;
?? OLDTITLE ??
?? NEWTITLE := 'deconfigure_networks', EJECT ??

    PROCEDURE deconfigure_networks;

      VAR
        i: integer,
        network_device_list: ^nlt$network_device_list;

      network_device_list := nlv$configured_network_devices.network_device_list;
      IF network_device_list <> NIL THEN
      nlv$configured_network_devices.network_device_list := NIL;
      FOR i := LOWERBOUND (network_device_list^) TO UPPERBOUND (network_device_list^) DO
        { Return the element if the network elements have been reserved for NAM/VE. }
        IF (network_device_list^[i].logical_unit <> 0) THEN
          nap$idle_pp (network_device_list^[i].pp_number);
          nap$return_network_elements (network_device_list^[i].element, network_device_list^[i].channel,
            network_device_list^[i].pp_identification);
        IFEND;
      FOREND;
        FREE network_device_list IN nav$network_paged_heap^;
      IFEND;

    PROCEND deconfigure_networks;
?? OLDTITLE ??
?? NEWTITLE := '[INLINE] free_device_usage_data', EJECT ??
{
{ PURPOSE:
{   The purpose of this request is to clear the device usage data list.
{   The structure is freed as the result of resetting the network wired heap.
{

  PROCEDURE [INLINE] free_device_usage_data;

    nlv$device_usage_data := NIL;
  PROCEND free_device_usage_data;
?? OLDTITLE ??
?? NEWTITLE := 'init_device_usage_data', EJECT ??
  PROCEDURE init_device_usage_data
    (VAR status: ost$status);

    VAR
      i: integer,
      network_device_count: nlt$device_count;

    status.normal := TRUE;
    network_device_count := nlv$configured_network_devices.network_device_count;
    ALLOCATE nlv$device_usage_data: [1 .. network_device_count] IN nav$network_wired_heap^;

    IF nlv$device_usage_data <> NIL THEN
      FOR i := 1 TO network_device_count DO
        nlv$device_usage_data^ [i].bytes_transmitted := 0;
        nlv$device_usage_data^ [i].bytes_received := 0;
      FOREND;
    ELSE
      osp$set_status_condition (nae$initialization_fatal, status);
    IFEND;
  PROCEND init_device_usage_data;
?? OLDTITLE ??
?? NEWTITLE := 'return_namve_to_null_state', EJECT ??

    PROCEDURE return_namve_to_null_state;

      VAR
        phase: initialization_phase,
        status: ost$status;

      phase := PRED (initialized);
      WHILE (phase > uninitialized) DO
        IF (phase IN nav$initialization_complete) THEN
          CASE phase OF
          = activate_network_configuration =
            deconfigure_networks;
            nap$reset_network_responses;

          = initialize_access_agents =
            ;

          = initialize_buffer_pools =
            nlp$bm_free_buffer_pools;

          = initialize_pp_buffer_descriptor =
            nap$free_pp_buffer_descriptor;

          = initialize_request_blocks =
            ; { Request blocks need not be deallocated. }

          = initialize_response_list =
            nap$free_response_list;

          = initialize_device_usage_data =
            free_device_usage_data;

          = initialize_pp_send_queue_tails =
            nap$free_pp_send_queue_tails;

          = replenish_pp_buffer_pools =
            nap$free_pp_buffer_pools;
            { Buffer manager containers in the PP buffer pools are freed as the result of resetting the
            { network wired heap.
            ;

          = reserve_network_elements =
            deconfigure_networks;

          = activate_statistics =
{           NOTE: at Release 1.3.1 required statistics will be established outside the NAM/VE initialization }
{                 process.  In the mean time sfp$activate_system_statistics will return no errors            }
{                 when executed.  Therefore, it is unnecessary deactivate the statistics.                    }

          = open_directory_sap =
            nap$close_network_sap (nac$xi_cdna_directory_sap, status);

          = install_applications =
            ;
          CASEND;

          nav$initialization_complete := nav$initialization_complete - $initialization_phases [phase];

        IFEND;
        phase := PRED (phase);

      WHILEND;

      osp$reset_heap (nav$network_wired_heap, nac$network_heap_size, TRUE, nac$heap_algorithm);
      osp$free_heap_pages (nav$network_wired_heap);

    PROCEND return_namve_to_null_state;
?? OLDTITLE ??
MODEND nam$initialize_networks_r3;
