~vcs-imports/bluez/master

« back to all changes in this revision

Viewing changes to mesh/net.c

  • Committer: Brian Gix
  • Author(s): Inga Stotland
  • Date: 2019-02-12 23:30:53 UTC
  • Revision ID: git-v1:c1551f20270f5a3cf43729645a1f1fd15a11c0c8
mesh: Separate functions for net key add and update

This splits mesh_net_key_add() into two separate functions:
mesh_net_key_add() and mesh_net_key_update().
mesh_net_key_update() essentially replaces mesh_net_kr_phase_one()
since switching to Key Refresh phase one can only be triggered
by successful network key update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
970
970
        return MESH_STATUS_SUCCESS;
971
971
}
972
972
 
973
 
int mesh_net_add_key(struct mesh_net *net, bool update, uint16_t idx,
974
 
                                                        const void *value)
 
973
int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
975
974
{
976
 
        int status;
977
975
        struct mesh_subnet *subnet;
978
976
 
979
977
        subnet = l_queue_find(net->subnets, match_key_index,
980
978
                                                        L_UINT_TO_PTR(idx));
981
979
 
982
 
        if (update) {
983
 
                if (subnet && subnet->kr_phase == KEY_REFRESH_PHASE_NONE) {
984
 
                        l_info("Start key refresh");
985
 
                        status = mesh_net_kr_phase_one(net, idx, value);
986
 
                        if (status == MESH_STATUS_SUCCESS &&
987
 
                                !storage_net_key_add(net, idx,
988
 
                                                value, KEY_REFRESH_PHASE_ONE))
989
 
                                return MESH_STATUS_STORAGE_FAIL;
990
 
                } else
991
 
                        return MESH_STATUS_CANNOT_UPDATE;
992
 
        }
993
 
 
994
980
        if (subnet) {
995
981
                if (net_key_confirm(subnet->net_key_cur, value))
996
982
                        return MESH_STATUS_SUCCESS;
3570
3556
        return MESH_STATUS_SUCCESS;
3571
3557
}
3572
3558
 
3573
 
int mesh_net_kr_phase_one(struct mesh_net *net, uint16_t idx,
 
3559
int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
3574
3560
                                                        const uint8_t *value)
3575
3561
{
3576
3562
        struct mesh_subnet *subnet;
3580
3566
 
3581
3567
        subnet = l_queue_find(net->subnets, match_key_index,
3582
3568
                                                        L_UINT_TO_PTR(idx));
 
3569
 
3583
3570
        if (!subnet)
3584
3571
                return MESH_STATUS_CANNOT_UPDATE;
3585
3572
 
 
3573
        /* Check if the key has been already successfully updated */
 
3574
        if (subnet->kr_phase == KEY_REFRESH_PHASE_ONE &&
 
3575
                                net_key_confirm(subnet->net_key_upd, value))
 
3576
                return MESH_STATUS_SUCCESS;
 
3577
 
3586
3578
        if (subnet->net_key_upd) {
3587
3579
                net_key_unref(subnet->net_key_upd);
3588
3580
                l_info("Warning: overwriting new keys");
3606
3598
 
3607
3599
        l_info("key refresh phase 1: Key ID %d", subnet->net_key_upd);
3608
3600
 
 
3601
        if (!storage_net_key_add(net, idx, value, KEY_REFRESH_PHASE_ONE))
 
3602
                return MESH_STATUS_STORAGE_FAIL;
 
3603
 
3609
3604
        subnet->kr_phase = KEY_REFRESH_PHASE_ONE;
3610
3605
 
3611
3606
        return MESH_STATUS_SUCCESS;