| AVR Z-LINKŪ |

# callbacks.c

Go to the documentation of this file.

    00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
    00029 /* === Includes ============================================================ */
    00030 #include<stdbool.h>
    00031 #include<stdint.h>
    00032
    00033 #include"compiler.h"
    00034
    00035 #include"ieee_const.h"
    00036 #include"ieee_types.h"
    00037 #include"wpan_mac.h"
    00038
    00039 #include"chat.h"
    00040 #include"serialPortHAL.h"
    00041 #include"utilities.h"
    00042
    00043 /* ==== Macros ============================================================= */
    00044 /* === Typedefs ============================================================ */
    00045 /* === Variables =========================================================== */
    00046 uint16_t shortAddress = 0x0000;
    00047 bool permit = true;
    00048 /* === Prototypes ========================================================== */
    00049 /* === Implementation ====================================================== */
    00050
    00059 void usr_mlme_reset_conf( uint8_t status ){
    00060
    00061         //If success, send OK to confirm.
    00062         if( status == MAC_SUCCESS ){
    00063
    00064                 sendOK( );
    00065                 state = CHAT_IDLE;
    00066         }
    00067
    00068         //Else, give error feedback.
    00069         else{
    00070
    00071                 sendERROR( RESET_FAILED );
    00072         }
    00073 }
    00074
    00107 void usr_mlme_scan_conf( uint8_t status, uint8_t ScanType, uint32_t UnscannedChannels,
    00108                                                  uint8_t ResultListSize, uint8_t *data, uint8_t data_length ){
    00109
    00110         uint8_t capabilityInfo;
    00111     capabilityInfo = WPAN_CAP_FFD | WPAN_CAP_PWRSOURCE |\
    00112                       WPAN_CAP_RXONWHENIDLE | WPAN_CAP_ALLOCADDRESS;
    00113
    00114         //The only valid call to this function is as a termination of the
    00115         //mlme_scan_request done in startNetworkOperation.
    00116         if( state != CHAT_ACTIVE_SCAN_PENDING ){
    00117
    00118                 sendERROR( INCONSISTENT_STATE );
    00119                 return;
    00120         }
    00121
    00122         //Coordinator.
    00123         if( role == COORDINATOR ){
    00124
    00125                 //Should not receive any beacon frames.
    00126                 //This means that none else is using the channel.
    00127                 if( status == MAC_NO_BEACON ){
    00128
    00129                         wpan_mlme_set_request( macShortAddress, &shortAddress,
    00130                                                                    sizeof( shortAddress ) );
    00131
    00132                         state = CHAT_SET_ADDRESS_PENDING;
    00133                 }
    00134
    00135                 else{
    00136
    00137                         sendERROR( ACTIVE_SCAN_FAILED );
    00138                         state = CHAT_IDLE;
    00139                 }
    00140         }
    00141
    00142         //End_device.
    00143         else{
    00144
    00145                 if( status == MAC_SUCCESS ){
    00146
    00147                         wpan_mlme_associate_request( chatChannel, WPAN_ADDRMODE_SHORT,
    00148                                                                                  chatPANID, shortAddress,
    00149                                                                                  capabilityInfo, false );
    00150
    00151                         state = CHAT_ASSOCIATION_PENDING;
    00152                 }
    00153
    00154                 else{
    00155
    00156                         sendERROR( ACTIVE_SCAN_FAILED );
    00157                         state = CHAT_IDLE;
    00158                 }
    00159
    00160         }
    00161 }
    00162
    00180 void usr_mlme_set_conf( uint8_t status, uint8_t PIBAttribute ){
    00181
    00182         //State check.
    00183         if( !( ( state == CHAT_SET_ADDRESS_PENDING ) ||
    00184              ( state == CHAT_SET_PERMIT_ASSOCIATION_PENDING ) ) ){
    00185
    00186                 sendERROR( INCONSISTENT_STATE );
    00187                 state = CHAT_IDLE;
    00188                 return;
    00189         }
    00190
    00191         //Set macShortAddress.
    00192         if( PIBAttribute == macShortAddress )
    00193     {
    00194
    00195                 if( status == MAC_SUCCESS ){
    00196
    00197                         wpan_mlme_start_request( chatPANID, chatChannel, 0x0F, 0x0F, true, false, false, false );
    00198                         state = CHAT_START_PENDING;
    00199                 }
    00200
    00201                 else{
    00202
    00203                         sendERROR( SET_MAC_ADDRESS_FAILED );
    00204                         state = CHAT_IDLE;
    00205                 }
    00206         }
    00207
    00208         //Set macAssociationPermit.
    00209         else{
    00210
    00211                 if( status == MAC_SUCCESS ){
    00212
    00213                         sendOK( );
    00214                         state = CHAT_WAIT_FOR_ASSOCIATION;
    00215                 }
    00216
    00217                 else{
    00218
    00219                         sendERROR( START_NETWORK_FAILED );
    00220                         state = CHAT_IDLE;
    00221                 }
    00222         }
    00223 }
    00224
    00237 void usr_mlme_start_conf( uint8_t status )
    00238 {
    00239
    00240         //Check status and that the state is correct.
    00241         if( ( status == MAC_SUCCESS ) && ( state == CHAT_START_PENDING ) ){
    00242
    00243                 wpan_mlme_set_request( macAssociationPermit, &permit,
    00244                                                                    sizeof( permit ) );
    00245
    00246                 state = CHAT_SET_PERMIT_ASSOCIATION_PENDING;
    00247         }
    00248
    00249         else{
    00250
    00251                 sendERROR( START_NETWORK_FAILED );
    00252                 state = CHAT_IDLE;
    00253         }
    00254 }
    00255
    00280 void usr_mlme_associate_ind( uint64_t DeviceAddress, uint8_t CapabilityInformation, uint8_t SecurityUse, uint8_t ACLEntry ){
    00281
    00282         if( state == CHAT_WAIT_FOR_ASSOCIATION ){
    00283
    00284                 //Generate response.
    00285                 wpan_mlme_associate_response( DeviceAddress, 0x0001,
    00286                                                                           ASSOCIATION_SUCCESSFUL, false );
    00287         }
    00288
    00289         else{
    00290
    00291                 //Generate response.
    00292                 wpan_mlme_associate_response( DeviceAddress, 0x0001,
    00293                                                                           PAN_AT_CAPACITY, false );
    00294         }
    00295 }
    00296
    00314 void usr_mlme_comm_status_ind( wpan_commstatus_addr_t *pAddrInfo, uint8_t status ){
    00315
    00316         if( status == MAC_SUCCESS ){
    00317
    00318                 sendAssociationNotification( );
    00319                 state = CHAT_CONNECTED;
    00320         }
    00321 }
    00322
    00337 void usr_mlme_associate_conf( uint16_t AssocShortAddress, uint8_t status ){
    00338
    00339         if( ( status == MAC_SUCCESS ) && ( state == CHAT_ASSOCIATION_PENDING ) ){
    00340
    00341                 sendOK( );
    00342                 state = CHAT_CONNECTED;
    00343         }
    00344
    00345         else{
    00346
    00347                 sendERROR( ASSOCIATION_FAILED );
    00348                 state = CHAT_IDLE;
    00349         }
    00350 }
    00351
    00365 void usr_mcps_data_conf( uint8_t msduHandle, uint8_t status ){
    00366
    00367         //Check if the message was successfully transmitted.
    00368         if( status == MAC_SUCCESS ){
    00369
    00370                 sendOK( );
    00371         }
    00372
    00373         //Give feedback about errors to user.
    00374         else{
    00375
    00376                 sendERROR( DATA_TRANSMISSION_FAILED );
    00377         }
    00378 }
    00379
    00404 void usr_mcps_data_ind( wpan_mcpsdata_addr_t *addrInfo, uint8_t mpduLinkQuality,
    00405         uint8_t SecurityUse, uint8_t ACLEntry, uint8_t msduLength, uint8_t *msdu ){
    00406
    00407         //Only possible to send messages from this state.
    00408         if( state != CHAT_CONNECTED ){
    00409
    00410                 return;
    00411         }
    00412
    00413         sendDataNotification( msduLength,msdu );
    00414 }
    00415

@DOC_TITLE@