fix_asn1 3.72 KB
Newer Older
Cedric Roux's avatar
Cedric Roux committed
1
2
3
#!/bin/bash

# in those arrays, each line is:
4
#   <file> <sha1sum of file (without line 4 which changes depending on the location of the files)> <patch to apply to file>
Cedric Roux's avatar
Cedric Roux committed
5

Cedric Roux's avatar
Cedric Roux committed
6
RRC_Rel14=(
Cedric Roux's avatar
Cedric Roux committed
7
  "SystemInformation-r8-IEs.h" 4df485c5ddf2540eca271876cdc512caa19b0890 "fix_asn1.data/RRC.rel14/SystemInformation-r8-IEs.h.diff"
Cedric Roux's avatar
Cedric Roux committed
8
9
)

Cedric Roux's avatar
Cedric Roux committed
10
RRC_Rel10=(
11
  "SystemInformation-r8-IEs.h" 603cd6615cff36ec7020692d72c0d6de7c4859cb "fix_asn1.data/RRC.rel10/SystemInformation-r8-IEs.h.diff"
Cedric Roux's avatar
Cedric Roux committed
12
13
14
)

X2AP_Rel11_2=(
15
  "X2ap-CriticalityDiagnostics-IE-List.h" ae96308b37fcbcbf39da5012e42968135fc5f27b "fix_asn1.data/X2AP.rel11.2/X2ap-CriticalityDiagnostics-IE-List.h.diff"
Cedric Roux's avatar
Cedric Roux committed
16
17
)

18
19
20
red_color="$(tput setaf 1)"
green_color="$(tput setaf 2)"
reset_color="$(tput sgr0)"
Cedric Roux's avatar
Cedric Roux committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

function error()
{
  echo -e "$red_color"ERROR: "$@""$reset_color"
  exit 1
}

function check_sha1()
{
  local file="$1"
  local target_sha1="$2"

  if [ ! -f "$file" ]
  then
    error "$file: no such file"
  fi

38
39
40
41
42
43
  # we don't use the line 4 of the file
  # it contains the location of the ASN1 grammar
  # and this location is not the same on every
  # installation (this is for *.h files, for *.c
  # files it's no big deal to skip that line)
  local computed_sha1=$(sed 4d "$file" | sha1sum | cut -f 1 -d ' ')
Cedric Roux's avatar
Cedric Roux committed
44
45
46
47
48
49
50

  if [ "$target_sha1" != "$computed_sha1" ]
  then
    error "$file: wrong SHA1"
  fi
}

51
function patch_file()
Cedric Roux's avatar
Cedric Roux committed
52
{
53
54
  local patch="$1"
  local file="$2"
Cedric Roux's avatar
Cedric Roux committed
55

56
  echo -e "$green_color""patch file $file with $OPENAIR_DIR/cmake_targets/tools/$patch""$reset_color"
Cedric Roux's avatar
Cedric Roux committed
57

58
  patch "$file" "$OPENAIR_DIR/cmake_targets/tools/$patch"
Cedric Roux's avatar
Cedric Roux committed
59
60
  if [ $? -ne 0 ]
  then
61
    error "patching of $file with $OPENAIR_DIR/cmake_targets/tools/$patch failed"
Cedric Roux's avatar
Cedric Roux committed
62
63
64
  fi
}

65
function apply_patches()
Cedric Roux's avatar
Cedric Roux committed
66
67
68
69
70
71
72
73
{
  local directory="$1"
  local array=$2
  local len=$3       # the length could be computed locally but the way to do it is not clear to me [CROUX]

  local i
  local file
  local sha1
74
  local patch
Cedric Roux's avatar
Cedric Roux committed
75
76
77
78
79
80
81
  local item

  for (( i = 0; i < $len; i += 3 ))
  do
    # special bash syntax to access the array
    item=$array[$i];       file=${!item}
    item=$array[$((i+1))]; sha1=${!item}
82
    item=$array[$((i+2))]; patch=${!item}
Cedric Roux's avatar
Cedric Roux committed
83
    check_sha1 "$directory/$file" "$sha1"
84
    patch_file "$patch" "$directory/$file"
Cedric Roux's avatar
Cedric Roux committed
85
86
87
88
89
90
91
92
93
  done
}

function patch_rrc()
{
  local directory="$1"
  local version="$2"

  case "$version" in
Cedric Roux's avatar
Cedric Roux committed
94
95
96
97
    Rel14 )
      echo "patching RRC files release 14"
      apply_patches "$directory" RRC_Rel14 ${#RRC_Rel14[*]}
      ;;
Cedric Roux's avatar
Cedric Roux committed
98
99
    Rel10 )
      echo "patching RRC files release 10"
100
      apply_patches "$directory" RRC_Rel10 ${#RRC_Rel10[*]}
Cedric Roux's avatar
Cedric Roux committed
101
      ;;
102
103
104
    Rel8 )
      echo "patching RRC files release 8 TODO?"
      ;;
Cedric Roux's avatar
Cedric Roux committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    * )
      error unknwon/unhandled RRC version \'"$version"\'
      ;;
  esac
}

function patch_x2ap()
{
  local directory="$1"
  local version="$2"

  case "$version" in
    R11 )
      echo "patching X2AP files release 11.2"
119
      apply_patches "$directory" X2AP_Rel11_2 ${#X2AP_Rel11_2[*]}
Cedric Roux's avatar
Cedric Roux committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
      ;;
    * )
      error unknwon/unhandled X2AP version \'"$version"\'
      ;;
  esac
}

function patch_s1ap()
{
  local directory="$1"
  local version="$2"

  case "$version" in
    R10 )
134
      #nothing to do anymore (fixes went to asn1c)
Cedric Roux's avatar
Cedric Roux committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
      ;;
    * )
      error unknwon/unhandled S1AP version \'"$version"\'
      ;;
  esac
}

function main()
{
  if [ $# -ne 3 ]
  then
    echo "ERROR: pass <output directory> <module> <version>"
    exit 1
  fi

  if [ x"$OPENAIR_DIR" = x ]
  then
    error "the variable OPENAIR_DIR is not set"
  fi

  local directory="$1"
  local module="$2"
  local version="$3"

  case "$module" in
    RRC )
      patch_rrc "$directory" "$version"
      ;;
    X2AP )
      patch_x2ap "$directory" "$version"
      ;;
    S1AP )
      patch_s1ap "$directory" "$version"
      ;;
    * )
      error unknown module "$module"
      ;;
  esac

  exit 0
}

main "$@"