# Arm Authorization

When enabled by setting a parameter on flight stack, the drone will only arm the motors if authorized by a external entity. This external entity is responsible for requesting any information that it needs from the drone and from other sources (example: weather) and whether (or not) to authorize the arming procedure.

This is required to comply with [NASA UTM](https://utm.arc.nasa.gov/), but may also be useful for private companies.

## Authorization Flow

[![Mermaid Squence: Authorization Flow](https://mermaid.ink/img/eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtO1xuICAgIHBhcnRpY2lwYW50IERyb25lXG4gICAgcGFydGljaXBhbnQgUmVtb3RlIGNvbnRyb2wvUUNTXG4gICAgcGFydGljaXBhbnQgQXJtIGF1dGhvcml6ZXJcbiAgICBwYXJ0aWNpcGFudCBJbnRlcm5ldFxuXG4gICAgUmVtb3RlIGNvbnRyb2wvUUNTLT4-RHJvbmU6IFJlcXVlc3QgYXJtXG4gICAgRHJvbmUtPj5Bcm0gYXV0aG9yaXplcjogQ09NTUFORF9MT05HIGNvbW1hbmQ9TUFWX0NNRF9BUk1fQVVUSE9SSVpBVElPTl9SRVFVRVNUXG4gICAgQXJtIGF1dGhvcml6ZXItPj5Ecm9uZTogQ09NTUFORF9BQ0sgcmVzdWx0PU1BVl9SRVNVTFRfSU5fUFJPR1JFU1NcbiAgICBBcm0gYXV0aG9yaXplci0-PkRyb25lOiAob3B0aW9uYWwpUmVxdWVzdCBpbmZvcm1hdGlvbiBhYm91dCBtaXNzaW9uLCBiYXR0ZXJ5IGxldmVsIGFuZCBldGMuXG4gICAgQXJtIGF1dGhvcml6ZXItPj5JbnRlcm5ldDogKG9wdGlvbmFsKVJlcXVlc3QgaW5mb3JtYXRpb24gYWJvdXQgd2VhdGhlciwgYWVyb3NwYWNlIHRyYWZpYyBhbmQgZXRjLlxuICAgIEFybSBhdXRob3JpemVyLT4-RHJvbmU6IENPTU1BTkRfQUNLIGNvbW1hbmQ9TUFWX0NNRF9BUk1fQVVUSE9SSVpBVElPTl9SRVFVRVNUIHJlc3VsdD1BQ0NFUFRFRCwgVEVNUE9SQVJJTFlfUk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ENPTU1BTkRfQUNLIGNvbW1hbmQ9TUFWX0NNRF9BUk1fQVVUSE9SSVpBVElPTl9SRVFVRVNUIHJlc3VsdD1BQ0NFUFRFRCwgVEVNUE9SQVJJTFlfUkVKRUNURUQgb3IgREVOSUVEXG4gICAgRHJvbmUtPj5SZW1vdGUgY29udHJvbC9RQ1M6IFFDUyBDT01NQU5EX0FDSyBjb21tYW5kPU1BVl9DTURfQ09NUE9ORU5UX0FSTV9ESVNBUk0gcmVzdWx0PUFDQ0VQVEVELCBURU1QT1JBUklMWV9SRUpFQ1RFRCBvciBERU5JRUQiLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ)

<!-- Original diagram
sequenceDiagram;
    participant Drone
    participant Remote control/QCS
    participant Arm authorizer
    participant Internet

    Remote control/QCS->>Drone: Request arm
    Drone->>Arm authorizer: COMMAND_LONG command=MAV_CMD_ARM_AUTHORIZATION_REQUEST
    Arm authorizer->>Drone: COMMAND_ACK result=MAV_RESULT_IN_PROGRESS
    Arm authorizer->>Drone: (optional)Request information about mission, battery level and etc.
    Arm authorizer->>Internet: (optional)Request information about weather, aerospace trafic and etc.
    Arm authorizer->>Drone: COMMAND_ACK command=MAV_CMD_ARM_AUTHORIZATION_REQUEST result=ACCEPTED, TEMPORARILY_REJECTED or DENIED
    Drone->>Remote control/QCS: QCS COMMAND_ACK command=MAV_CMD_COMPONENT_ARM_DISARM result=ACCEPTED, TEMPORARILY_REJECTED or DENIED
-->

In case the authorizer need a lot of time to get and process the information is better have another authorization flow to avoid arm the drone at unexpected time.

[![Mermaid Sequence: Arm authorisation 2](https://mermaid.ink/img/eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtO1xuICAgIHBhcnRpY2lwYW50IERyb25lXG4gICAgcGFydGljaXBhbnQgUmVtb3RlIGNvbnRyb2wvUUNTXG4gICAgcGFydGljaXBhbnQgQXJtIGF1dGhvcml6ZXJcbiAgICBwYXJ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yBhbmQgZXRjLlxuICAgIEFybSBhdXRob3JpemVyLT4-RHJvbmU6IENPTU1BTkRfQUNLIGNvbW1hbmQ9TUFWX0NNRF9BUk1fQVVUSE9SSVpBVElPTl9SRVFVRVNUIHJlc3VsdD1BQ0NFUFRFRCwgVEVNUE9SQVJJTFlfUkVKRUNURUQgb3IgREVOSUVEXG4gICAgRHJvbmUtPj5SZW1vdGUgY29udHJvbC9RQ1M6IFFDUyBTVEFUVVNURVhUIHRleHQ9QXJtIGF1dGhvcml6YXRpb24gd2FzIGFwcHJvdmVkIG9yIGRlbmllZFxuXG4gICAgUmVtb3RlIGNvbnRyb2wvUUNTLT4-RHJvbmU6IFJlcXVlc3QgYXJtMlxuICAgIERyb25lLT4-UmVtb3RlIGNvbnRyb2wvUUNTOiBRQ1MgQ09NTUFORF9BQ0sgY29tbWFuZD1NQVZfQ01EX0NPTVBPTkVOVF9BUk1fRElTQVJNIHJlc3VsdD1BQ0NFUFRFRCwgVEVNUE9SQVJJTFlfUkVKRUNURUQgb3IgREVOSUVEIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifSwidXBkYXRlRWRpdG9yIjpmYWxzZX0)

<!-- Original diagram
sequenceDiagram;
    participant Drone
    participant Remote control/QCS
    participant Arm authorizer
    participant Internet

    Remote control/QCS->>Drone: Request arm1
    Drone->>Remote control/QCS: QCS COMMAND_ACK result=TEMPORARILY_REJECTED
    Drone->>Arm authorizer: COMMAND_LONG command=MAV_CMD_ARM_AUTHORIZATION_REQUEST
    Arm authorizer->>Drone: COMMAND_ACK result=MAV_RESULT_IN_PROGRESS
    Arm authorizer->>Drone: (optional)Request information about mission, battery level and etc.
    Arm authorizer->>Internet: (optional)Request information about weather, aerospace trafic and etc.
    Arm authorizer->>Drone: COMMAND_ACK command=MAV_CMD_ARM_AUTHORIZATION_REQUEST result=ACCEPTED, TEMPORARILY_REJECTED or DENIED
    Drone->>Remote control/QCS: QCS STATUSTEXT text=Arm authorization was approved or denied

    Remote control/QCS->>Drone: Request arm2
    Drone->>Remote control/QCS: QCS COMMAND_ACK command=MAV_CMD_COMPONENT_ARM_DISARM result=ACCEPTED, TEMPORARILY_REJECTED or DENIED
-->

## Message Parameters

COMMAND_LONG

    command=MAV_CMD_ARM_AUTHORIZATION_REQUEST
    target_system=system id of arm authorizer
    target_component=component id of arm authorizer
    

COMMAND_ACK

    command=MAV_CMD_ARM_AUTHORIZATION_REQUEST
    result=ACCEPTED, TEMPORARILY_REJECTED or DENIED
    progress/result_param1=if result is TEMPORARILY_REJECTED or DENIED the reason should be set MAV_ARM_AUTH_DENIED_REASON otherwise it should be set as 0
    result_param2=if result is ACCEPTED the it should be set with the time in seconds that this authorization is valid otherwise an aditional information about why it was denied should be set. example: for result_param1=MAV_ARM_AUTH_DENIED_REASON_INVALID_WAYPOINT or MAV_ARM_AUTH_DENIED_REASON_AIRSPACE_IN_USE it may have the index of the waypoint that caused it to be denied.
    target_system=system id of the drone
    target_component=component id of the drone